Skip to content

Commit 570add1

Browse files
authored
docs: Add multi-agent streaming docs (#284)
1 parent 1f2c3b9 commit 570add1

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed

docs/user-guide/concepts/multi-agent/graph.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,51 @@ async def run_graph():
291291
result = asyncio.run(run_graph())
292292
```
293293

294+
## Streaming Events
295+
296+
Graphs support real-time streaming of events during execution using [`stream_async`](../../../api-reference/multiagent.md#strands.multiagent.graph.Graph.stream_async). This provides visibility into node execution, parallel processing, and nested multi-agent systems.
297+
298+
```python
299+
from strands import Agent
300+
from strands.multiagent import GraphBuilder
301+
302+
# Create specialized agents
303+
researcher = Agent(name="researcher", system_prompt="You are a research specialist...")
304+
analyst = Agent(name="analyst", system_prompt="You are an analysis specialist...")
305+
306+
# Build the graph
307+
builder = GraphBuilder()
308+
builder.add_node(researcher, "research")
309+
builder.add_node(analyst, "analysis")
310+
builder.add_edge("research", "analysis")
311+
builder.set_entry_point("research")
312+
graph = builder.build()
313+
314+
# Stream events during execution
315+
async for event in graph.stream_async("Research and analyze market trends"):
316+
# Track node execution
317+
if event.get("type") == "multiagent_node_start":
318+
print(f"🔄 Node {event['node_id']} starting")
319+
320+
# Monitor agent events within nodes
321+
elif event.get("type") == "multiagent_node_stream":
322+
inner_event = event["event"]
323+
if "data" in inner_event:
324+
print(inner_event["data"], end="")
325+
326+
# Track node completion
327+
elif event.get("type") == "multiagent_node_stop":
328+
node_result = event["node_result"]
329+
print(f"\n✅ Node {event['node_id']} completed in {node_result.execution_time}ms")
330+
331+
# Get final result
332+
elif event.get("type") == "multiagent_result":
333+
result = event["result"]
334+
print(f"Graph completed: {result.status}")
335+
```
336+
337+
See the [streaming overview](../streaming/overview.md#multi-agent-events) for details on all multi-agent event types.
338+
294339
## Graph Results
295340

296341
When a Graph completes execution, it returns a [`GraphResult`](../../../api-reference/multiagent.md#strands.multiagent.graph.GraphResult) object with detailed information:

docs/user-guide/concepts/multi-agent/swarm.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,47 @@ async def run_swarm():
186186
result = asyncio.run(run_swarm())
187187
```
188188

189+
## Streaming Events
190+
191+
Swarms support real-time streaming of events during execution using [`stream_async`](../../../api-reference/multiagent.md#strands.multiagent.swarm.Swarm.stream_async). This provides visibility into agent collaboration, handoffs, and autonomous coordination.
192+
193+
```python
194+
from strands import Agent
195+
from strands.multiagent import Swarm
196+
197+
# Create specialized agents
198+
coordinator = Agent(name="coordinator", system_prompt="You coordinate tasks...")
199+
specialist = Agent(name="specialist", system_prompt="You handle specialized work...")
200+
201+
# Create swarm
202+
swarm = Swarm([coordinator, specialist])
203+
204+
# Stream events during execution
205+
async for event in swarm.stream_async("Design and implement a REST API"):
206+
# Track node execution
207+
if event.get("type") == "multiagent_node_start":
208+
print(f"🔄 Agent {event['node_id']} taking control")
209+
210+
# Monitor agent events
211+
elif event.get("type") == "multiagent_node_stream":
212+
inner_event = event["event"]
213+
if "data" in inner_event:
214+
print(inner_event["data"], end="")
215+
216+
# Track handoffs
217+
elif event.get("type") == "multiagent_handoff":
218+
from_nodes = ", ".join(event['from_node_ids'])
219+
to_nodes = ", ".join(event['to_node_ids'])
220+
print(f"\n🔀 Handoff: {from_nodes}{to_nodes}")
221+
222+
# Get final result
223+
elif event.get("type") == "multiagent_result":
224+
result = event["result"]
225+
print(f"\nSwarm completed: {result.status}")
226+
```
227+
228+
See the [streaming overview](../streaming/overview.md#multi-agent-events) for details on all multi-agent event types.
229+
189230
## Swarm Results
190231

191232
When a Swarm completes execution, it returns a [`SwarmResult`](../../../api-reference/multiagent.md#strands.multiagent.swarm.SwarmResult) object with detailed information:

docs/user-guide/concepts/streaming/overview.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,33 @@ All streaming methods yield the same set of events:
4141
- `reasoning_signature`: Signature from reasoning process
4242
- `redactedContent`: Reasoning content redacted by the model
4343

44+
### Multi-Agent Events
45+
46+
Multi-agent systems ([Graph](../multi-agent/graph.md) and [Swarm](../multi-agent/swarm.md)) emit additional coordination events:
47+
48+
- `multiagent_node_start`: When a node begins execution
49+
- `type`: `"multiagent_node_start"`
50+
- `node_id`: Unique identifier for the node
51+
- `node_type`: Type of node (`"agent"`, `"swarm"`, `"graph"`)
52+
- `multiagent_node_stream`: Forwarded events from agents/multi-agents with node context
53+
- `type`: `"multiagent_node_stream"`
54+
- `node_id`: Identifier of the node generating the event
55+
- `event`: The original agent event (nested)
56+
- `multiagent_node_stop`: When a node completes execution
57+
- `type`: `"multiagent_node_stop"`
58+
- `node_id`: Unique identifier for the node
59+
- `node_result`: Complete NodeResult with execution details, metrics, and status
60+
- `multiagent_handoff`: When control is handed off between agents (Swarm) or batch transitions (Graph)
61+
- `type`: `"multiagent_handoff"`
62+
- `from_node_ids`: List of node IDs completing execution
63+
- `to_node_ids`: List of node IDs beginning execution
64+
- `message`: Optional handoff message (typically used in Swarm)
65+
- `multiagent_result`: Final multi-agent result
66+
- `type`: `"multiagent_result"`
67+
- `result`: The final GraphResult or SwarmResult
68+
69+
See [Graph streaming](../multi-agent/graph.md#streaming-events) and [Swarm streaming](../multi-agent/swarm.md#streaming-events) for usage examples.
70+
4471
## Quick Examples
4572

4673
### Async Iterator Pattern

0 commit comments

Comments
 (0)