Skip to main content

Agentic loop stepper

One call to /v1/resolve, three turns, four tool calls. Step through it and watch two things move: the message stack grows on every turn, and so does the bill.

Token counts are representative of a real run against claude-opus-5. Exact figures move per ticket. The shape is what matters.

First request. The prefix is written to cache. Claude has the ticket and nothing else, so it reaches for the two lookups it needs before it can reason about anything: the order, and the account standing. Both go out in one turn, in parallel.

messages sent this turn (2 blocks)
  • system: role + policy handbook (cached prefix)
  • user: the customer ticket
tools called
lookup_order
{ "order_id": "NW-48211" }
{ "found": true, "total_usd": 218.4, "days_since_delivery": 16, … }
lookup_customer
{ "email": "dana.k@example.com" }
{ "found": true, "member_tier": "trail_club", "refunds_last_30d_usd": 0, … }
usage this turn
cache_creation_input_tokens4,711
cache_read_input_tokens0
input_tokens (fresh)68
output_tokens124
cost this turn$0.0329
Running total after turn 1$0.0329
True total, all 3 turns$0.0593
If you logged only the final message$0.0180

The final message’s usage describes only the final request. Log that and you report $0.0180 for a run that actually cost $0.0593, an under-report of 3.3x. And the error is not 1/N, because the turns are not equal — history accumulates, so the last turn is the largest one. Sum every turn.

This is the question learners most often get wrong: Lab 3, Q3. The code that gets it right is in src/routes/resolve.ts, which iterates the runner rather than awaiting it, precisely so it can capture every turn.