history.WithSummarizer when constructing the conversation manager. Import pkg/agents/history and pkg/agents/history/summariser (the package uses the spelling summariser).
Keep a sliding window
A sliding window retains recent runs without making another model call:Summarize older runs with a model
Given a configuredmodel and persistence adapter:
TokenThreshold is a context-occupancy trigger, not a lifetime token budget. The manager combines the latest provider usage with estimates for messages added since that call. KeepRecentCount preserves recent runs unchanged; despite historical comments referring to messages, grouping is by run. Its default is five.
Leave room below the selected model’s context limit for instructions, tools, new input, and the next response. Tool results can enlarge context between model calls. Summarization itself costs a model call and can fail.
Custom strategies and filters
Implementhistory.HistorySummarizer for another strategy. Its SummaryResult identifies the retained messages and summarization boundary. A history.MessageFilter can alter the messages selected for model input.
Keep related tool calls and outputs together, preserve unresolved interruptions, and test continuation after a summary boundary. Use the transcript APIs for display rather than reconstructing chat history from the shortened model context.