Chapter Three · Tools

Tools

Six topics turn an agent that can only read into one that can change the world. What a tool is on each side of the split between your code and the model, schemas the model can actually choose between, what a result should contain, errors written for a reader who must act, why nine tools beat twenty-two — and the twelve seconds in which a timed-out refund was paid twice.

6 topics

Vera's forty-line agent could look things up and nothing else. On the cracked shelving ticket it searched the orders, read the record, retrieved the damage procedure, and then wrote the buyer a paragraph promising a refund it had no ability to perform. Every capability in Chapter 1 was real; the reply was a draft that a person still had to act on. This chapter gives the agent the four tools that act — returns, replacements, refunds, messages to sellers — and everything that has to be true before any of them is safe to attach.

A tool is two halves that live in different places: a function in your code, and a declaration the model reads on every turn. The model never executes anything — it emits a structured request and stops, and your dispatcher decides whether to run it. That split is where the whole permission model comes from, and the declaration half turns out to be measurable rather than a matter of style: rewriting one description at Sundry, with no code change at all, moved correct tool selection from 71% to 93% on a labelled set of 200 tickets.

The last topic is the one to read twice. issue_refund timed out after the payment provider had already accepted it, the tool reported a failure, the model asked again in good faith, and a buyer was paid $118.00 twice while a marketplace seller's balance went to minus $47 — discovered three days later by finance, on tickets the eval set had scored as resolved. Idempotency keys derived from intent close that wound here; Chapter 8 generalizes it into partial failure and compensation.

One round trip, and the only step in it that runs your code
The model asksid · name · arguments
The dispatcher decidesvalidates · authorizes
The function runsyour code, your credentials
Result appendedtagged with the same id
The model reads itnext turn, and every turn after

Topics in This Chapter

Topic 13
What a Tool Really Is
A function in your code plus a declaration the model reads, and the model only ever sees the second half. Why authorization belongs in the dispatcher rather than the prompt, and why a wrong get_order costs a token where a wrong issue_refund costs a phone call.
Tool Anatomy
Topic 14
Tool Schemas the Model Can Use
Documentation for a reader who cannot ask a follow-up question, measured on a labelled set rather than argued about. Two lines of description moved correct tool selection from 71% to 93%, and three rewrites in between scored worse and were thrown away.
Schema Design
Topic 15
The Tool-Call Round Trip
The five steps of one circuit, and why the request id matters the moment two tools are called at once. Sundry's get_order goes from 6 KB of upstream JSON to 340 tokens of the fourteen fields anyone reads, with identical resolution on the eval set.
Result Shaping
Topic 16
Errors as Teaching
Three failure classes — the model's fault, the world's fault, the system's fault — each needing a different sentence and a different next move. What a timeout must never be allowed to look like, and how a permanent failure ends a run on turn 3 instead of turn 12.
Error Design
Topic 17
Designing a Tool Surface
Four tools score 97% on first-call selection, nine score 93%, and twenty-two generated from an OpenAPI document score 76% while adding no capability at all. What to merge, what to split across a permission boundary, what to hide, and the two Sundry tools that were deleted.
Surface Design
Topic 18
Side Effects, Idempotency, and Retries
Twelve seconds on a Tuesday afternoon in which one refund became two, told with the timestamps and then taken apart layer by layer. Keys derived from intent, the model's retry as the layer no counter can see, and the rule that after an ambiguous write you read before you write again.
Idempotency