Sub topic 3
Reasoning Tokens and Model Choice for Coding Agents
Assume you can read basic Python and JSON, and you understand an agent as a model that can call tools over several turns.
Reasoning tokens
Reasoning tokens are internal tokens a model uses while solving a problem. They may not appear in the final answer, but they can still affect usage, latency, and cost. Extra reasoning helps with debugging, planning, and changes that affect many files. It often adds little value for formatting, short summaries, or simple lookups.
Subagents isolate context
A subagent is a separate model session assigned a narrow task. It receives only the context you provide, so it does not inherit every file read and tool result from the main agent. This can reduce repeated input tokens and make the task easier to review.
Route each step to a suitable model
Model tiers trade capability, cost, and latency. Use a stronger model for planning or ambiguous design decisions. Use a smaller model for predictable tasks such as summarizing tool output or running a test command.
ROUTES = {
"plan": "large-model",
"edit": "mid-model",
"summarize_tool_output": "small-model",
"run_tests": "small-model",
}
def pick_model(step_kind, default="mid-model"):
return ROUTES.get(step_kind, default)
print(pick_model("plan"))
print(pick_model("other"))Read usage data and attribute spend
Record input tokens, output tokens, cached tokens, reasoning tokens when reported, model name, step type, and task ID. Calculate each request separately, then group requests by task or agent. This prevents a large tool call from being hidden inside an average.
> callout note > Provider fields differ. Confirm whether reported output tokens include reasoning tokens and whether cached tokens have a separate rate.
Compare cost per resolved task
Price per token is only a forecast. A cheaper model may need more retries or fail more tasks. Use:
cost per resolved task = total spend, including failed attempts / tasks resolved
Compare models on the same task set and count quality failures, not only successful completions.
Set budgets and guardrails
Set a maximum number of turns, maximum output tokens, and maximum spend per task. Truncate oversized tool output, ask for confirmation before expensive operations, and stop when repeated attempts produce no progress.
Exercise
A model costs twice as much per token but resolves twice as many tasks with half as many retries. What should you compare?
Show answer
Compare total spend per resolved task on the same workload, including retries and failed attempts.