Chapter 6 · Part 3
Cost, models & where next
You have a working agent. Two things matter before you turn it loose on real work — what it costs, and which model to run — and then a map of where to go from here.
An agent multiplies cost
A chatbot makes one call per question. An agent makes several, and each call re-sends the whole
growing conversation. So the same task can cost many times a single reply. Watch it: every
response carries a usage block, so add it up across the loop.
total_in = total_out = 0
# ... inside the loop, after each client.messages.create(...) ...
total_in += reply.usage.input_tokens
total_out += reply.usage.output_tokens
# ... after the loop ...
print(f"Used {total_in} input + {total_out} output tokens across the task.")Multiply those totals by the model's per-token price (on Anthropic's pricing page) and you have the cost of the run. Two habits keep it sane: set a spend limit in the Console, and keep tools' results short — a tool that returns a 50,000-line file dumps all of it into every later call.
Right-size the model
Default to a capable model while you build, then choose deliberately:
claude-opus-4-8— the most capable; best for hard, long agent runs. What we've used.claude-sonnet-5— near-Opus quality, cheaper; a great everyday agent default.claude-haiku-4-5— fastest and cheapest; good for simple, high-volume tools.
For agents specifically, also raise the effort — it makes Claude plan and use tools more thoroughly, which is exactly what agentic work needs:
reply = client.messages.create(
model="claude-opus-4-8",
max_tokens=1024,
output_config={"effort": "xhigh"}, # low | medium | high | xhigh | max — 'high' is the default
tools=tools,
messages=messages,
)The four ways to build an agent
You built yours the most hands-on way. As the job gets bigger, you move up this ladder — each step hands more of the work to Anthropic:
- The manual loop — you write the
whileloop yourself. Total control. (Chapters 2–3.) - The tool runner — the SDK turns the loop; you supply the tools. (Chapter 4 — your day-to-day default.)
- The Claude Agent SDK — Claude Code packaged as a library: built-in file, edit and shell tools, context management and subagents, all included. Reach for it to build a coding or filesystem agent without wiring tools yourself.
- Managed Agents — Anthropic runs the loop and hosts a sandbox where the tools execute. You send a task and stream back events; there's no loop to host at all.
You started this track drawing pixels and end it building an agent — the same pattern behind the coding assistants, research bots and computer-use tools making headlines. From here: give your agent web search, point it at a real API, or wire it into the RAG chatbot you built earlier so it can look things up and act. You now know how all of it works, all the way down. 🎉