Ultimate

X_AGENT_CONTEXT_EXHAUSTED

Means

an agent's next request would not fit its model's context window

Typical cause

an agent()'s next request was estimated over the model's contextWindow less maxTokens, and auto-compaction (compact, default 'auto') could not bring it under: there were no turns older than keepTurns to summarise, the summary call failed (no text, cut off, refused, unreachable), or the compacted request still did not fit. Raised before the request is sent, never as a truncated transcript — or, as of 2026-11, after a provider refused the turn as over the window (X_AI_CONTEXT_OVERFLOW) and the one forced compaction failed or was refused too (meta.refused holds the provider's text)

Fix

compact: { at: 0.6, keepTurns: 2 } — on the agent — compact earlier and keep fewer turns verbatim; or lower maxToolResultChars, or run on a model whose registerModel row has a larger contextWindow

Listed under MCP and AI

This page as markdown