01.05 · Walkthrough
Your first agent, end to end
Build a working single-tool agent and watch every message in the loop.
A minimal agent is a controlled loop around a chat transcript: the model requests an action, your code validates and runs the tool, then feeds the result back so the model can continue or answer. The useful part is seeing every message, not treating the agent as autonomous magic.
What this lesson answers
- how does a simple AI agent loop work
- what messages are in an agent transcript
- how do tool calls work in agents
Notes
An agent is a program that lets a language model choose actions, not just produce a final answer. In the simplest useful version, your code sends the model a goal, the model either answers or asks to call a tool, your code runs that tool, then sends the tool result back to the model. That repeats until the model decides it has enough information to answer.
The mental model is a small event loop around a chat transcript. The transcript contains system instructions, the user request, the assistant’s proposed tool call, the tool’s output, and the assistant’s final response.
Common questions
- What makes an agent different from a normal model call?
- A normal model call returns an answer directly. An agent gives the model a chance to request actions before answering. Your program receives that request, runs an approved tool, records the result, and calls the model again with the updated transcript.
- Does the language model execute the tool itself?
- No. The model emits a structured request that describes the tool it wants and the arguments to use. Your application owns execution: it checks the request, calls the actual function or API, captures the output, and adds that output back into the conversation.
- Why print the full message trace when building an agent?
- The trace shows the real control flow. You can see the user request, the model’s tool request, the tool result, and the final response. That makes it clear whether failures come from prompting, argument shape, tool behaviour, missing context, or loop logic.