Cheat sheet
Tools
From lesson 0005. The model writes a slip. You cook. The ticket re-enters RAM.
- ProposeStructured tool call, not English.
- RunYour code or an MCP server.
- PasteResult goes into the script.
- PickPack · read · pick, now with a live fact.
When
- Do: live state, actions, anything the weights cannot know tonight.
- Skip: already in the script, or a tiny general question (2+2).
- RAG pastes pages you found. Tools paste tickets from work you ran.
MCP
USB-C for AI apps: one plug, many kitchens. Same loop. Not a bigger window, not a new tokenizer.
OpenAI: tool call → you execute → tool output. Anthropic: the model never executes on its own.
The loop in code
From lesson 0021. Claude Messages API shapes; TypeScript.
const messages = [{ role: "user", content: userText }];
let turns = 0;
while (true) {
if (turns === maxTurns) return "max_turns"; // CAP
turns++;
const response = await client.messages.create({ model, max_tokens, tools, messages });
if (response.stop_reason === "end_turn") return text; // STOP
messages.push({ role: "assistant", content: response.content }); // KEEP, whole
const results = response.content // RUN
.filter((block) => block.type === "tool_use")
.map((slip) => ({
type: "tool_result",
tool_use_id: slip.id,
content: runTool(slip.name, slip.input),
}));
messages.push({ role: "user", content: results }); // PASTE, one message
}
stop_reason:tool_usemeans run slips;end_turnmeans done.- Results go in a
usermessage, immediately after the slip message. Notoolrole. - Every
tool_useid needs a matchingtool_result, or the API returns 400. - The whole array is resent each call. Input tokens grow every turn.
Source: Handle tool calls.