Repository navigation
DRU-1144 -- Count the tokens and cost of a Codex call's subagents - #1171
Open
p-r-a-v-i-n wants to merge 1 commit into
Open
p-r-a-v-i-n wants to merge 1 commit into
p-r-a-v-i-n wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
A Codex call now records the tokens and cost of the subagents it spawns, together with its own. Before, Druks read only the main thread:
turn.completedon stdout carries only the main thread's totals, and each subagent keeps its totals in its own session file under~/.codex/sessions. With a subagent running, more than one session file is newer than the marker, so the wrapper also skippedsession.jsonl, and a failed call with subagents recorded nothing.thread_spawnsource as a subagent's file. For each one, it writes the first line, the lastturn_contextand the lasttoken_countto a newsubagents.jsonlartifact. It pickssession.jsonlfrom the other files as before.read_codex_subagent_costskeeps the subagents whoseparent_thread_idis the main thread id from thethread.startedevent on stdout, so another call's files on the same sandbox are not counted. It prices each subagent at the model on itsturn_context, becausespawn_agentcan pick a different model.parseadds each subagent's cost and tokens to the main thread's totals. The model and rate fields in the cost metadata still describe the main thread.agents.max_depthof 1, so only direct children are counted.