Section650

Writing

TopicAI
Reading8 min

Graph Engineering: When an AI Workflow Needs Branches

Graph-based agent orchestration makes the path through an AI workflow explicit: routing, dependencies, shared state, parallel steps and approvals. When a direct workflow is enough, and what a graph adds in complexity, through a coding agent fixing a sorting bug.

By Ka Lun Chan · Cloud & AI · AI / Architecture

What does graph engineering mean here?

In this article, graph engineering means graph-based agent orchestration: designing an AI workflow as explicit steps, the transitions between them, the state they share, and the points where the path branches, runs steps in parallel or waits for a person. A graph earns its place when the next step depends on what just happened. When the steps always run in the same order, a direct workflow is simpler and easier to operate.

Part of a series on what it takes to make an AI system reliable. A loop decides whether to try a step again. A graph decides which step runs next.

This article uses “graph engineering” to mean structuring a workflow. Graph databases and knowledge graphs can supply information to an agent through retrieval. A workflow graph decides what runs next.

The steps in that graph don’t have to be agents. Running a test suite, waiting for an approval and opening a pull request are ordinary operations, and most useful workflow graphs are mostly ordinary operations with a model in a few of the steps.

The direct workflow

The illustrative scenario this series follows: a ticket says the Quantity column on the Orders page sorts as 1, 10, 2, and a coding agent is asked to fix it. For that one bug, a straight line works:

Direct workflow
reproduce → diagnose → fix → verify → approve → open draft PR

Each step runs once, in order, and the loop around “fix” and “verify” handles retries. Anthropic’s guidance distinguishes workflows, where models and tools follow predefined code paths, from agents, where the model directs its own process, and recommends the simplest solution that works. For a single, well-understood bug, this line is that solution. You can read it, test it and explain it to the person approving the result.

Where the path starts to depend on results

Now run the same workflow on every sorting ticket that arrives, not just this one. The straight line breaks in predictable places.

  • Some tickets won’t reproduce. The agent shouldn’t move on to “fix.” The work should wait for the reporter to supply steps or data.
  • Some causes sit in a different place. If diagnosis finds the API really does return quantities as strings, the fix belongs to another team’s code, with a different reviewer and a different scope.
  • The checks are independent. Unit tests, a type check and a browser check of the rendered table can run at the same time, and the next step should wait for all three.
  • Approval is a pause, not a step that finishes instantly. The workflow might sit for hours waiting for a person and must resume where it stopped.

You can push those decisions into the agent’s prompt and let it choose. Then the model is deciding, on every run, whether it reproduced the bug, whether the cause is in scope and whether it may skip the wait. Making them explicit edges takes those decisions away from the model and puts them in code you can test.

Fig. 742-1 The sorting fix as a graph
StepRun byOn successOtherwise
ReproduceAgentDiagnoseAsk reporter
Ask reporterPerson (wait)ReproduceClose as cannot reproduce
DiagnoseAgentFix (client)Escalate (cause is in the API)
Fix (client)AgentChecksHand back after the attempt limit
ChecksCode, three in parallelApproveFix (client), with the failures
ApprovePerson (wait)Open draft PRFix (client), with the reviewer’s note
Open draft PRCodeEndRetry once, then alert the owner
Three of the seven steps involve no model at all. The graph coordinates ordinary code and people as much as it coordinates agents.

Routing, dependencies, shared state, parallel steps and approvals

LangGraph’s documentation provides names for five common workflow concepts. Other orchestrators and plain code offer similar building blocks.

Routing. A conditional edge picks the next step from the current state. After “Reproduce,” the edge reads whether reproduction succeeded and routes to “Diagnose” or “Ask reporter.” LangGraph calls these conditional edges, and they can route to one or more nodes or end the run.

Dependencies. A step that needs results from several others waits for all of them. “Approve” runs only after all three checks finish, because a person shouldn’t approve a change whose browser check hasn’t come back.

Shared state. Every step reads from and writes to one state object: the ticket, the reproduction result, the root cause, the diff, the check results, the approval. LangGraph models a graph as state, nodes and edges. Designing that state is most of the work. If “root cause” is a free-text field, the routing decision after diagnosis is a guess. If it is a structured field with “client” or “server,” the route is a lookup.

Parallel steps. The three checks fan out and run side by side. When parallel steps write to the same state, something has to define how their updates combine. LangGraph uses reducers for this, and runs fanned-out destinations together in what it calls a super-step. Without a merge rule, the last check to finish can silently overwrite the others’ results.

Approvals. The workflow pauses, saves its state and resumes when a person responds. LangGraph implements this with interrupts and checkpointers, which save state at each super-step and, according to its docs, also enable resuming after failures and replaying earlier states. Whatever tool you use, the pause has to survive a restart. An approval that lives only in memory is lost the first time the process is redeployed.

Written as a framework-neutral sketch, the graph is short:

Workflow graph (sketch)
state: ticket, reproduced, cause_location, diff, checks[], approval

reproduce   → reproduced ? diagnose : ask_reporter
ask_reporter (wait for person) → reproduce | close
diagnose    → cause_location == "client" ? fix : escalate
fix         → [unit_tests, type_check, browser_check]   # in parallel
checks done → all passed ? approve : fix               # loop limit applies
approve     (wait for person) → approved ? open_draft_pr : fix
open_draft_pr → end

What complexity does a graph add?

Every edge in that sketch is a path someone has to test, and every state field is a contract between steps. That is real ongoing work.

  • More paths to test. A straight line has one path. The graph above has a reproduce branch, an escalation branch, a check-failure loop and an approval rejection loop. Each needs at least one test case, or it will break the first time it runs for real.
  • A state schema to maintain. Adding a field, renaming one or changing its meaning affects every step that reads it, and saved runs that were paused under the old schema.
  • Merge rules for parallel writes. If two steps update the same field, define how their results combine or serialize the writes.
  • Harder debugging. “What happened?” becomes “which path did this run take, and why?” The harness logs need to record each transition and the state that caused it.
  • A framework to learn and depend on. Anthropic’s guidance warns that frameworks can add layers that obscure the prompts and responses underneath, which makes debugging harder. That is a reason to understand what your framework does, or to start in plain code.

A workflow graph is an architecture diagram that executes. Each branch has an operational cost, as discussed in The Architecture You Don’t Build.

When is a direct workflow enough?

A direct workflow is enough when the steps are known, always run in the same order, and a failure at any step can simply stop the run or send it back through a loop. Move to a graph when the next step genuinely depends on results, when independent steps should run in parallel, or when the workflow must pause for people and resume reliably.

Fig. 742-2 Pick the simplest shape that fits
ShapeUse it whenIn the sorting example
Direct workflowThe steps are known and always run in the same orderOne bug, one repository, a fixed reproduce, fix, verify, approve sequence
GraphThe next step depends on results, some steps can run in parallel, or people must approve along the wayTickets that may not reproduce, causes that may sit in another team’s code, checks that can run side by side
Agent choosing its own pathThe steps can’t be listed in advance and a wrong path is cheap to correctOpen-ended investigation inside one node, such as diagnosing the cause

In the sorting example, the model decides how to diagnose the problem inside a node. The graph constrains the possible next steps.

One more sign you may need a graph: if your agent prompt has grown a section of “if this, then do that, otherwise ask” rules, those rules are edges written in prose. Moving them into the workflow makes them testable, and shortens the prompt as a bonus.

Sources

The sources below explain the workflow primitives. The sorting example and graph are illustrative.

Short answers

Is graph engineering the same as using a knowledge graph or graph database?

No. In this article, graph engineering means graph-based orchestration: modelling a workflow as steps connected by transitions. Knowledge graphs and graph databases store data as entities and relationships. They can feed an agent information, which is a retrieval decision, but they don’t decide which step of the workflow runs next.

Do the steps in an AI workflow graph have to be agents?

No. A node can be a model call, an agent with tools, ordinary code such as running a test suite, or a wait for a person’s approval. In most useful graphs, many of the nodes are plain code.

Before you draw the graph

Write the workflow as a straight line first. Add a branch only where you can name the result that should change the next step, and a test that proves it does.

Next: evaluation engineering Series overview