AI Agents
Understand AI concepts by exploring diagrams that move. Scenarios: Coding agent, Finance assistant.
An AI agent from far away. You ask, it works for you, it reports back.
- You
- You give the agent a goal in plain words.
- Agent
- A program around the model. It keeps the work going step by step and acts on the model's behalf. People also call it the harness.
- Model
- The LLM. It reads text and writes text. It decides the next step but can't touch anything itself.
- Tools
- The actions the agent can take for the model.
- Codebase / Bank data
- What the agent works on for you. It only knows what it has read.
Inside the agent: the same loop, turn after turn, until the model stops asking for tools.
- Context
- Everything the model sees on this turn: your goal, the tool list and every result so far. It grows each turn.
- Model
- The same model every turn. Only the Context changes.
- Decision
- Each turn, the model either answers or asks to use a tool.
- Tool call
- The model's request to act.
- Tool result
- What came back. It gets added to the Context.
- Stop
- The loop ends when the model answers without asking for a tool, or hits a limit.
One tool call, up close. The model only asks. The agent acts.
- Tool definitions
- The menu of tools the model is shown before it chooses.
- Call
- A structured request: a name plus arguments. It's text, not an action.
- Permission
- The agent may ask you before it acts.
- Agent runs it
- The agent runs the tool, not the model. The model only asks.
- Result
- The output goes back as text. Errors count as results too.
One tool, taken apart. Every tool has the same four parts.
- Name
- What the model writes to pick the tool.
- Description
- Plain words telling the model when to use the tool. The model chooses based on this, so the description is effectively a prompt.
- Input schema
- The shape the arguments must take. The agent checks each call against it.
- Code behind it
- An ordinary function that the agent runs.
- More examples
- Every tool has the same four parts.
The same loop, seen from its exits. Tool calls keep it going. The finish reason only explains why it stopped.
- Tool calls?
- After every response the agent asks one question: did the model ask for a tool? Yes, it runs them and goes round. No, the turn is over.
- Iteration cap
- A limit on round-trips to the model, not on tool calls. Several calls in one response count once. When it fires, the agent gives up with no answer. It's checked as the loop comes back round, so the tools on the last lap still run, and the model never sees what they did. Harmless for a read. Not for an edit. That's where Asking first comes in.
- Finish reason
- Why the model stopped writing. Read it only after the loop ends, to tell a whole answer from a broken one. Don't loop on it: some APIs, like OpenAI's Responses API, leave it empty even when the model asked for tools.
- Answer
- The normal exit: no tool call, and a finished reply. OpenAI calls it stop, Anthropic end_turn.
- Cut off
- The model ran out of output tokens mid-answer. OpenAI says length, Anthropic max_tokens. Skip this check and half an answer looks like a whole one.
- Blocked
- The provider's filter stopped the reply. OpenAI says content_filter, Anthropic refusal. Rare day to day. Like Cut off, it tends to show up first in production.
One risky call, stopped at the gate. You can tell the model to be careful. Only the gate makes sure.
- Marked tool
- Tools that change things are marked when they're registered: editing a file, running a command, importing a statement. The model doesn't decide what needs asking. Many agents also let you always allow the safe ones. An agent that can only read can't be talked into a change.
- Gate
- One check in the agent's loop, right before a call becomes an action. It's the only place that can stop it, because the model only asks. If the model also asks you in the chat, you get asked twice and learn to click through. So the model is told not to ask, and the gate does it.
- What you see
- The call and its arguments, before anything runs. Without the arguments, you're approving blind.
- Allow
- The agent runs the tool. Only a clear yes counts.
- Decline
- It goes back to the model as a normal result, not an error: the user declined, don't retry. So the model answers instead of trying again.
- Injected instruction
- Text inside a file or a tool result that tells the model to do something. The model can't always tell it apart from what you asked. The gate doesn't care why the model asked.
The model remembers nothing. The agent sends it everything, every turn.
- System prompt
- The agent's standing instructions, first in the Context on every turn. When history gets summarised, it stays as it is, or the agent forgets what it's for.
- History
- Every message so far: what you asked, every tool call, every result. The agent sends all of it again on every turn, because the model keeps nothing between calls.
- Context window
- How much the model can read in one go. Every turn reads the whole history again, so you pay for it again. You notice the bill before you hit the limit.
- Summary
- Past a threshold, the agent asks the model to fold the old turns into one summary message. It's a model call too. The summary decides what survives, and a summary of a summary drifts: facts get lost.
- Recent tail
- The last few messages, kept word for word after a summary. A tool call and its result always travel together, or the next request fails.
- Memory file
- What survives between sessions. A file of notes the agent reads into the Context at the start, like your project's conventions. It only holds what someone wrote down. Everything else starts from zero.
All Topics