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
Copy file name to clipboardExpand all lines: docs/user-guide/concepts/multi-agent/graph.md
+39-39Lines changed: 39 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Graph Multi-Agent Pattern
2
2
3
-
A Graph is a deterministic Directed Acyclic Graph (DAG) based agent orchestration system where agents or other multi-agent systems (like Swarm or nested Graphs) are nodes in a graph. Nodes are executed according to edge dependencies, with output from one node passed as input to connected nodes.
3
+
A Graph is a deterministic Directed Acyclic Graph (DAG) based agent orchestration system where agents or other multi-agent systems (like [Swarm](./swarm.md) or nested Graphs) are nodes in a graph. Nodes are executed according to edge dependencies, with output from one node passed as input to connected nodes.
4
4
5
5
-**Deterministic execution order** based on DAG structure
6
6
-**Output propagation** along edges between nodes
@@ -27,9 +27,39 @@ graph TD
27
27
C --> D
28
28
```
29
29
30
+
## Graph Components
31
+
32
+
### 1. GraphNode
33
+
34
+
A [`GraphNode`](../../../api-reference/multiagent.md#strands.multiagent.graph.GraphNode) represents a node in the graph with:
35
+
36
+
-**node_id**: Unique identifier for the node
37
+
-**executor**: The Agent or MultiAgentBase instance to execute
38
+
-**dependencies**: Set of nodes this node depends on
39
+
-**execution_status**: Current status (PENDING, EXECUTING, COMPLETED, FAILED)
40
+
-**result**: The NodeResult after execution
41
+
-**execution_time**: Time taken to execute the node in milliseconds
42
+
43
+
### 2. GraphEdge
44
+
45
+
A [`GraphEdge`](../../../api-reference/multiagent.md#strands.multiagent.graph.GraphEdge) represents a connection between nodes with:
46
+
47
+
-**from_node**: Source node
48
+
-**to_node**: Target node
49
+
-**condition**: Optional function that determines if the edge should be traversed
50
+
51
+
### 3. GraphBuilder
52
+
53
+
The [`GraphBuilder`](../../../api-reference/multiagent.md#strands.multiagent.graph.GraphBuilder) provides a simple interface for constructing graphs:
54
+
55
+
-**add_node()**: Add an agent or multi-agent system as a node
56
+
-**add_edge()**: Create a dependency between nodes
57
+
-**set_entry_point()**: Define starting nodes for execution
58
+
-**build()**: Validate and create the Graph instance
59
+
30
60
## Creating a Graph
31
61
32
-
To create a Graph, you use the `GraphBuilder` to define nodes, edges, and entry points:
62
+
To create a [`Graph`](../../../api-reference/multiagent.md#strands.multiagent.graph.Graph), you use the [`GraphBuilder`](../../../api-reference/multiagent.md#strands.multiagent.graph.GraphBuilder) to define nodes, edges, and entry points:
You can use a Graph or Swarm as a node within another Graph:
124
+
You can use a [`Graph`](../../../api-reference/multiagent.md#strands.multiagent.graph.Graph) or [`Swarm`](../../../api-reference/multiagent.md#strands.multiagent.swarm.Swarm) as a node within another Graph:
125
125
126
126
```python
127
127
from strands import Agent
@@ -154,7 +154,7 @@ print(f"\n{result}")
154
154
155
155
## Multi-Modal Input Support
156
156
157
-
Graphs support multi-modal inputs like text and images using ContentBlocks:
157
+
Graphs support multi-modal inputs like text and images using [`ContentBlocks`](../../../api-reference/types.md#strands.types.content.ContentBlock):
158
158
159
159
```python
160
160
from strands import Agent
@@ -186,21 +186,21 @@ result = graph(content_blocks)
186
186
187
187
## Asynchronous Execution
188
188
189
-
You can also execute a Graph asynchronously:
189
+
You can also execute a Graph asynchronously by calling the [`invoke_async`](../../../api-reference/multiagent.md#strands.multiagent.graph.Graph.invoke_async) function:
190
190
191
191
```python
192
192
import asyncio
193
193
194
194
asyncdefrun_graph():
195
-
result =await graph.execute_async("Research and analyze market trends...")
195
+
result =await graph.invoke_async("Research and analyze market trends...")
196
196
return result
197
197
198
198
result = asyncio.run(run_graph())
199
199
```
200
200
201
201
## Graph Results
202
202
203
-
When a Graph completes execution, it returns a `GraphResult` object with detailed information:
203
+
When a Graph completes execution, it returns a [`GraphResult`](../../../api-reference/multiagent.md#strands.multiagent.graph.GraphResult) object with detailed information:
204
204
205
205
```python
206
206
result = graph("Research and analyze...")
@@ -256,9 +256,9 @@ Agents can dynamically create and orchestrate graphs by using the `graph` tool a
256
256
257
257
```python
258
258
from strands import Agent
259
-
from strands_tools importgraph
259
+
from strands_tools importagent_graph
260
260
261
-
agent = Agent(tools=[graph], system_prompt="Create a graph of agents to solve the user's query.")
261
+
agent = Agent(tools=[agent_graph], system_prompt="Create a graph of agents to solve the user's query.")
262
262
263
263
agent("Design a TypeScript REST API and then write the code for it")
Copy file name to clipboardExpand all lines: docs/user-guide/concepts/multi-agent/swarm.md
+26-6Lines changed: 26 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,7 @@ swarm = Swarm(
50
50
max_iterations=20,
51
51
execution_timeout=900.0, # 15 minutes
52
52
node_timeout=300.0, # 5 minutes per agent
53
-
repetitive_handoff_detection_window=8,
53
+
repetitive_handoff_detection_window=8,# There must be >= 3 unique agents in the last 8 handoffs
54
54
repetitive_handoff_min_unique_agents=3
55
55
)
56
56
@@ -73,7 +73,7 @@ In this example:
73
73
74
74
## Swarm Configuration
75
75
76
-
The `Swarm` constructor allows you to control the behavior and safety parameters:
76
+
The [`Swarm`](../../../api-reference/multiagent.md#strands.multiagent.swarm.Swarm) constructor allows you to control the behavior and safety parameters:
77
77
78
78
| Parameter | Description | Default |
79
79
|-----------|-------------|---------|
@@ -86,7 +86,7 @@ The `Swarm` constructor allows you to control the behavior and safety parameters
86
86
87
87
## Multi-Modal Input Support
88
88
89
-
Swarms support multi-modal inputs like text and images using ContentBlocks:
89
+
Swarms support multi-modal inputs like text and images using [`ContentBlocks`](../../../api-reference/types.md#strands.types.content.ContentBlock):
90
90
91
91
```python
92
92
from strands import Agent
@@ -166,21 +166,21 @@ You have access to swarm coordination tools if you need help from other agents o
166
166
167
167
## Asynchronous Execution
168
168
169
-
You can also execute a Swarm asynchronously:
169
+
You can also execute a Swarm asynchronously by calling the [`invoke_async`](../../../api-reference/multiagent.md#strands.multiagent.swarm.Swarm.invoke_async) function:
170
170
171
171
```python
172
172
import asyncio
173
173
174
174
asyncdefrun_swarm():
175
-
result =await swarm.execute_async("Design and implement a complex system...")
175
+
result =await swarm.invoke_async("Design and implement a complex system...")
176
176
return result
177
177
178
178
result = asyncio.run(run_swarm())
179
179
```
180
180
181
181
## Swarm Results
182
182
183
-
When a Swarm completes execution, it returns a `SwarmResult` object with detailed information:
183
+
When a Swarm completes execution, it returns a [`SwarmResult`](../../../api-reference/multiagent.md#strands.multiagent.swarm.SwarmResult) object with detailed information:
184
184
185
185
```python
186
186
result = swarm("Design a system architecture for...")
Agents can dynamically create and orchestrate swarms by using the `swarm` tool available in the [Strands tools package](../tools/example-tools-package.md).
211
+
212
+
```python
213
+
from strands import Agent
214
+
from strands_tools import swarm
215
+
216
+
agent = Agent(tools=[swarm], system_prompt="Create a swarm of agents to solve the user's query.")
217
+
218
+
agent("Research, analyze, and summarize the latest advancements in quantum computing")
219
+
```
220
+
221
+
In this example:
222
+
223
+
1. The agent uses the `swarm` tool to dynamically create a team of specialized agents. These might include a researcher, an analyst, and a technical writer
224
+
2. Next the agent executes the swarm
225
+
3. The swarm agents collaborate autonomously, handing off to each other as needed
226
+
4. The agent analyzes the swarm results and provides a comprehensive response to the user
227
+
208
228
## Safety Mechanisms
209
229
210
230
Swarms include several safety mechanisms to prevent infinite loops and ensure reliable execution:
0 commit comments