Guide 2 of 6How AI agents work
  1. Anatomy of an automation
  2. How AI agents work
    1. What an agent is
    2. Step through a run
    3. Tools are the whole game
    4. Context and memory
    5. Workflow or agent?
  3. RAG: answering from your documents
  4. MCP: connecting AI to tools
  5. Guardrails, review and evals
  6. How a project runs

Core concept3 min readUpdated

How AI agents work

A model in a loop with tools: planning, tool calls, context, stop conditions, and when not to use one.

Includes an interactive demo: Agent loop stepper

What an agent is

An AI agent is a model running in a loop with tools. Each turn it looks at the goal and everything that has happened so far, then either calls a tool or decides it is finished. That’s it: no magic, just a loop with good instructions and good tools.

Step through a run

Here is one run of a lead-handling agent. Watch the phase move around the loop and the context grow with every step.

InteractiveOne agent run, step by stepStep forward or press play
  1. Read the goal and plan: The model receives the goal, the available tools and their descriptions. It decides the first step.
  2. Call a tool: It asks to run a tool with arguments. The application, not the model, actually executes it.
  3. Read the result: The tool result goes back into the context. Nothing found, so this is a new contact.
  4. Call the next tool: It creates the contact, then asks a calendar tool for open slots.
  5. Handle a failure: The calendar API times out. The agent reads the error and retries once, as its instructions say.
  6. Check before acting: Sending an email is an outside action, so a guardrail asks: is this allowed without a human? Here it is.
  7. Stop and report: The goal is met, so the loop stops and returns a summary. A step limit would also stop it.

Want to drive one yourself, with failures and approvals? Try Agent Lab.

Tools are the whole game

A model can only do what its tools allow. Each tool is a name, a description the model reads, and a JSON schema for its inputs. Clear names and descriptions matter more than clever prompts.

A tool definitionjson
{
  "name": "calendar.find_slots",
  "description": "Find open 30-60 minute meeting slots on the sales calendar. Use before offering times to a lead.",
  "input_schema": {
    "type": "object",
    "properties": {
      "duration_min": { "type": "integer", "enum": [30, 45, 60] },
      "within_days":  { "type": "integer", "minimum": 1, "maximum": 14 }
    },
    "required": ["duration_min"]
  }
}

Context and memory

Every turn, the whole history goes back to the model, so context grows with each step. Long runs need managing:

  1. Keep tool results shortReturn the 3 fields the agent needs, not the whole API response.
  2. Summarise old turnsReplace early steps with a short summary once they’re no longer needed.
  3. Store facts outsidePut durable facts in a database or notes file the agent can read back.
  4. Set a budgetA hard limit on steps and tokens stops a confused agent from looping forever.

Workflow or agent?

Workflow versus agent
AspectWorkflowAgent
PathFixed, drawn in advanceDecided by the model each turn
Best forRepeatable processesOpen-ended tasks with many possible paths
Cost per runLow and predictableHigher, varies with steps
DebuggingEasy: same path every timeHarder: needs traces and evals
My default✓ Most business processesWhen the path genuinely varies