Repository navigation
Clear a long run's old results late, close to the model's own window - #2963
Merged
Merged
Conversation
Every engine cleared old tool results past 100,000 input tokens, whatever
the model. On a model with a 1M window that cleared what a Bot had read
long before it had to: Claude Code on the same model keeps everything
until about 367,000.
shared/context-window.ts holds one rule: clear close to the window of the
model the run is on, as Claude Code compacts. 1M and 400K windows clear at
367,000 (Claude Code's 400K auto window, kept as a cost guard), a 200K
window at 167,000, a 128K window at 95,000, a small one at half its window,
and an unknown window at 100,000 as before. The server says the window of
the model it chose in forwardedProps.openbotContextWindow; a stock AG-UI
agent ignores it.
The LangGraph engine clears from that trigger on every provider, holds its
boundary at 60% of it, and tells Anthropic's context editing the same
trigger. The Claude Agent SDK engine replays more of the thread on a larger
window: 100,000 estimated tokens on a 200K or unknown window as before,
about 238,000 on a 1M window, never past where Claude Code itself would
compact. A connected Bot can declare its model's window in its AG-UI
capabilities, custom["openbot.contextWindow"] = { "tokens": N }, and is
cleared at the same point.
davidmckayv
requested review from
MikeRyanDev,
dustywusty,
guidovizoso,
mxmzb,
samjulien and
tylerslaton
as code owners
December 4, 2026 20:40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
Long runs clear their old tool results late, close to the model's own window. Every engine used to clear past 100,000 input tokens, whatever the model. On a model with a 1M window that threw away what a Bot had read long before it had to: Claude Code on the same model keeps everything until about 367,000.
shared/context-window.tsholds one rule for every engine, the way Claude Code sets its compaction point:autowindow, which leaves 33K for the turn. It stays as a cost guard: every step sends the whole conversation.How each place uses it:
forwardedProps.openbotContextWindow. A stock AG-UI agent ignores it.custom["openbot.contextWindow"] = { "tokens": N }. It is then cleared at the same point as OpenBot's own engines.docs/agent-frameworks.mdsays how.Nothing here is specific to one model or provider. The window comes from the provider's own listing or from models.dev, and the rule is the same for every engine.
How Claude does it (searched 2026-12-04)
autowindow is 400K, "tuned per model for the best cost and performance": "Onautoat 400K, compaction runs at about 367K tokens". At a full 1M it is about 967K. Model configuration, Default auto-compact thresholdstrigger100K andkeep3 tool uses. Context editingAgentCapabilities.customfor integration-specific declarations; OpenBot already readsopenbot.runGuidancethere.Where it runs
forwardedProps.Boundary and audit
API and database
api/, no app's requests, no database change and norelease-policy.json.Changelog
Bots.
custom["openbot.contextWindow"] = { "tokens": N }in its AG-UI capabilities, and OpenBot clears what it sends it at the same point.Proof
Each test was red before the change and green after.
agent-langgraph-ts/test/context-room.test.ts, "A model with a 1M window": a real AG-UI run against a fake provider with a 1M window. OpenAI gets all 60 results whole, and Claude's context editing trigger is 367,000.agent-claude-sdk/tests/test_long_turn_replay.py::test_a_model_with_a_1m_window_replays_far_more_whole: through the adapter, a 45-result thread replays every result whole on a 1M window, and is cut on an unknown window.shared/tests/context-window.test.tspins the rule against real windows.bun test shared: 706 passed.tscand Biome: clean.