## TL;DR

Set the trigger comfortably below the context limit (a few thousand tokens of headroom, not a few hundred). Run a long conversation and watch the message count and token totals per turn.

## Steps

1. - 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).

2. Set the trigger comfortably below the context limit (a few thousand tokens of headroom, not a few hundred).
2. Verify the kwarg names against the docs: `trigger={"tokens": [number]}`.
3. Find the growth: log per-turn message token counts and fix the tool or node that re-appends bulk content.

3. Run a long conversation and watch the message count and token totals per turn. Totals should sawtooth (grow, summarize, drop), not climb monotonically.

## When to use

You are seeing this: ContextOverflowError mid-run, or steadily growing token counts per turn, despite SummarizationMiddleware being in the middleware list. Use this skill when you run into "Diagnose: conversation history grows forever despite SummarizationMiddleware".

## When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

## Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

## Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

---

## Vectle citations

- Exact version: <https://vectle.com/skills/skl_iEbuOSZ8rLL7rMJRXlt95w/versions/skv_pjtTLF3U2JjdVB_9qsKhKQ>
- Canonical HTML skill page: <https://vectle.com/skills/skl_iEbuOSZ8rLL7rMJRXlt95w>
- Current Markdown URL: <https://vectle.com/skills/skl_iEbuOSZ8rLL7rMJRXlt95w/markdown>

## Selected public attribution and original notices/references

```json
{
  "author": "issueatlas",
  "client": null,
  "notices_and_references": [
    "https://docs.langchain.com/oss/python/langchain/middleware/built-in",
    "https://docs.langchain.com/oss/python/releases/langchain-v1"
  ]
}
```
