Skip to content

Commit c4ddf99

Browse files
committed
PR feedback
1 parent a3f1c74 commit c4ddf99

File tree

2 files changed

+65
-45
lines changed

2 files changed

+65
-45
lines changed

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

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Graph Multi-Agent Pattern
22

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.
44

55
- **Deterministic execution order** based on DAG structure
66
- **Output propagation** along edges between nodes
@@ -27,9 +27,39 @@ graph TD
2727
C --> D
2828
```
2929

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+
3060
## Creating a Graph
3161

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:
3363

3464
```python
3565
from strands import Agent
@@ -70,36 +100,6 @@ print(f"\nStatus: {result.status}")
70100
print(f"Execution order: {[node.node_id for node in result.execution_order]}")
71101
```
72102

73-
## Graph Components
74-
75-
### 1. GraphNode
76-
77-
A `GraphNode` represents a node in the graph with:
78-
79-
- **node_id**: Unique identifier for the node
80-
- **executor**: The Agent or MultiAgentBase instance to execute
81-
- **dependencies**: Set of nodes this node depends on
82-
- **execution_status**: Current status (PENDING, EXECUTING, COMPLETED, FAILED)
83-
- **result**: The NodeResult after execution
84-
- **execution_time**: Time taken to execute the node in milliseconds
85-
86-
### 2. GraphEdge
87-
88-
A `GraphEdge` represents a connection between nodes with:
89-
90-
- **from_node**: Source node
91-
- **to_node**: Target node
92-
- **condition**: Optional function that determines if the edge should be traversed
93-
94-
### 3. GraphBuilder
95-
96-
The `GraphBuilder` provides a simple interface for constructing graphs:
97-
98-
- **add_node()**: Add an agent or multi-agent system as a node
99-
- **add_edge()**: Create a dependency between nodes
100-
- **set_entry_point()**: Define starting nodes for execution
101-
- **build()**: Validate and create the Graph instance
102-
103103
## Conditional Edges
104104

105105
You can add conditional logic to edges to create dynamic workflows:
@@ -121,7 +121,7 @@ builder.add_edge("research", "analysis", condition=only_if_research_successful)
121121

122122
## Nested Multi-Agent Patterns
123123

124-
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:
125125

126126
```python
127127
from strands import Agent
@@ -154,7 +154,7 @@ print(f"\n{result}")
154154

155155
## Multi-Modal Input Support
156156

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):
158158

159159
```python
160160
from strands import Agent
@@ -186,21 +186,21 @@ result = graph(content_blocks)
186186

187187
## Asynchronous Execution
188188

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:
190190

191191
```python
192192
import asyncio
193193

194194
async def run_graph():
195-
result = await graph.execute_async("Research and analyze market trends...")
195+
result = await graph.invoke_async("Research and analyze market trends...")
196196
return result
197197

198198
result = asyncio.run(run_graph())
199199
```
200200

201201
## Graph Results
202202

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:
204204

205205
```python
206206
result = graph("Research and analyze...")
@@ -256,9 +256,9 @@ Agents can dynamically create and orchestrate graphs by using the `graph` tool a
256256

257257
```python
258258
from strands import Agent
259-
from strands_tools import graph
259+
from strands_tools import agent_graph
260260

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.")
262262

263263
agent("Design a TypeScript REST API and then write the code for it")
264264
```

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

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ swarm = Swarm(
5050
max_iterations=20,
5151
execution_timeout=900.0, # 15 minutes
5252
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
5454
repetitive_handoff_min_unique_agents=3
5555
)
5656

@@ -73,7 +73,7 @@ In this example:
7373

7474
## Swarm Configuration
7575

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:
7777

7878
| Parameter | Description | Default |
7979
|-----------|-------------|---------|
@@ -86,7 +86,7 @@ The `Swarm` constructor allows you to control the behavior and safety parameters
8686

8787
## Multi-Modal Input Support
8888

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):
9090

9191
```python
9292
from strands import Agent
@@ -166,21 +166,21 @@ You have access to swarm coordination tools if you need help from other agents o
166166

167167
## Asynchronous Execution
168168

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:
170170

171171
```python
172172
import asyncio
173173

174174
async def run_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...")
176176
return result
177177

178178
result = asyncio.run(run_swarm())
179179
```
180180

181181
## Swarm Results
182182

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:
184184

185185
```python
186186
result = swarm("Design a system architecture for...")
@@ -205,6 +205,26 @@ print(f"Execution time: {result.execution_time}ms")
205205
print(f"Token usage: {result.accumulated_usage}")
206206
```
207207

208+
## Swarm as a Tool
209+
210+
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+
208228
## Safety Mechanisms
209229

210230
Swarms include several safety mechanisms to prevent infinite loops and ensure reliable execution:

0 commit comments

Comments
 (0)