Skip to content

feat(context): opt-in ContextSift context management - #12

Merged
ayman3000 merged 1 commit into
mainfrom
feat/context-sift-context-management
Jul 27, 2026
Merged

feat(context): opt-in ContextSift context management#12
ayman3000 merged 1 commit into
mainfrom
feat/context-sift-context-management

Conversation

@ayman3000

Copy link
Copy Markdown
Owner

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 AgentConfig has a ContextManager set:

  • The main user/assistant conversation stays intact.
  • Completed tool exchanges are externalized — each finished tool result collapses to 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) so it can be retrieved losslessly on demand rather than resent every turn.
  • The single in-flight (active) tool exchange is kept in full, bounded by maxActiveResultChars, so the model always has what it needs to act next.
  • Two retrieval tools — artifact_read (paged) and artifact_search (line-level substring) — are auto-registered so the model can pull back any offloaded output by its artifact-… id.

Leaving contextManager as nil preserves the previous behavior exactlymakeLLMRequest routes through the manager only when one is set.

Files

New under Sources/SwiftAgentKit/Context/:

  • ArtifactStore.swiftArtifact, ArtifactSlice, ArtifactMatch, protocol ArtifactStore, actor InMemoryArtifactStore.
  • ToolReceipt.swift — compact receipt + ledgerLine().
  • ContextManager.swift — the transformation (modelMessages(_:systemTemplate:)), receipt/artifact spill, active-exchange detection.
  • ArtifactTools.swiftArtifactReadTool, ArtifactSearchTool.

Wiring in Core/Agent.swift: AgentConfig.contextManager, tool auto-registration in Agent.init, makeLLMRequest made async and routed through the manager when present.

Tests

  • Completed exchanges collapse to a ledger + artifact and drop from model context.
  • Active exchange is kept in full.
  • Large tool results spill to an artifact and round-trip via artifact_read.
  • ArtifactStore read (paged) and search (line-level).

All 93 tests pass (swift test).

🤖 Generated with Claude Code

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>
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@ayman3000
ayman3000 merged commit e1dd2cc into main Jul 27, 2026
1 check passed
@ayman3000
ayman3000 deleted the feat/context-sift-context-management branch July 27, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant