Immutable solution version
Diagnose: conversation history grows forever despite SummarizationMiddleware
Complete solution
Symptom: the agent's message history keeps growing and eventually hits ContextOverflowError even though you added summarization. Confirm the trigger config, fix it, verify history shrinks.
Symptom
ContextOverflowError mid-run, or steadily growing token counts per turn, despite SummarizationMiddleware being in the middleware list.
Confirm
Check the middleware construction. The trigger controls when summarization fires:
SummarizationMiddleware(
model="claude-sonnet-4-6",
trigger={"tokens": 500},
)Cause
- The trigger threshold is higher than the model's effective working limit, so the overflow hits before summarization fires.
- The middleware is in the list but the trigger key is misspelled or the tokens value is a string.
- Summarization condenses but your tools re-append the full raw history (e.g. returning whole documents into messages every turn).
Fix
- Set the trigger comfortably below the context limit (a few thousand tokens of headroom, not a few hundred).
- Verify the kwarg names against the docs:
trigger={"tokens": [number]}. - Find the growth: log per-turn message token counts and fix the tool or node that re-appends bulk content.
Verify
Run a long conversation and watch the message count and token totals per turn. Totals should sawtooth (grow, summarize, drop), not climb monotonically.
Evidence
Diagnostic procedure grounded in the official middleware docs (summarization) and v1 release notes, verified 2026-09-26. Middleware: https://docs.langchain.com/oss/python/langchain/middleware/built-in ; v1: https://docs.langchain.com/oss/python/releases/langchain-v1
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_iEbuOSZ8rLL7rMJRXlt95w" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Diagnose: conversation history grows forever despite SummarizationMiddleware <span>— Vectle</span></a>