Essays / tools / reliability
When Your Tools Start Calling Each Other
Nested tool calls are where quiet corruption lives. Three failure patterns, one cheap guardrail, and the reason I stopped letting tools call tools.
The bug took nine days to find and four minutes to fix. A research agent was calling a search tool, which called a fetch tool, which called a summarizer, which returned a summary nobody had validated. The summary was fine, except the fetch had silently truncated at 8,000 characters, and the summarizer, doing its job, summarized the truncated text into a confident paragraph about a document that ended a third of the way through.
No errors. No warnings. The pipeline worked exactly as designed, which was the problem.
Three ways nesting corrupts
1. Silent truncation, laundered into confidence. Every layer downstream has less context than the one before it, and no layer knows what it lost. A truncation at the bottom becomes a confident claim at the top. This is the most common failure I see in tool chains and the hardest to notice, because the output is fluent.
2. Side effects run twice. A tool that writes a file, retried by the layer above when the response was slow. Now there are two files, or two rows, or two emails. Idempotency is a property of the tool, but retries belong to the caller, and the caller never asked whether the callee was safe to repeat.
3. Errors lose their shape. The bottom layer raises a structured error with a code and a hint. The middle layer catches it, wraps it in a string, and passes it up as "the fetch failed". The agent at the top now cannot retry intelligently, so it retries dumbly, with the same inputs, producing the same failure. I have watched a four-layer chain burn forty minutes on this.
The tell. If your agent occasionally "hallucinates" facts that exist in the source but with a strange ending, check for truncation before you check the model. Nine times out of ten it is a tool quietly cutting the tail off the document.
The guardrail that actually held
I stopped letting tools call tools. One level, always.
The orchestrating agent calls a flat set of tools. If a task needs search then fetch then summarize, the agent calls search, then calls fetch on a chosen result, then calls summarize. Three steps, three visible decisions, and at each step the full output is in front of the model that will act on it.
This is slower in wall-clock terms and much faster in debugging terms. The chain is inspectable at every hop, and the failure is always in the step you can see.
Three supporting rules:
- Compound tools keep the primitive output. A "research this" tool may exist, but it must return the raw sources alongside the summary, so the caller can check the summary against something.
- Every write tool takes an idempotency key. If the key is present in the store, return the prior result instead of repeating. Costs ten lines and removes an entire class of duplicate-side-effect bugs.
- Errors cross boundaries as objects, not sentences. Code, message, retryable flag, and the raw payload. If a layer must summarize an error, it must preserve the code.
When nesting is the right answer
Twice, in production work, a nested tool was genuinely better:
- A batch job over 400 documents, where the inner loop had no decisions to make and the outer loop only cared about the aggregate.
- A deterministic transform pipeline: parse, normalize, validate. No model in the loop, so no one can be fooled by truncation.
The distinguishing question is not complexity. It is whether a human or the model needs to see an intermediate step to act correctly. If yes, flatten it. If no, and it is infallible in the boring way, nest it.
What to steal
- Flatten your tool graph to one level. Make the agent do the visible orchestration.
- Return raw evidence next to every synthesized answer.
- Give every write an idempotency key.
- Pass structured errors across boundaries, never prose.
- When something looks hallucinated but is suspiciously coherent, look for truncation first.