Raphael Friedmann
← Understanding AI

How an agent uses tools and memory

The loop, one level down: how the model requests a tool, why its whole memory is just the growing transcript, and why long multi-step tasks fall apart.

An agent is a language model in a loop with tools: think, act, observe, repeat. That is the shape. This post opens up the two parts that decide whether an agent is useful in practice or only in a demo: how a tool call really works, and what the agent uses for memory.

How the model asks for a tool

At the start of a task, the runner hands the model a menu: here are the tools you have, what each does, and the arguments each one takes. In practice that’s a machine-readable list, one entry per tool:

{
  "name": "read_file",
  "description": "Return the text contents of a file.",
  "arguments": { "path": "string, the file to read" }
}

When the model wants to use one, it doesn’t write a sentence about it. It emits a structured request the runner can parse exactly:

{ "tool": "read_file", "arguments": { "path": "downloads/report.pdf" } }

The runner validates the request (is this a real tool? are the arguments the right shape?), runs it, and appends the result back into the conversation as a new entry, usually tagged with a tool role so the model can tell its own words apart from what came back from the world. Then the model takes another turn. That handshake, model proposes, runner executes, result returns, is every step of the loop. Where the menu and the code behind each tool come from is a standard of its own, MCP.

The memory is just the transcript

An agent has no separate memory. What it “remembers” mid-task is simply the text so far, the goal plus every think, act, and observe, all concatenated and fed back in on every single turn.

Picture the window as a fixed-width strip that the running task slowly fills from the left:

The context window fills as the task runs
everything the agent knows = the text so far goal ...each step's output piles on... overflow
The transcript only ever grows, never shrinks, so a long enough task eventually runs out of room.

So “memory” and “the prompt” are the same thing. Each turn, the runner rebuilds the whole transcript and the model re-reads it from scratch. (The engine caches the heavy maths so re-reading is cheap, which is the KV cache story, but conceptually the model starts every turn by reading everything again.)

This design is simple, and it is also the central limitation. The transcript only grows: a twenty-step task carries twenty steps of tool output along with it. Two things go wrong as it fills up.

A short task

  • Goal and a few tool results fit easily
  • The model sees the whole history every turn
  • Each decision is made with full information

A long task

  • Transcript grows past the context window
  • Early steps must be dropped or summarised
  • The model starts forgetting its own goal

Making memory last longer

Because the window is finite, practical agents don’t let the transcript grow unchecked. The common fixes:

  1. Summarise the old turns

    When the history gets long, compress the early steps into a short recap and keep only that. The agent trades fine detail for room to keep going.

  2. Keep a scratchpad

    Have the agent write its plan and findings to a small running note, a file or a to-do list, so the important state lives in a few lines instead of buried in pages of tool output.

  3. Store outside, fetch on demand

    Put big things (documents, past results) in external storage and give the agent a search tool. Now it pulls in only the few relevant pieces when it needs them, instead of carrying everything at once.

That last one is why so many agents come with a search or retrieval tool: it turns “remember everything” into “look it up when needed”, which scales far better.

Why long plans fall apart

This explains why long-running agents fail. Each step is a fresh guess, conditioned on a transcript that’s getting longer and noisier with every turn. Three things compound:

  • Errors stack. A small wrong turn at step 3 becomes the context the model trusts at step 4, and the mistake becomes part of the plan.
  • The goal fades. As tool output piles up, the original instruction is a smaller and smaller fraction of what the model is reading. Late in a long run it can genuinely lose the thread.
  • Noisy tools crowd out the signal. A tool that dumps thousands of lines of output uses up the context budget and buries the relevant information. Good agent tools return the answer, not all the raw data.

None of this means agents do not work. It means the ones that work are tightly scoped: small, well-defined tasks, tools that return little, and a check at the end rather than unchecked trust in a twenty-step chain. The skill lies less in writing the prompt than in keeping the loop short enough that each step stays grounded.

Tools also add an attack surface. Text a tool brings back lands in the same context as your instructions, and that is where prompt injection starts.

Which leads to the question that matters once an agent can touch real systems: when to let it act on its own, and when to keep a human in control.