Lesson 40.3 · 3 of 3 · 6 min read · Reviewed 24 Nov 2026
The cost of autonomy
By the end, you can
- Estimate how autonomy changes cost, latency and failure rates.
- List the controls an agent needs before it goes to production.
Autonomy is not free. Before choosing an agentAgent: A system where a model decides its own next steps, calling tools in a loop until the task is done., put numbers on what it costs.
Cost grows faster than steps
An agent re-sends the conversation on every turn: the system prompt, the tool definitionsTool definition: The name, description and input schema that tell the model what a tool does and how to call it., every earlier tool call and result. A 10-turn run with a growing history can use many times the tokens of a 10-step workflow that sends only what each step needs. Prompt cachingPrompt caching: Reusing the processed form of a repeated prompt prefix across requests, which cuts cost and latency. (70.1) cuts this a lot, but the shape stays the same.
Latency adds up
Every turn waits for a model response and a tool call. Ten turns of three seconds each is a 30-second answer. Users notice.
Errors compound
If each step is right 95% of the time, ten steps are all right only about 60% of the time (0.95¹⁰ ≈ 0.6). Agents recover from some mistakes by noticing them, but you can’t count on it.
What autonomy demands
Before an agent reaches users it needs:
- a turn limit and a cost budget in code (chapter 42)
- tracingTrace: A record of everything that happened during one request or agent run, as a tree of timed steps. of every model call and tool call (chapter 67)
- least-privilege tools, with risky actions behind approval (chapter 45)
- evalsEval: A repeatable test that measures how well an AI system performs on a set of cases with defined success criteria. on trajectories, not just final answers (chapter 19)
- a clean way to hand off to a person
If that list feels heavy for the task, it’s a sign the task wants a workflowWorkflow: A system where LLM calls and tools follow a path defined in code, rather than chosen by the model..
Key points
- Each extra turn re-sends the whole conversation, so agent cost grows faster than the number of steps.
- Errors compound: ten steps that are each 95% right finish correctly only about 60% of the time.
- Agents need turn limits, budgets, tracing, sandboxed tools and a way to hand off to a person.
Put numbers on the cost of autonomy
Calculate how tokens, latency and reliability change as an agent takes more turns, and compare with a workflow.
You will have: A table of tokens, seconds and success chance for runs of 1 to 20 turns, plus the workflow equivalent.
Steps
- Set the illustrative numbers: system prompt and tools of 3,000 tokens, 800 new tokens per turn, 3 seconds per turn and 95% per-step accuracy.
- Write agent_tokens(turns): every turn re-sends everything so far.
- Write workflow_tokens(steps): each step sends only the prompt plus its own 800 tokens.
- Compute latency and the chance that every step is right, 0.95 to the power of the steps.
- Print the table for 1, 5, 10 and 20 steps.
Done when
- The token ratio grows with the number of steps, reaching 3x at 20 steps.
- The 10-step success chance prints as 60%.
- 20 turns take a full minute at 3 seconds each.
Open in the Playground No API key needed.
Starter code (Python)
BASE, PER_TURN, SECONDS, ACC = 3000, 800, 3, 0.95 # illustrative numbers
def agent_tokens(turns):
# TODO: on turn k the request holds BASE + k * PER_TURN tokens; add them up
return 0
def workflow_tokens(steps):
# TODO: each step sends BASE + PER_TURN
return 0
print("steps agent_tokens workflow_tokens ratio seconds success")
for n in [1, 5, 10, 20]:
# TODO: print one row
pass
Show a solution
BASE, PER_TURN, SECONDS, ACC = 3000, 800, 3, 0.95 # illustrative numbers
def agent_tokens(turns):
return sum(BASE + k * PER_TURN for k in range(1, turns + 1))
def workflow_tokens(steps):
return steps * (BASE + PER_TURN)
print("steps agent_tokens workflow_tokens ratio seconds success")
for n in [1, 5, 10, 20]:
a, w = agent_tokens(n), workflow_tokens(n)
print(f"{n:>5} {a:>12,} {w:>15,} {a / w:>5.1f} {n * SECONDS:>7} {ACC ** n:>7.0%}")
Finished the chapter? Take the chapter check.