Uh oh!
There was an error while loading. Please reload this page.
feat(task): expose subagent token consumption to primary agent - #4611
feat(task): expose subagent token consumption to primary agent#4611arsham wants to merge 1 commit into
Conversation
Expose token consumption and context capacity to primary agent to enable informed delegation decisions. Aggregates subagent token consumption and updates parent message with cumulative costs. Includes context_limit and context_percentage in task_metadata so primary agent can decide whether to continue with subagent or spawn fresh session based on remaining context capacity.
arsham
commented
Nov 21, 2025
Side note - noticed something in processor.ts While working on this, I came across something in case"finish-step":
input.assistantMessage.cost+=usage.cost// accumulatesinput.assistantMessage.tokens=usage.tokens// replacesCost uses Is this intentional? My guess is tokens represents "current context window state" while cost is "total spent" - but wanted to flag it in case this was an oversight. If a single message has multiple finish-step events, only the last step's tokens would be retained. Not blocking this PR on it, just curious if anyone knows the reasoning here. |
f1dc981 to
3e15a39Comparedf8bdf9 to
0dd5039Comparerekram1-node
commented
Nov 24, 2025
yes that’s intentional |
rekram1-node
commented
Nov 24, 2025
for your token consumption stuff, is this a problem you were running into? Also note that child sessions work like any other so it automatically prunes tool calls and automatically compacts if needed so it is rare thatd itd run out of context |
arsham
commented
Nov 24, 2025
Not a problem. This is an improvement over the The primary agent delegates to some agents. My subagents return the confidence level of what they are doing, but the only measurement they don't have is the context consumption. On the next turn, the primary looks at the confidence level and other metrics including the session_id, then makes a decision to reuse the same agent. This helps by reducing duplicate work and also if we get lucky and before cache invalidation, we get to reuse the cached prompt from the API side. |
f1ae801 to
08fa7f7CompareClosing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR. |
Primary agent now receives token consumption data from subagents via
task_metadata, enabling smarter delegation decisions based on remaining context capacity.The
task_metadatanow includes:Example
Why
Previously,
task_metadataonly returnedsession_id. The primary had no visibility into how much context a subagent had consumed, making it impossible to know when to spawn a fresh session vs continue with an existing one.Primary can now check
context_percentageand decide to continue with the same subagent or start fresh when context is running low.