Skip to content

Lesson 11: Multi-Agent Patterns: Graph Workflows

Play

Watch on YouTube

Code for this lesson: samples/11-graphs

Graphs and workflows give you deterministic control over multi-agent execution. Unlike agents-as-tools, where the orchestrator decides the flow dynamically, these patterns let you define the exact execution order, dependencies, and parallel paths upfront. Use them when you can draw the workflow on a whiteboard.

Each node is a full agent; edges express dependencies. A node executes when all its incoming edges are satisfied, and the graph resolves what runs in parallel and what waits.

from strands import Agent
from strands.multiagent import GraphBuilder
from strands.vended_tools.web_fetch import web_fetch
researcher = Agent(
name="researcher",
system_prompt="Gather comprehensive information from the web.",
tools=[web_fetch],
)
analyst = Agent(
name="analyst",
system_prompt="Identify patterns, trends, and key insights from research.",
)
summarizer = Agent(
name="summarizer",
system_prompt="Condense raw research into concise key points.",
)
report_writer = Agent(
name="report_writer",
system_prompt="Synthesize analysis and summaries into a final report.",
)
builder = GraphBuilder()
builder.add_node(researcher, "research")
builder.add_node(analyst, "analysis")
builder.add_node(summarizer, "summarize")
builder.add_node(report_writer, "report")
builder.add_edge("research", "analysis")
builder.add_edge("research", "summarize") # analyst + summarizer run in parallel
builder.add_edge("analysis", "report")
builder.add_edge("summarize", "report") # report waits for both
builder.set_execution_timeout(600)
graph = builder.build()
result = graph("Research the impact of AI on healthcare")

📂 basic_graph.py

Data flow: entry nodes receive the original task. Downstream nodes receive the original task plus labeled outputs from their dependencies. Use invocation_state for metadata (user IDs, feature flags) that shouldn’t be exposed to the models.

Common shapes: sequential pipelines, parallel fan-out (as above), conditional branching, and cyclic feedback loops. If you build a cycle, set set_max_node_executions so it can’t loop forever.

  • Nodes are agents (or any callable). They execute when all incoming edges are satisfied.
  • Edges define dependencies. An edge from A to B means B waits for A.
  • Parallel fan-out: nodes without dependencies on each other run concurrently.
  • Context passing: each step receives the output of its predecessors.
  • When to use: pipelines with known structure, fan-out/fan-in, workflows that need guaranteed execution order, and processes requiring audit trails.
PatternFlow ControlBest For
Agents as ToolsOrchestrator decidesSeparable domains, synthesis
GraphsDefined by edgesKnown pipelines, parallelism
SwarmsAgents decideUnknown sequences, exploration