Asked about Managing the context as it grows

An agent overflows its context after ten turns. What do you do?

An answer that works

In order: make tools return less, drop stale tool results, summarise older turns while keeping recent ones verbatim, and offload large payloads to storage with an id the model can use to retrieve them. Moving to a bigger context window is the last resort.

Then they push further

Which of those usually gives the biggest win?

Making tools return less. Tool results are usually most of the context, and a tool that returns a whole record when the model needs three fields fills the window fast. Trimming at the source also cuts cost on every later turn.

What is the risk of summarising older turns?

The summary drops something that matters later: an id, a constraint the user stated, or a failed attempt the agent will now repeat. Keep a structured record of decisions and key facts outside the summary, and keep recent turns word for word.

What gets marked up

Strong answers attack the source of the bloat before compressing, and name what compaction loses. A bigger context window as the first answer is marked down.

Reading an answer is not being able to give one. The section that teaches this is Managing the context as it grows, 4 hours of The agent loop.

Learn this properly