04 Trust in productionLesson 4 of 411 minIntermediateHelps to have seen:Tokens, context and cost
Cost and latency
- + conversation m06
- + three tools
The diagram shows: "Cancel both" (4836 and 4848), Agent (the loop: model and tools), buscar_pedido (4836 and 4848), buscar_politica (cancellation), criar_reembolso (after checking) and Turns (of this conversation).
Highlighted: Agent and Turns.
"Cancel both" sends to Agent carrying "cancel both".
Added: conversation m06. Added: three tools.
Step 1 of 8: The customer waits, the bill goes up
- Why the conversation costs the sum of its turns
- Grouping independent tools
- Sending the simple stuff to a smaller model
- Looking at the tail, not just the average
Cost and time per conversation, average and worst 5%, on the store’s 50 test conversations
Coming soon: I will measure this on the example agent and publish the number with the report.
The whole lesson as textEvery step, to read at once, search or print.
The customer waits, the bill goes up
"I want to cancel orders 4836 and 4848." To answer correctly, the agent needs five tools: look up both orders, fetch the policy and create two refunds.
One at a time, that is five turns plus the reply: six calls to the model. The customer stares at a frozen screen.
The cost that matters is the conversation’s, not the call’s.
The conversation costs the sum of its turns
On every turn, the model rereads everything: instructions, policy, history and the tool results that keep piling up. The input grows with each turn.
Time adds up too: each turn waits for the model and the tool. Fewer turns is the first lever, before any model swap.
Fewer turns: fewer tokens and less waiting.
Independent tools in the same turn
The two orders and the policy do not depend on each other. The model can ask for all three lookups in a single turn, and your code runs them in parallel.
On the next turn, with everything at hand, it creates both refunds together. Then it replies. From six calls down to three.
What is independent goes together.
The simple stuff goes to a smaller model
Not every message needs the most capable model. "What is the Pix deadline?" calls no money tool and fits a smaller model, cheaper and faster.
On Anthropic’s price list, Haiku 5.5 costs US$ 0.10 per million input tokens; Sonnet 5.5, US$ 2. It is the routing from the patterns lesson applied to cost.
The right model for each question.
The average hides the conversation that never ends
The average cost per conversation looks great. But in one conversation the agent does not understand the result and calls buscar_pedido again, and again.
That conversation costs many times the average and leaves the customer waiting. Also look at the worst 5%, and put a turn limit in code that hands off to a support rep.
The problem lives in the tail.
Real waiting and perceived waiting
Time can also shrink in perception. With streaming, the text appears while the model writes, instead of all at the end.
Between turns, a line like "looking up order 4836" shows that the agent is working. The wait is the same; the frozen screen is not.
Show the work while it happens.
The architecture decides the bill
In the write-up of its research system, Anthropic says agents use about 4 times the tokens of a chat, and multi-agent systems about 15 times.
Our reading: before cutting words from the prompt, look at how many turns, how many agents and which model.
The biggest cost lever is the architecture.
The bill belongs to the whole conversation
Every turn pays for the conversation again. Fewer turns, a smaller model for the simple stuff and a limit in code cut cost and time.
How to check your own case: the trace already keeps time and tokens for each step. Add them up per conversation and look at the average and the worst 5%, before and after each change.
Measure the whole conversation, and the tail.
Questions in this lesson
- Why does the input grow with each turn of the loop?
- The model rereads the context with the accumulated results. Each tool result goes into the context of the next turn.
- Does "What is the Pix deadline?" need the most capable model?
- No, a smaller model handles it, cheaper and faster. A simple question, with no money tool: route it to the smaller model.
- Why look at the worst 5% and not just the average?
- Because the conversation stuck in a loop disappears in the average. A few expensive, slow conversations can dominate the cost and the complaints.