strands-context-manager
Skill51 starsChanged 3 months agoApache-2.0View on GitHub
Strands conversation/context manager patterns, including sliding window with summarization. Use when building agents with context management, preventing session pollution, or implementing conversation compaction.
In this repository16 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- agentcore-browser-web-scrapingSkill
- agentcore-mcp-oauth-facadeSkill
- agentic-responsible-ai-assessmentSkill
- api-gateway-authorizer-securitySkill
- aws-agentic-aiSkill
- aws-cdk-developmentSkill
- aws-cost-operationsSkill
- aws-mcp-setupSkill
- cost-estimatorSkill
- create-install-scriptsSkill
- end-to-end-testingSkill
- gitlab-docs-publishingSkill
- quip-to-gitlab-wikiSkill
- security-scanSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 29
Use _is_summarizing flag with try/finally to prevent recursion during summarization calls.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Strands Context Manager (Sliding Window with Summarization)
Strands Agents SDK conversation manager combining sliding window and summarization strategies.
When to Apply
Reference this skill when:
- Building Strands agents with long conversations
- Implementing context window management
- Preventing session pollution in multi-turn dialogs
- Combining sliding window with summarization
Critical Pitfalls
1. Inheritance Pitfall
DON'T inherit from SummarizingConversationManager.
DO inherit from base ConversationManager.
2. Infinite Recursion
Use _is_summarizing flag with try/finally to prevent recursion during summarization calls.
3. Hook Closure Problem (MOST CRITICAL)
Lambda closures capture session_manager references during initialization. Create summarization agent WITHOUT session_manager, hooks, or persistence.
Implementation Pattern
class SlidingWindowWithSummarizationManager(ConversationManager):
def __init__(self, window_size=40, summarization_agent=None, summarization_system_prompt=None):
self._is_summarizing = False
self._summarization_agent = summarization_agent # Lazy init when None
def _get_summarization_agent(self):
# Create clean agent without session_manager
return Agent(
# NO session_manager, NO hooks
)Usage
from conversation_manager import SlidingWindowWithSummarizationManager
manager = SlidingWindowWithSummarizationManager(
window_size=20,
)Critical Test
def test_no_session_pollution():
# Verify internal messages don't persist
# Verify no "Please summarize" in sessionReferences
- Architecture - Detailed design and testing
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

