feat(context): add context_manager="auto" facade on Agent#2643
Conversation
One-liner that composes ContextOffloader + SummarizingConversationManager with benchmark-validated defaults (1500/750 token thresholds, 0.3 summary ratio). Saves 54% tokens on Sonnet, improves code retrieval by 20% on complex tasks with Opus.
Adds proactive compression (compression_threshold=0.85) to the default SummarizingConversationManager created by context_manager="auto". This triggers context reduction before hitting the window limit.
|
Assessment: Comment Clean, well-scoped feature that aligns with the SDK tenets (simple at any scale, extensible by design). The coexistence rules are well thought out. Review Themes
Nice feature that makes context management accessible in a single parameter — well aligned with "simple things should be simple." |
- Move stateful model validation before resolution (avoid unnecessary allocation) - Update error message to mention both context_manager and conversation_manager - Add runtime ValueError for unsupported context_manager values - Add compression_threshold=0.85 to docstring - Expand _resolve_context_manager docstring with full Args/Returns/Raises - Fix MyPlugin test to inherit from Plugin ABC - Add test for unsupported value error
|
Assessment: Approve All previous feedback has been addressed — the code now validates before constructing, has accurate error messages, includes runtime guards for unsupported values, and has complete documentation. Changes verified
One remaining consideration: this introduces a new public API parameter on |
Same facade as the Python SDK — one-liner that composes ContextOffloader (maxResultTokens=1500, previewTokens=750) with SummarizingConversationManager (summaryRatio=0.3, compressionThreshold=0.85) using benchmark-validated defaults.
|
Assessment: Approve Clean, opt-in facade that composes benchmark-validated context management primitives behind a single parameter. Pay-for-play design (existing agents unaffected), proper validation ordering, and comprehensive cross-SDK test coverage. Remaining Items
Well-aligned with "simple things should be simple" and "provide both low-level and high-level APIs" tenets. |
|
Assessment: Approve Well-designed opt-in facade that composes benchmark-validated context management primitives ( Review Details
The |
|
Assessment: Approve Clean opt-in facade that composes Review Details
The implementation is well-structured, test coverage is comprehensive across both SDKs, and the coexistence semantics (user CM precedence, offloader dedup, stateful model guard) are correct and consistent. |
- TS: CM_* → CONTEXT_MANAGER_* constants - Tests: user_cm → user_conversation_manager, cm → conversationManager
|
Assessment: Approve Well-designed opt-in facade — all prior feedback addressed, cross-SDK consistency is solid, durability caveat now documented in both SDKs. One remaining item
|
Description
Adds
contextManager: "auto"/context_manager="auto"as an opt-in parameter onAgentin both SDKs. When set, it wires up the benchmark-winning context management configuration:ContextOffloader(storage=InMemoryStorage(), maxResultTokens=1500, previewTokens=750)— caches oversized tool results, keeps truncated previews in context, providesretrieve_offloaded_contenttoolSummarizingConversationManager(summaryRatio=0.3, compressionThreshold=0.85)— summarizes older messages on context overflow, proactively compresses at 85% context window usageCoexistence rules:
conversationManager, theirs is used (offloader still added)ContextOffloaderin their plugins list, it's not overriddenRelated Issues
strands-agents/docs#831
Documentation PR
N/A — docs PR (strands-agents/docs#831) covers the design. User-facing docs page to follow once this ships.
Type of Change
New feature
Testing
hatch fmt --linter --checkpasses (ruff + mypy)tsc --noEmitpasseshatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.