liveBook · Manning

Context pruning

As explained in AI Agents in Action, Second Edition

Context trimming is the selective summarization or removal of conversation history, tool information, attachments, or other context before a model call.

Context trimming reduces the tokens sent on each model call by summarizing or removing conversation history, dropping irrelevant tool descriptions, or constraining response length with structured outputs. section 8.3.8

Unlike caching or model routing, which reduce costs through reuse or model selection, trimming changes the context sent to the model. Tight summaries can save tokens but weaken coherence across multi-turn conversations. section 8.3.8

Use trimming selectively:

  • Summarize or remove conversation history that does not need to be sent on every call. section 8.3.8
  • Drop irrelevant tool descriptions or use structured outputs to constrain response length. section 8.3.8
  • Measure cost per session, resolved task, and user before optimizing; weigh savings against coherence and the value being produced. section 8.3.8

How AI Agents in Action, Second Edition covers it

How deep it goes
Defines trimming through context summarization or removal and identifies a coherence trade-off, without prescribing a detailed workflow.
Examples
Uses conversation-history summarization or removal, irrelevant tool-description removal, and structured outputs that constrain response length.
What you can do after
Apply context trimming by summarizing or removing history and irrelevant tool descriptions, or constraining response length with structured outputs.
How it connects
Connects context trimming with conversation history, tool descriptions, structured outputs, caching, model routing, and cost-to-value measurement.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Agents in Action, Second Edition. The section links point to the parts of the book it draws on.