15 agent internals
after Hanako
15 things your agent does before it answers you see the last one
one turn
1/15
1. Renders the prompt
templateyou are {{role}}budget {{n}} turns
rendereda reviewer, 12 turns
template plus variables, not what you typed
2. Picks the context
api.tsspec.mdlog
context
which files and history get in
3. Trims the middle
184k tokens
head + tail kepttext-amber-700 dark:text-amber-400
what did not fit is simply gone
4. Loads tool schemas
schemas
6.2k tokens
every tool you defined costs tokens
5. Chooses one tool
read_filerun_testsopen_pr
one wins
one call, out of everything available
6. Fills the arguments
arguments
pathsrc/api.ts
moderw
guessed, not giventhe path it guessed, not the one you meant
7. Waits on the tool
model 210ms
tool 2,840ms
queue 90ms
the latency nobody attributes correctly
8. Truncates the result
42k
900 tokens
42k of output, 900 tokens kept
9. Retries in silence
attempt 1timeoutattempt 2ok
never surfaced to youthe failure you never saw happen
10. Grades its own work
rubric score
passes at 8.0
only if you wrote a rubric
11. Decides to continue
check
continuestop
continue, retry, or stop
12. Compacts the history
one summary
your turn 3 becomes one sentence
13. Writes to disk
statestate.json
checkpointedthe only part that survives a crash
14. Spawns a subagent
mainsubagent
40k in, 1k back
burns 40k, hands back 1k
15. Picks what to show
reasoningfinal answertrace
youtext-orange-700 dark:text-orange-400the one line you actually read