feat(context): opt-in ContextSift context management - #12
Merged
Conversation
Ports the ContextSift approach into SwiftAgentKit as an opt-in feature. When an AgentConfig has a ContextManager set, completed tool exchanges are externalized: each finished tool result becomes a compact one-line receipt in a tool ledger (folded into the system prompt), and its full output is offloaded to an ArtifactStore (default InMemoryArtifactStore) for lossless on-demand retrieval instead of being resent every turn. The single active tool exchange is kept in full (bounded by maxActiveResultChars). Two retrieval tools (artifact_read, artifact_search) are auto-registered when a ContextManager is present so the model can pull back any offloaded output by its artifact id. Leaving contextManager nil preserves prior behavior exactly — makeLLMRequest is unchanged when unset. New files under Sources/SwiftAgentKit/Context/: ArtifactStore.swift, ToolReceipt.swift, ContextManager.swift, ArtifactTools.swift. Regression coverage: completed exchanges collapse to a ledger + artifact and drop from context; active exchange kept; large results spill and round-trip via artifact_read; artifact store read/search. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
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.
Summary
Brings the ContextSift context-management approach into SwiftAgentKit as an opt-in feature. The goal: keep long tool-heavy conversations from ballooning the prompt while never losing information.
When an
AgentConfighas aContextManagerset:ArtifactStore(defaultInMemoryArtifactStore) so it can be retrieved losslessly on demand rather than resent every turn.maxActiveResultChars, so the model always has what it needs to act next.artifact_read(paged) andartifact_search(line-level substring) — are auto-registered so the model can pull back any offloaded output by itsartifact-…id.Leaving
contextManagerasnilpreserves the previous behavior exactly —makeLLMRequestroutes through the manager only when one is set.Files
New under
Sources/SwiftAgentKit/Context/:ArtifactStore.swift—Artifact,ArtifactSlice,ArtifactMatch,protocol ArtifactStore,actor InMemoryArtifactStore.ToolReceipt.swift— compact receipt +ledgerLine().ContextManager.swift— the transformation (modelMessages(_:systemTemplate:)), receipt/artifact spill, active-exchange detection.ArtifactTools.swift—ArtifactReadTool,ArtifactSearchTool.Wiring in
Core/Agent.swift:AgentConfig.contextManager, tool auto-registration inAgent.init,makeLLMRequestmadeasyncand routed through the manager when present.Tests
artifact_read.ArtifactStoreread (paged) and search (line-level).All 93 tests pass (
swift test).🤖 Generated with Claude Code