Think, act, look — one lap around the agent loop
Here is a simulated agent solving one question that needs three different tools: a file reader, a calculator, and web search. Step through it. Watch two things: the loop phase (top) and the scratchpad — the notes the agent accumulates, which are the only reason step 7 knows what step 2 found.
Press Next step to run the loop.
Simulated agent with a scripted trace — real agents generate each THINK with an LLM, but the loop structure (and the scratchpad trick) is exactly this.
You are the router — pick the right tool or pay for it
At every THINK step the agent must choose which tool to call next. Now it's your job. The question needs exactly two facts. Route well and you're done in 2 calls; route badly and you burn money on calls that teach you nothing. (Every call costs real tokens.)
Cost estimated at ~900 tokens per tool round-trip at $3 / million tokens — small per call, brutal at scale.
file_read can only waste a step here. Routing is most of what an agent's THINK step does, and bad routing is the #1 silent cost leak in production agents.The tool lied — retry, reroute, recover
Tools fail constantly: timeouts, empty payloads, HTML error pages where a number should be. The loop's superpower is that the agent reads the result before using it — if it bothers to check. Run both agents against the same flaky stock-price API and compare.
The validation here is a real check running in this page: “does the output parse as a price?” Real agents validate with schemas, regexes, or a second LLM pass.
The infinite retry — why every agent has a kill switch
Same tool call + same broken tool = same error, forever. A loop with no exit condition will happily re-call a dead database until your credit card melts. Run it with no limit and watch the meter; then set max iterations and see the guardrail fire.
The tool is db_query and the database is down. It will not come back during this run — and the agent has no way to know that.
One poisoned number — the error cascade
The loop's other failure mode is quieter and scarier: a tool returns plausible garbage, the agent believes it, and every later step builds on the lie. Run the healthy pipeline, then the corrupted one — and then turn on the sanity check and run it corrupted again.
The dollar figures are computed live from the pipeline's own numbers — corrupt step ① and watch the damage compound through ②③④.