Skip to content

Commit 0603866

Browse files
feat(summarizing_conversation_manager): introduce docs
1 parent 9936ab7 commit 0603866

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

docs/user-guide/concepts/agents/context-management.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,100 @@ Key features of the `SlidingWindowConversationManager`:
6464
- **Maintains Window Size**: Automatically removes messages from the window if the number of messages exceeds the limit.
6565
- **Dangling Message Cleanup**: Removes incomplete message sequences to maintain valid conversation state.
6666
- **Overflow Trimming**: In the case of a context window overflow, it will trim the oldest messages from history until the request fits in the models context window.
67+
68+
#### SummarizingConversationManager
69+
70+
The [`SummarizingConversationManager`](../../../api-reference/agent.md#strands.agent.conversation_manager.summarizing_conversation_manager.SummarizingConversationManager) implements intelligent conversation context management by summarizing older messages instead of simply discarding them. This approach preserves important information while staying within context limits.
71+
72+
**Basic Usage:**
73+
74+
```python
75+
from strands import Agent
76+
from strands.agent.conversation_manager import SummarizingConversationManager
77+
78+
# Create the summarizing conversation manager with default settings
79+
conversation_manager = SummarizingConversationManager(
80+
summary_ratio=0.3, # Summarize 30% of messages when context reduction is needed
81+
preserve_recent_messages=10, # Always keep 10 most recent messages
82+
)
83+
84+
agent = Agent(
85+
conversation_manager=conversation_manager
86+
)
87+
```
88+
89+
**Advanced Configuration with Custom Summarization Agent:**
90+
91+
```python
92+
from strands import Agent
93+
from strands.agent.conversation_manager import SummarizingConversationManager
94+
from strands.models import AnthropicModel
95+
96+
# Create a cheaper, faster model for summarization tasks
97+
summarization_model = AnthropicModel(
98+
model_id="claude-haiku-4-20250514", # More cost-effective for summarization
99+
max_tokens=1000,
100+
params={"temperature": 0.1} # Low temperature for consistent summaries
101+
)
102+
custom_summarization_agent = Agent(model=summarization_model)
103+
104+
conversation_manager = SummarizingConversationManager(
105+
summary_ratio=0.4,
106+
preserve_recent_messages=8,
107+
summarization_agent=custom_summarization_agent
108+
)
109+
110+
agent = Agent(
111+
conversation_manager=conversation_manager
112+
)
113+
```
114+
115+
**Custom System Prompt for Domain-Specific Summarization:**
116+
117+
```python
118+
from strands import Agent
119+
from strands.agent.conversation_manager import SummarizingConversationManager
120+
121+
# Custom system prompt for technical conversations
122+
custom_system_prompt = """
123+
You are summarizing a technical conversation. Create a concise bullet-point summary that:
124+
- Focuses on code changes, architectural decisions, and technical solutions
125+
- Preserves specific function names, file paths, and configuration details
126+
- Omits conversational elements and focuses on actionable information
127+
- Uses technical terminology appropriate for software development
128+
129+
Format as bullet points without conversational language.
130+
"""
131+
132+
conversation_manager = SummarizingConversationManager(
133+
summary_ratio=0.4,
134+
preserve_recent_messages=8,
135+
summarization_system_prompt=custom_system_prompt
136+
)
137+
138+
agent = Agent(
139+
conversation_manager=conversation_manager
140+
)
141+
```
142+
143+
Key features of the `SummarizingConversationManager`:
144+
145+
- **Context Window Management**: Automatically reduces context when token limits are exceeded
146+
- **Intelligent Summarization**: Uses structured bullet-point summaries to capture key information
147+
- **Tool Pair Preservation**: Ensures tool use and result message pairs aren't broken during summarization
148+
- **Flexible Configuration**: Customize summarization behavior through various parameters
149+
- **Fallback Safety**: Handles summarization failures gracefully
150+
151+
Configuration parameters:
152+
153+
- **`summary_ratio`** (float, default: 0.3): Percentage of messages to summarize when reducing context (clamped between 0.1 and 0.8)
154+
- **`preserve_recent_messages`** (int, default: 10): Minimum number of recent messages to always keep
155+
- **`summarization_agent`** (Agent, optional): Custom agent for generating summaries. If not provided, uses the main agent instance. Cannot be used together with `summarization_system_prompt`.
156+
- **`summarization_system_prompt`** (str, optional): Custom system prompt for summarization. If not provided, uses a default prompt that creates structured bullet-point summaries focusing on key topics, tools used, and technical information in third-person format. Cannot be used together with `summarization_agent`.
157+
158+
How it works:
159+
160+
1. **Proactive Management**: The `apply_management()` method can be extended for proactive context management
161+
2. **Context Reduction**: When context limits are exceeded, `reduce_context()` generates summaries of older messages
162+
3. **Smart Splitting**: Automatically adjusts split points to preserve tool use/result message pairs
163+
4. **Summary Generation**: Creates structured summaries using bullet points, focusing on key topics and technical information

0 commit comments

Comments
 (0)