Skip to content

Commit 2b607b5

Browse files
authored
fix: enable parallel execution in graph workflow (#485)
1 parent 6638fb0 commit 2b607b5

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/strands/multiagent/graph.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,18 @@ async def _execute_graph(self) -> None:
338338
current_batch = ready_nodes.copy()
339339
ready_nodes.clear()
340340

341-
# Execute current batch of ready nodes
342-
for node in current_batch:
343-
if node not in self.state.completed_nodes:
344-
await self._execute_node(node)
345-
346-
# Find newly ready nodes after this execution
347-
ready_nodes.extend(self._find_newly_ready_nodes())
341+
# Execute current batch of ready nodes concurrently
342+
tasks = [
343+
asyncio.create_task(self._execute_node(node))
344+
for node in current_batch
345+
if node not in self.state.completed_nodes
346+
]
347+
348+
for task in tasks:
349+
await task
350+
351+
# Find newly ready nodes after batch execution
352+
ready_nodes.extend(self._find_newly_ready_nodes())
348353

349354
def _find_newly_ready_nodes(self) -> list["GraphNode"]:
350355
"""Find nodes that became ready after the last execution."""

tests_integ/test_multiagent_graph.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ def proceed_to_second_summary(state):
131131

132132
# Verify execution order - extract node_ids from GraphNode objects
133133
execution_order_ids = [node.node_id for node in result.execution_order]
134-
assert execution_order_ids == ["computation_subgraph", "secondary_math", "validator", "primary_summary"]
134+
# With parallel execution, secondary_math and validator can complete in any order
135+
assert execution_order_ids[0] == "computation_subgraph" # First
136+
assert execution_order_ids[3] == "primary_summary" # Last
137+
assert set(execution_order_ids[1:3]) == {"secondary_math", "validator"} # Middle two in any order
135138

136139
# Verify specific nodes completed
137140
assert "computation_subgraph" in result.results

0 commit comments

Comments
 (0)