Chapter 01
Claude API
The request/response contract every agent is built on — and the four fields the exam actually tests.
1.1
One request carries the whole world
Request–response. Nothing is remembered between calls, so every call ships everything the model needs.
1.1b
The API is stateless — the transcript is the memory
Nothing survives between calls except what you resend. That is why cost grows quadratically over a long turn.
1.2
Three roles — and tool results are not one of them
A tool result rides inside a user turn as a tool_result block. There is no tool role.
tool_use_id is what pairs a result to its request — never the position in the array.system can also appear inside messages[] to add instructions mid-conversation without invalidating the cached prefix from the top-level field. Later system messages win over earlier ones and over the top-level field, for turns after them.
1.3
stop_reason is the only completion signal
A structured field decides the control flow. Never the reply text.
1.4
The system prompt shapes tool behaviour too
It is loaded once, outranks user messages, and quietly creates tool associations you did not ask for.
Role, hard constraints, output format, escalation rules — the things that must hold across every turn.
"Always verify the customer" makes the model call get_customer on turns where nobody needed verifying. Wording creates tool gravity.
1.5
The context window is a budget you spend four ways
System prompt + full history + tool definitions + tool results. Tool results are the ones that run away.
A tool returning 40 fields when 5 matter wastes the window on every later call. Trim at the boundary — a PostToolUse hook, or the tool itself.
Compaction eats exactly what you need: numbers, percentages, dates become "about", "roughly", "a few". Extract facts into a separate block before compacting.
Recall in 60 seconds
- Send the full history every call — the model persists nothing.
- Tool results are
tool_resultblocks in a user turn. Notoolrole exists. tool_use_idpairs a result to its request. Never rely on ordering.- Completion =
stop_reason === 'end_turn'. Not text, not an iteration count. max_tokenscaps the reply. The context window caps everything.- System-prompt wording creates tool gravity — "always verify" causes needless lookups.
- Lost in the middle → put constraints at the start or the end.
- Compaction destroys numbers and dates. Extract them out first.