feat(context): add context manager class#2547
Draft
lizradway wants to merge 1 commit into
Draft
Conversation
06171e3 to
a1337f0
Compare
a1337f0 to
a97206c
Compare
a97206c to
8f0feca
Compare
8f0feca to
3ef3431
Compare
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.
Description
Implements the v1
contextManagerfacade as designed in strands-agents/docs#831.Adds a
contextManagerparameter toAgentConfigthat pre-composes the SDK's context management primitives into a single configuration surface. An internalContextManagerplugin composes sub-plugins (ContextCompression,ContextOffloader) that handle the actual behavior.Architecture
Sub-plugins work independently when used standalone. User-provided plugins with matching names take precedence over managed sub-plugins. When
contextManageris set,ContextCompressiontakes priority —NullConversationManageris used (same pattern as other dedicated-param plugins likeretryStrategy,sessionManager).What ships
contextManagerparameter onAgentConfig— accepts"auto"or a config objectContextCompressionplugin — proactive/reactive compression with own reduction logic (truncate or summarize)ContextOffloader— stays invended-plugins/context-offloader/, composed internally by ContextManagercontext-manager/compression/pin-message) —pinMessageToolfor agent-controlled pinning at runtime. Internal utilities (pinMessage,unpinMessage,isPinned) are not exported; programmatic pinning API (e.g.,Message.pin()) deferred.estimateInputTokens()utility — shared token estimation insrc/context-manager/token-estimation.tsprotectedMessageRange— positive protects first N, negative protects last N messages from evictionconversationManagermarked as pending deprecation — still works, JSDoc-taggedPublic API Surface
New on
AgentConfig:contextManager?: ContextManagerParamNew exports:
pinMessageTool(agent-invokable tool)ContextManagerParam,ContextManagerConfig,ContextStrategyValue,OffloaderConfig,CompressionConfig,CompressionOptions,TruncateCompressionConfig,SummarizeCompressionConfig,CompressionMethodAll classes (
ContextManager,ContextCompression,ContextOffloader) are internal.ContextOffloaderremains accessible via thevended-plugins/context-offloadersub-path for backward compat.Configuration model
Two semantics depending on whether
strategy: 'auto'is present:Override (strategy: 'auto') — starts with everything enabled, you override specific settings:
Additive (no strategy) — starts with nothing, you enable what you want:
Plugin registration
contextManagermust be passed via the dedicated parameter — same pattern asconversationManager,retryStrategy, andsessionManager. No guards for misuse inplugins[](consistent with other special-cased plugins).Deprecation Plan
The following are marked as pending deprecation in v1 and will be removed in v2:
AgentConfig.conversationManager→contextManager: { compression: ... }Agent._estimateInputTokens()→ sharedestimateInputTokens()utilityBeforeModelCallEvent.projectedInputTokens→ futurecontextManagerbudget APIConversationManager,SlidingWindowConversationManager,SummarizingConversationManager,NullConversationManager→ContextCompressionpluginvended-plugins/context-offloader/sub-path → import from@strands-agents/sdkdirectlyBreaking Changes
None. All changes are additive. Existing behavior is unchanged when
contextManageris not set.Related Issues
Documentation PR
strands-agents/docs#831
Type of Change
New feature
Testing
How have you tested the change?
npm run checknpm run type-check)npm run lint)Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.