Skip to content

perf(agent): a finished worker returns its report, not every step - #423

Merged
mrnasil merged 1 commit into
mainfrom
perf/subagent-final-report
Nov 7, 2026
Merged

mrnasil merged 1 commit into
mainfrom
perf/subagent-final-report

Conversation

@mrnasil

@mrnasil mrnasil commented Nov 7, 2026

Copy link
Copy Markdown
Member

Part of the token-efficiency series (#418–#422).

Problem

A subagent's result was the concatenation of the text from every step: "Let me read n.txt first.", "Now I'll check the tests.", …, and only then the actual findings. All of it landed in the parent's context as one tool result, typically 0.5–3k tokens per task call, with the narration carrying no information.

Change

  • A worker that finishes returns the text of its last step that said anything (subagent.rs).
  • Every worker's system prompt (built-in or custom agent) ends with a short # Report note: only its final message reaches the parent, so put every finding there. Findings therefore are not left in earlier messages.
  • Unchanged. An unfinished worker (turn limit, failure, cancel) still returns its full step log, which gives the parent more to pick up from. Structured output already reads the final message.

Checks

  • New test finished_worker_returns_its_report_not_every_step: a narrated tool step followed by a report step returns exactly the report.
  • whycodes-agent --lib passes (765). fmt and clippy are ok. Local llvm-cov: every changed line is covered.
  • Two schedule timing tests (execute_schedule_tool_command_and_goal, execute_bg_kill_already_status…) failed once under instrumented coverage. They pass in a normal run and do not touch this code.

🤖 Generated with Claude Code

A subagent's result was the concatenation of the text from every step:
"Let me read n.txt first.", "Now I'll check the tests.", ... and then the
actual findings. All of it landed in the parent's context as one tool
result.

A worker that finishes now returns the text of its last step that said
anything. Every worker's system prompt (built-in or custom agent) ends
with a short `# Report` note saying only its final message reaches the
parent, so findings are not left in earlier messages. An unfinished
worker still returns its full step log, which gives the parent more to
pick up from. Structured output already reads the final message.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mrnasil
mrnasil force-pushed the perf/subagent-final-report branch from fd5ddcd to bd4d5db Compare November 7, 2026 13:48
@mrnasil
mrnasil merged commit 9bc713e into main Nov 7, 2026
7 checks passed
@mrnasil
mrnasil deleted the perf/subagent-final-report branch November 7, 2026 13:55
@mrnasil mrnasil mentioned this pull request Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant