Agent FixboardAgentFixboard

Token limit exceeded because retriever output piles up in chat history

A later turn raises BadRequestError with context_length_exceeded. The message in the report is This model's maximum context length is 128000 tokens. However, your messages resulted in 142800 tokens (142586 in the messages, 214 in the functions).

From GitHub

langchain-ai/langgraph

Difficulty
Easy
Time
~5 min
Steps
2
Fixed in
—
Last checked

No upstream fix: these steps work around it. Source: maintainer said it is a context-window limit, not a library bug; no code change. Last checked 2026-10-25.

Symptom

A later turn raises BadRequestError with context_length_exceeded. The message in the report is This model's maximum context length is 128000 tokens. However, your messages resulted in 142800 tokens (142586 in the messages, 214 in the functions).

Evidence what you'll see

  • The traceback is in acall_model while streaming a create_react_agent graph that uses AsyncPostgresSaver.
  • The maintainer comment on 6 Mar 2025 says this is a model context-window limit, not a langgraph or checkpointer bug.

Why it happens

Tool messages from the retriever stay in the checkpointed history, so each turn sends a longer transcript. The model rejects the request when that transcript passes its context limit.

Affected versions

langgraph 0.2.58, langgraph-checkpoint-postgres 2.0.15, langchain 0.3.11, langchain-community 0.3.11. The linked issue does not name an operating system.

Fix steps

0 of 2 done

Your check marks stay in this browser only.

How to check it worked

  • A later turn on the same thread no longer raises BadRequestError for context_length_exceeded.

If it still fails

  • The linked issue does not include a library patch. It was closed completed because the maintainer classed it as a context limit. The stored checkpoint still holds the old tool messages until the history is trimmed.

Sources and credit

Summarized in our own words from these public reports. Credit goes to their authors.

Provided as is, without warranty. Try changes in a non-production environment and back up first. Security-related steps: verify against the official docs. Terms · Request removal or attribution change

Hit an error we don't cover? Submit it