Skip to content

Commit 4f885dd

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

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

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

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,108 @@ 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+
Configuration parameters:
73+
74+
- **`summary_ratio`** (float, default: 0.3): Percentage of messages to summarize when reducing context (clamped between 0.1 and 0.8)
75+
- **`preserve_recent_messages`** (int, default: 10): Minimum number of recent messages to always keep
76+
- **`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`.
77+
- **`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`.
78+
79+
**Basic Usage:**
80+
81+
By default, the `SummarizingConversationManager` leverages the same model and configuration as your main agent to perform summarization.
82+
83+
```python
84+
from strands import Agent
85+
from strands.agent.conversation_manager import SummarizingConversationManager
86+
87+
agent = Agent(
88+
conversation_manager=SummarizingConversationManager()
89+
)
90+
```
91+
92+
You can also customize the behavior by adjusting parameters like summary ratio and number of preserved messages:
93+
94+
```python
95+
from strands import Agent
96+
from strands.agent.conversation_manager import SummarizingConversationManager
97+
98+
# Create the summarizing conversation manager with default settings
99+
conversation_manager = SummarizingConversationManager(
100+
summary_ratio=0.3, # Summarize 30% of messages when context reduction is needed
101+
preserve_recent_messages=10, # Always keep 10 most recent messages
102+
)
103+
104+
agent = Agent(
105+
conversation_manager=conversation_manager
106+
)
107+
```
108+
109+
**Custom System Prompt for Domain-Specific Summarization:**
110+
111+
You can customize the summarization behavior by providing a custom system prompt that tailors the summarization to your domain or use case.
112+
113+
```python
114+
from strands import Agent
115+
from strands.agent.conversation_manager import SummarizingConversationManager
116+
117+
# Custom system prompt for technical conversations
118+
custom_system_prompt = """
119+
You are summarizing a technical conversation. Create a concise bullet-point summary that:
120+
- Focuses on code changes, architectural decisions, and technical solutions
121+
- Preserves specific function names, file paths, and configuration details
122+
- Omits conversational elements and focuses on actionable information
123+
- Uses technical terminology appropriate for software development
124+
125+
Format as bullet points without conversational language.
126+
"""
127+
128+
conversation_manager = SummarizingConversationManager(
129+
summarization_system_prompt=custom_system_prompt
130+
)
131+
132+
agent = Agent(
133+
conversation_manager=conversation_manager
134+
)
135+
```
136+
137+
**Advanced Configuration with Custom Summarization Agent:**
138+
139+
For advanced use cases, you can provide a custom `summarization_agent` to handle the summarization process. This enables using a different model (such as a faster or a more cost-effective one), incorporating tools during summarization, or implementing specialized summarization logic tailored to your domain. The custom agent can leverage its own system prompt, tools, and model configuration to generate summaries that best preserve the essential context for your specific use case.
140+
141+
```python
142+
from strands import Agent
143+
from strands.agent.conversation_manager import SummarizingConversationManager
144+
from strands.models import AnthropicModel
145+
146+
# Create a cheaper, faster model for summarization tasks
147+
summarization_model = AnthropicModel(
148+
model_id="claude-haiku-4-20250514", # More cost-effective for summarization
149+
max_tokens=1000,
150+
params={"temperature": 0.1} # Low temperature for consistent summaries
151+
)
152+
custom_summarization_agent = Agent(model=summarization_model)
153+
154+
conversation_manager = SummarizingConversationManager(
155+
summary_ratio=0.4,
156+
preserve_recent_messages=8,
157+
summarization_agent=custom_summarization_agent
158+
)
159+
160+
agent = Agent(
161+
conversation_manager=conversation_manager
162+
)
163+
```
164+
165+
Key features of the `SummarizingConversationManager`:
166+
167+
- **Context Window Management**: Automatically reduces context when token limits are exceeded
168+
- **Intelligent Summarization**: Uses structured bullet-point summaries to capture key information
169+
- **Tool Pair Preservation**: Ensures tool use and result message pairs aren't broken during summarization
170+
- **Flexible Configuration**: Customize summarization behavior through various parameters
171+
- **Fallback Safety**: Handles summarization failures gracefully

0 commit comments

Comments
 (0)