Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
aws-samples avatar

Strands Context Manager

  • 25 installs
  • 41 repo stars
  • Updated July 6, 2026
  • aws-samples/sample-agent-skills-for-builders

strands-context-manager is a Claude skill that implements a Strands Agents SDK conversation manager combining sliding window and summarization for context management.

About

This skill provides a Strands Agents SDK conversation manager that combines a sliding window with summarization. A developer uses it when building Strands agents with long conversations that need context-window management and compaction. It documents critical pitfalls such as the inheritance trap, infinite recursion, and the hook-closure problem, and shows the implementation pattern.

  • Strands Agents SDK conversation manager combining sliding window and summarization
  • Prevents session pollution in long multi-turn dialogs
  • Documents inheritance, recursion, and hook-closure pitfalls

Strands Context Manager by the numbers

  • 25 all-time installs (skills.sh)
  • Ranked #9,800 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
  • Data as of Jul 30, 2026 (Skillselion catalog sync)
At a glance

strands-context-manager capabilities & compatibility

Capabilities
langgraph agents · token optimization
Use cases
memory · orchestration · token optimization
Pricing
Free
From the docs

What strands-context-manager says it does

Strands conversation/context manager patterns, including sliding window with summarization.
SKILL.md
Strands Agents SDK conversation manager combining sliding window and summarization strategies.
SKILL.md
Use `_is_summarizing` flag with try/finally to prevent recursion during summarization calls.
SKILL.md
npx skills add https://github.com/aws-samples/sample-agent-skills-for-builders --skill strands-context-manager

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs25
repo stars41
Last updatedJuly 6, 2026
Repositoryaws-samples/sample-agent-skills-for-builders

What it does

Implement a Strands Agents conversation manager that combines a sliding window with summarization to manage context and prevent session pollution.

Who is it for?

Developers building Strands agents that need long-conversation context management and compaction.

When should I use this skill?

When building agents with context management, preventing session pollution, or implementing conversation compaction.

What you get

A sliding-window-plus-summarization conversation manager that compacts context without polluting the session.

  • SlidingWindowWithSummarizationManager implementation
  • no-session-pollution test

By the numbers

  • 3 critical pitfalls documented
  • default window_size of 40

Files

SKILL.mdMarkdownGitHub ↗

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 session

References

  • Architecture - Detailed design and testing

Related skills

FAQ

What is the most critical pitfall?

The hook-closure problem: lambda closures capture session_manager references at init, so the summarization agent must be created without session_manager, hooks, or persistence.

Should I inherit from SummarizingConversationManager?

No. Inherit from the base ConversationManager instead.

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.