Repository navigation
feat(ai): bounded agent context-assembly policy (ADR-0028 Option A) - #94
Merged
Merged
Conversation
ai/agent gains optional maxContextTokens (approximate budget) + contextStrategy (drop-oldest default | summarize). Before each completion the running transcript is bounded by trimContext: it preserves the leading system turns + the first user task and the most recent turns, dropping the oldest middle turns; 'summarize' replaces them with one LLM-generated summary turn (opt-in extra call, recorded as a steps entry). Token estimate is a coarse ~4-chars/token heuristic, centralized for a future tokenizer. Absent budget = unchanged behavior. Persisted cross-run session store (Option B) and vector/RAG (Option C) deferred. ADR-0028 Proposed -> Accepted (Option A shipped). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Second "finish the agents" leaf PR. ADR-0028 Option A — bounded context-assembly.
What
ai/agentgains two optional inputs (backward compatible — absent = today's behavior):maxContextTokens— approximate token budget for the running transcript.contextStrategy—drop-oldest(default, deterministic) |summarize.Before each completion,
trimContext(internal/packages/functions/ai/context.go) bounds thetranscript: it preserves the leading system turns + the first user task and the most recent turns,
dropping the oldest middle turns.
summarizereplaces the dropped span with one LLM-generatedsummary turn (an opt-in extra model call, recorded as a
stepsentry; falls back to drop-oldest onerror). Token estimation is a coarse ~4-chars/token heuristic, centralized so a real tokenizer can
replace it later.
Scope
Persisted cross-run session store (Option B) and vector/RAG memory (Option C) remain deferred.
ADR-0028
Proposed → Accepted(Option A).Verify
make lint0 ·make buildok ·make test706 pass ·make swaggerok.trimContextispure and table-tested (under/over budget, head preservation, recent-turns-exceed-budget).
Next leaf PR: 0030 structured output.
🤖 Generated with Claude Code