The loop from Chapter 1 makes exactly one kind of request, and everything the agent does or fails to do passes through it. Six topics open that request up: the message array and the four roles inside it, the token arithmetic that explains the bill, why the same ticket gets two different answers, the one response field the loop branches on, how to get JSON that parses, and a single quarantined page where vendor names are allowed to live.
6 topics
Vera's forty-line agent works, in the sense that it answers the cracked-shelving ticket without crashing. What she cannot yet say is why it costs what it costs, why the same ticket produced a different sequence of tool calls the second time she ran it, or why one run ended with the sentence "Let me look that order up" delivered to the buyer as a resolution. All three answers are inside one HTTP request and the response it gets back, and none of them are visible through the SDK's typed objects.
So this chapter takes the SDK away. The call is a list of messages with roles, a list of tool definitions, and a handful of sampling settings; the response is one more message, a token count, and a stop reason. That is the entire interface a language model exposes, and it is the same interface underneath every framework in Chapter 14. Everything the rest of the book builds — memory, retrieval, planning, budgets, approval gates — is code that decides what goes into that array and what to do with what comes back.
Two of these topics carry numbers the rest of the book leans on. Topic 08 works the Sundry arithmetic in full and shows that a ticket whose context tops out at 4,880 tokens bills roughly 12,000 input tokens, because turn N re-sends turns 1 through N-1; that number is the reason Chapter 5 exists. Topic 10 is the stop reason, the field a correct loop branches on and the field a broken loop ignores. The chapter closes on the vendor surface, deliberately isolated on one page so that when a provider ships something next quarter, exactly one file in this book goes stale.
One request opened up, and rebuilt from scratch every turn
One HTTP request
everything the model will see this turn
system
who the agent is, and what it may not do
the stable prefix a cache can pay for
tools[]
nine schemas · about 680 tokens
identical every turn, billed every turn
messages[]
user, assistant and tool results, in order
grows by one exchange per turn
One message back
content blocks · token counts · stop reason
the loop branches on the stop reason, never on the text