subagent: tell the child its iter budget, warn near the cap#493
Merged
Conversation
The child loop's tool-iter cap was enforced from the outside only; the subagent's system prompt never said "you have N tool calls", and the child had no way to know which iteration it was on. The visible failure mode was an explore subagent burning all 20 iters mapping the territory, then hitting the cap mid-thought and emitting a partial summary the parent had to re-dispatch from. Two pieces: 1. spawnSubagent now appends a one-paragraph budget notice to the child's system prompt — literal "Tool budget: you have N tool calls" with the resolved cap baked in. Applies to default, typed (explore/verify), and caller-supplied system prompts uniformly. 2. ToolRegistry gains setResultAugmenter(), a final-stage post-hook on dispatch. spawnSubagent installs one that counts dispatches and appends "[budget: K of N tool calls left — wrap up soon]" once the child is within 3 iters of the cap, escalating to "0 left — finalize NOW" on the last call. Static prompt + dynamic countdown together: prompt sets expectation, countdown forces reckoning when the budget is actually tight. Closes #488
ChasLui
pushed a commit
to ChasLui/DeepSeek-Reasonix
that referenced
this pull request
May 23, 2026
…engine#493) The child loop's tool-iter cap was enforced from the outside only; the subagent's system prompt never said "you have N tool calls", and the child had no way to know which iteration it was on. The visible failure mode was an explore subagent burning all 20 iters mapping the territory, then hitting the cap mid-thought and emitting a partial summary the parent had to re-dispatch from. Two pieces: 1. spawnSubagent now appends a one-paragraph budget notice to the child's system prompt — literal "Tool budget: you have N tool calls" with the resolved cap baked in. Applies to default, typed (explore/verify), and caller-supplied system prompts uniformly. 2. ToolRegistry gains setResultAugmenter(), a final-stage post-hook on dispatch. spawnSubagent installs one that counts dispatches and appends "[budget: K of N tool calls left — wrap up soon]" once the child is within 3 iters of the cap, escalating to "0 left — finalize NOW" on the last call. Static prompt + dynamic countdown together: prompt sets expectation, countdown forces reckoning when the budget is actually tight. Closes esengine#488
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Subagents had no visibility into their own tool-iter budget. The parent's
maxToolIterscapped the loop from outside, but the child neither knew the cap nor its current iteration — so anexplorerun could burn all 20 iters mapping the territory, hit the cap mid-thought, and emit a partial summary the parent had to re-dispatch.This PR closes the gap with prompt + telemetry:
spawnSubagentappends a one-paragraph "Tool budget: you have N tool calls" notice with the resolved cap baked in, applied uniformly to default, typed (explore/verify), and caller-supplied system prompts.setResultAugmenter— a new final-stage post-hook onToolRegistry.dispatch().spawnSubagentinstalls one that counts dispatches and appends[budget: K of N tool calls left — wrap up soon]once the child is within 3 iters of the cap, escalating to[budget: 0 left — finalize NOW]on the last call.Static prompt sets the expectation; dynamic countdown forces reckoning when the budget is actually tight.
Closes #488
Test plan
tests/subagent.test.ts— new case drives 5 tool calls under amaxToolIters: 5budget and asserts the augmented tool-result content at each iteration (no warning on iter 1, then3 / 2 / 1 / 0 lefton iters 2–5)..toBeto.toContain+ a regex match for the budget line.npm run verify(full suite, 2292 tests).