You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Include multi-agent session management to current (#306)
* feat: include multi-agent session management to current
* fix: rename multi-agents to multi-agent systems
* fix: add a warning to avoid mix usage of session manager in multiagent systems
Copy file name to clipboardExpand all lines: docs/user-guide/concepts/agents/session-management.md
+94-17Lines changed: 94 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,18 +4,30 @@ Session management in Strands Agents provides a robust mechanism for persisting
4
4
5
5
## Overview
6
6
7
-
A session represents all of the stateful information that is needed by an agent to function, including:
7
+
A session represents all of stateful information that is needed by agents and multi-agent systems to function, including:
8
8
9
+
**Single Agent Sessions**:
9
10
- Conversation history (messages)
10
11
- Agent state (key-value storage)
11
12
- Other stateful information (like [Conversation Manager](./state.md#conversation-manager))
12
13
13
-
Strands provides built-in session persistence capabilities that automatically capture and restore this information, allowing agents to seamlessly continue conversations where they left off.
14
+
**Multi-Agent Sessions**:
15
+
- Orchestrator state and configuration
16
+
- Individual agent states and result within the orchestrator
17
+
- Cross-agent shared state and context
18
+
- Execution flow and node transition history
19
+
20
+
Strands provides built-in session persistence capabilities that automatically capture and restore this information, allowing agents and multi-agent systems to seamlessly continue conversations where they left off.
14
21
15
22
Beyond the built-in options, [third-party session managers](#third-party-session-managers) provide additional storage and memory capabilities.
16
23
24
+
!!! warning
25
+
You cannot use a single agent with session manager in a multi-agent system. This will throw an exception. Each agent in a multi-agent system must be created without a session manager, and only the orchestrator should have the session manager. Additionally, multi-agent session managers only track the current state of the Graph/Swarm execution and do not persist individual agent conversation histories.
26
+
17
27
## Basic Usage
18
28
29
+
### Single Agent Sessions
30
+
19
31
Simply create an agent with a session manager and use it:
20
32
21
33
```python
@@ -34,6 +46,31 @@ agent("Hello!") # This conversation is persisted
34
46
35
47
The conversation, and associated state, is persisted to the underlying filesystem.
36
48
49
+
### Multi-Agent Sessions
50
+
51
+
Multi-agent systems(Graph/Swarm) can also use session management to persist their state:
52
+
53
+
```python
54
+
from strands.multiagent import Graph
55
+
from strands.session.file_session_manager import FileSessionManager
# Use the graph - all orchestrator state is persisted
71
+
result = graph("Research and write about AI")
72
+
```
73
+
37
74
## Built-in Session Managers
38
75
39
76
Strands offers two built-in session managers for persisting agent sessions:
@@ -43,7 +80,7 @@ Strands offers two built-in session managers for persisting agent sessions:
43
80
44
81
### FileSessionManager
45
82
46
-
The [`FileSessionManager`](../../../api-reference/session.md#strands.session.file_session_manager.FileSessionManager) provides a simple way to persist agent sessions to the local filesystem:
83
+
The [`FileSessionManager`](../../../api-reference/session.md#strands.session.file_session_manager.FileSessionManager) provides a simple way to persist both single agent and multi-agent sessions to the local filesystem:
# Use the agent normally - state and messages will be persisted to S3
106
157
agent("Tell me about AWS S3")
158
+
159
+
# Use with multi-agent orchestrator
160
+
swarm = Swarm(
161
+
agents=[agent1, agent2, agent3],
162
+
session_manager=session_manager
163
+
)
164
+
165
+
result = swarm("Coordinate the task across agents")
107
166
```
108
167
#### S3 Storage Structure
109
168
@@ -113,12 +172,15 @@ Just like in the [`FileSessionManager`](../../../api-reference/session.md#strand
113
172
<s3_key_prefix>/
114
173
└── session_<session_id>/
115
174
├── session.json # Session metadata
116
-
└── agents/
117
-
└── agent_<agent_id>/
118
-
├── agent.json # Agent metadata and state
119
-
└── messages/
120
-
├── message_<message_id>.json
121
-
└── message_<message_id>.json
175
+
├── agents/ # Single agent storage
176
+
│ └── agent_<agent_id>/
177
+
│ ├── agent.json # Agent metadata and state
178
+
│ └── messages/
179
+
│ ├── message_<message_id>.json
180
+
│ └── message_<message_id>.json
181
+
└── multi_agents/ # Multi-agent storage
182
+
└── multi_agent_<orchestrator_id>/
183
+
└── multi_agent.json # Orchestrator state and configuration
122
184
```
123
185
124
186
#### Required S3 Permissions
@@ -160,13 +222,19 @@ The session management system in Strands Agents works through a combination of e
160
222
161
223
### 1. Session Persistence Triggers
162
224
163
-
Session persistence is automatically triggered by several key events in the agent lifecycle:
225
+
Session persistence is automatically triggered by several key events in the agent and multi-agent lifecycle:
164
226
227
+
**Single Agent Events**
165
228
-**Agent Initialization**: When an agent is created with a session manager, it automatically restores any existing state and messages from the session.
166
229
-**Message Addition**: When a new message is added to the conversation, it's automatically persisted to the session.
167
230
-**Agent Invocation**: After each agent invocation, the agent state is synchronized with the session to capture any updates.
168
231
-**Message Redaction**: When sensitive information needs to be redacted, the session manager can replace the original message with a redacted version while maintaining conversation flow.
169
232
233
+
**Multi-Agent Events:**
234
+
-**Multi-Agent Initialization**: When an orchestrator is created with a session manager, it automatically restores state from the session.
235
+
-**Node Execution**: After each node invocation, synchronizes orchestrator state after node transitions
236
+
-**Multi-Agent Invocation**: After multiagent finished, captures final orchestrator state after execution
237
+
170
238
!!! warning "After initializing the agent, direct modifications to `agent.messages` will not be persisted. Utilize the [Conversation Manager](./conversation-management.md) to help manage context of the agent in a way that can be persisted."
171
239
172
240
@@ -181,7 +249,7 @@ The [`Session`](../../../api-reference/types.md#strands.types.session.Session) m
181
249
-**Purpose**: Provides a namespace for organizing multiple agents and their interactions
182
250
-**Key Fields**:
183
251
-`session_id`: Unique identifier for the session
184
-
-`session_type`: Type of session (currently "AGENT")
252
+
-`session_type`: Type of session (currently "AGENT" for both agent & multiagent in order to keep backward compatibility)
185
253
-`created_at`: ISO format timestamp of when the session was created
186
254
-`updated_at`: ISO format timestamp of when the session was last updated
187
255
@@ -211,6 +279,14 @@ The [`SessionMessage`](../../../api-reference/types.md#strands.types.session.Ses
211
279
212
280
These data models work together to provide a complete representation of an agent's state and conversation history. The session management system handles serialization and deserialization of these models, including special handling for binary data using base64 encoding.
213
281
282
+
**Multi-Agent State**
283
+
284
+
Multi-agent systems serialize their state as JSON objects containing:
285
+
286
+
-**Orchestrator Configuration**: Settings, parameters, and execution preferences
287
+
-**Node State**: Current execution state and node transition history
288
+
-**Shared Context**: Cross-agent shared state and variables
289
+
214
290
## Third-Party Session Managers
215
291
216
292
The following third-party session managers extend Strands with additional storage and memory capabilities:
@@ -277,3 +353,4 @@ When implementing session persistence in your applications, consider these best
277
353
278
354
-**Understand Persistence Triggers**: Remember that changes to agent state or messages are only persisted during specific lifecycle events
279
355
356
+
-**Concurrent Access**: Session managers are not thread-safe; use appropriate locking for concurrent access
0 commit comments