Repository navigation
feat(tea): compaction fires on input tokens, held image bytes or image count, whichever comes first - #998
Queued
cansirin wants to merge 3 commits into
Queued
feat(tea): compaction fires on input tokens, held image bytes or image count, whichever comes first#998cansirin wants to merge 3 commits into
cansirin wants to merge 3 commits into
Conversation
Keep legacy context-token semantics and route all thresholds through one pure facts reader and exhaustive trigger table. Cover boundaries, freshness, media projection and repeated image-budget crossings through defineAgent.run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Document strict input and byte thresholds, image-only configuration and retained media limits. Regenerate the public agent reference from its source. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Limit the no-usage skip instruction to token settings, so image-only users continue to their independent compaction recipe in the same step. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cansirin
added this pull request to the merge queue
Nov 21, 2026
Any commits made after this event will not be merged.
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.
defineAgentcan now compact when any one of five thresholds holds: the existing turn count and input-plus-output context size, plus three new ones. A model with a per-request image budget needs the new ones: a host that compacts only on tokens sends a request the provider refuses once screenshots pile up.What changed
compaction:afterInputTokens: the last brain turn's reportedusage.inputTokens, cached tokens included, strictly above N;afterImageBytes: held image payload bytes strictly above B (decoded bytes for base64,byteLengthfor bytes, 0 for a URL);afterImageCount: held image parts at or above C.afterTurnsandafterContextTokenskeep their meaning exactly (>=, input plus output).COMPACTION_TRIGGER_RULES(satisfies Record<CompactionTriggerTag, …>), read with.some(...), so any number firing at once folds once. The per-triggerifchain is deleted. The at-least-one-trigger type is derived from the keys, not hand-written.ToolRouter.partsOf) and recounted from the surviving records after a fold, so a folded image stops counting. No second inventory, no counters in state, no I/O:planCompactionstays pure (invariant 2, ADR 0004).Proof
compaction-triggers.test.ts, 17 cases through publicdefineAgent(...).run(...):Uint8Arrayviews, URLs, mixed parts and repeated images are counted correctly;{}and{ keepTurns: 2 }.api:ratchetagainst base 84a500e.Risk
Changeset: minor, Additive (declaration only).
🤖 Generated with Claude Code