Graph-based Orchestration

An executable graph of agents, tools, and state.

Agent coordination, tools, and state transitions are modeled as an explicit, executable state graph consisting of nodes and edges. It composes the two workflow relaxations — conditional edges (Routing) and bounded cycles (Loop) — over a closed node set with a validated state schema.

Level
03 · Multi-Agent
Also known as
Agent Graph, State Graph Orchestration
Trade-off
Extreme predictability and controllability are gained against significant modeling overhead.
Native in
LangGraph, AWS Strands, Microsoft Agent Framework, Google ADK
The mental model

A shape you can draw on a napkin.

The developer wires the node set and the admissible edges; a router node lets an LLM choose which edge to take at runtime.

  1. Nodes and edges are registered up front — the set stays closed.
  2. At conditional edges an LLM picks the next path from the registered set.
  3. Cycles are allowed, but a recursion limit bounds every loop.

Compare all six coordination patterns →

RouterNode ANode BFan-in
Walk it through

A real run, step by step.

TaskA support ticket runs through a graph with five nodes: classify, billing, diagnose, draft, check. The ticket says: “Our API calls fail since this morning.”
Illustrative run.
StepNodeStateNext edge
1classifyCategory: technicalConditional: to diagnose
2diagnoseCause: an expired certificateFixed: to draft
3draftReply, version 1Fixed: to check
4checkFailed: the reply names no fix. Attempts: 1Conditional: back to draft
5draftReply, version 2, with the steps to renewFixed: to check
6checkPassedConditional: end
What this shows: every path this run could take was written down before it started. A model chooses among the edges at two nodes, and it cannot invent a node or a third draft. That is why each path can be tested on its own and a run can be replayed from its state. The price is that every new case means changing the graph.
In code

The pattern in code.

Plain Pythonpython
NODES = {"classify": classify, "billing": billing, "diagnose": diagnose,
         "draft": draft, "check": check}

def next_node(current, state):  # every admissible edge is written here
    if current == "classify":  # conditional edge
        return {"billing": "billing", "technical": "diagnose"}[state["category"]]
    if current in ("billing", "diagnose"):
        return "draft"
    if current == "draft":
        return "check"
    # bounded cycle: at most two drafts
    if state["passed"] or state["attempts"] >= 2:
        return None
    return "draft"

def run(ticket):
    state, node = {"ticket": ticket, "attempts": 0}, "classify"
    while node:
        # a node returns an update to the state
        state = {**state, **NODES[node](state)}
        node = next_node(node, state)
    return state
Fit

Use it, or not.

When to reach for it

  • Coordination must be completely traceable and testable.
  • Complex flows involving cycles and strict conditions must run stably in production.

When it backfires

  • A linear workflow is sufficient.
  • Graph maintenance outweighs the benefits.
  • Autonomous emergence is preferred over explicit control.
Pitfalls

Two ways this pattern will hurt you.

Hallucinated routing — the model picks an edge that does not exist

When the router is an LLM, it can return an edge label that was never registered. The graph then either crashes or silently falls through to a default that hides the failure.

Countermeasure

Validate the router's output against the registered edge set before transitioning. Reject and retry on mismatch; never inherit corrupted routing decisions.

Unbounded cycles — the graph never terminates

Cycles are legal in this pattern. Without an explicit guard, a router that keeps choosing the same back-edge will loop until the process is killed.

Countermeasure

Set a hard recursion / step budget at the runtime level and an exit predicate the graph checks every iteration. Treat the budget as a correctness boundary, not a performance hint.

Framework support

Where Graph-based Orchestration is native.

LangGraphNative
AWS StrandsAWS Strands GraphNative
Sources

Where this pattern comes from.

  1. GPTSwarm: Language Agents as Optimizable GraphsIn the source list

Search

Search patterns, frameworks, and pages.