Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › AI workflows

How to Build Graph Workflows with Spring AI Alibaba: State, Routing, and Human Review

By Freedom251 Team · · 12 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

To build a graph-based workflow with Spring AI Alibaba, model the application as a directed graph: nodes perform work, edges choose the next step, and OverAllState carries shared data between steps. You register nodes in a StateGraph, connect START and END, compile the graph into a CompiledGraph, then run it with an initial state and runtime configuration. Conditional edges add branching and loops; checkpoint and interruption settings let a workflow pause for human review and resume later. This approach is intended for stateful, multi-step applications and multi-agent systems, not a single one-turn model call.

What is Spring AI Alibaba Graph, and when should you use it?

Spring AI Alibaba Graph is a Java workflow and multi-agent runtime for applications composed of multiple AI models, tools, or ordinary business operations. Instead of placing every decision in one large prompt or service method, you represent each meaningful operation as a node and make transitions explicit as edges.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A graph becomes useful when execution can branch, repeat, pause, stream progress, or continue after an interruption. Typical examples include an agent that classifies a request, calls a tool, validates the result, asks for approval, and either revises the work or finishes. A simple request-response endpoint may not need this machinery; a long-running, stateful process usually does.

The framework is positioned beneath the Spring AI Alibaba Agent Framework. Its runtime capabilities include persistence, workflow orchestration, streaming, conditional routing, nested graphs, parallel execution, and state management for long-running agents.

#1 Best Overall
GMKtec AI Mini PC Ryzen Al Max+ 395 (up to 5.1GHz) Mini Gaming Computers | 128GB LPDDR5X 8000MHz (16GB*8) 2TB PCIe 4.0 SSD, Triple Screen 8K Display, WiFi 7 & USB4, SD Card Reader 4.0 EVO-X2
  • EVOLUTION AMD RYZEN AI MAX+ 395 MINI PC - GMKtec EVO-X2 is the next evolution in AI mini PC Ryzen Strix Halo series. Thanks to AMD Simultaneous Multithreading (SMT) the core-count is effectively doubled, to 32 threads. Ryzen AI Max+ 395 has 64 MB of L3 cache and can boost up to 5.1 GHz, depending on the workload. The Ryzen AI Max+ 395 is currently rated as the "most powerful x86 APU" on the market for AI computing.
  • AI NPU with XDNA 2 ARCHITECTURE - Powered by 16 “Zen 5” CPU cores, 50+ peak AI TOPS XDNA 2 NPU and a truly massive integrated GPU driven by 40 AMD RDNA 3.5 CUs, the Ryzen AI MAX+ 395 is a transformative upgrade and delivers a significant performance boost over the competition. The Ryzen AI Max+ 395 excels in consumer AI workloads like the llama.cpp-powered application: LM Studio. Shaping up to be the must-have app for client LLM workloads, LM Studio allows users to locally run the latest language model without any technical knowledge required and unleash their creativity and productivity.
  • AMD RADEON 8090S iGPU GAMING PC - The AMD Radeon RX 8060S offers all 40 CUs with up to 2.9 GHz graphics clock and uses the new RDNA 3.5 architecture. The powerful iGPU is positioned between an RTX 4060 and 4070 laptop GPU and therefore enables gaming in FHD at maximum details in most demanding games. The 8060S can also utilize the full 128GB pool, which is perfect for running LLMs such as Deepseek 70B Q8, which runs comfortably on this machine.
  • EIGHT CHANNEL LPDDR5X - LPDDR5X is a new ground breaking memory small form factor installed on-board. With blazing speeds up to to 8000MT/s, it runs 1.5x faster than the DDR5 SODIMMs; 90% better performance over DDR5 SODIMMs in video conferencing and photo editing; 30% better performance in productivity apps; 12% better performance in digital content workloads.
  • QUAD SCREEN 8K DISPLAY SUPPORT - EVO-X2 AI Mini PC support 4-screen 4K/8K output via HDMI 2.1 (8K@60Hz), DisplayPort 1.4 (4K@60Hz), and dual USB 4 40Gbps Transfer speed (supporting PD3.0/DP1.4/DATA). Ideal for gaming, video editing, and multitasking, it provides expansive and crisp multi-display support.

How do StateGraph, nodes, edges, OverAllState, and CompiledGraph fit together?

The simplest mental model is: nodes do the work; edges decide what happens next. The objects have separate responsibilities so that work, state, and routing remain inspectable.

Abstraction Purpose What you define
StateGraph Builder for the workflow topology. Node registrations, fixed edges, conditional edges, and entry and terminal connections.
Node A unit of work executed by the runtime. Synchronous or asynchronous logic that reads state and returns updates. It may call an LLM through Spring AI or run regular Java code.
Edge A transition between nodes. A fixed destination or routing logic that selects a destination from current state.
OverAllState The shared, serializable workflow snapshot. Keys, value types, and update or merge strategies for data exchanged by nodes.
CompiledGraph The executable, validated graph. Compilation options such as checkpointing and interruption settings, followed by invocation or streaming.

Because the state is serializable, intermediate results can be checkpointed and later inspected or resumed. A node does not need to know which node ran before it; it consumes the state contract and returns the updates it owns. Routing code likewise belongs in edges rather than being hidden inside unrelated node implementations.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What is the build sequence for a graph workflow?

Build the workflow in a fixed order so structural errors are caught before a production run.

  1. Define the state schema. List every value that crosses a node boundary, its type, and its update strategy. Decide which keys are replaced, appended to, or merged by another policy.
  2. Implement nodes. Give each operation a clear input and output contract. A node can be synchronous or asynchronous and can call a Spring AI model, a tool, a database, or ordinary Java business logic.
  3. Create a StateGraph. Register every node under a unique name. Names are used by edges and should describe the operation rather than an implementation detail.
  4. Connect the topology. Add an edge from START to the entry node and connect the terminal path to END. Add ordinary edges for transitions that never vary.
  5. Add conditional routing. Use addConditionalEdges when classification, validation, tool output, or another state value determines the next node. The routing function returns a label, and a label-to-node map resolves that label to a destination.
  6. Compile. Turn the builder into a CompiledGraph. Compilation is the point to supply checkpoint and interruption settings and to catch graph-structure errors early.
  7. Execute. Pass initial state and runtime configuration to invoke for a completed run or to a streaming API for incremental output and events.

How should I design OverAllState and update strategies?

Start with the state contract before writing node code. Every key should have one owner or a documented merge rule, because ambiguous updates are a common source of non-deterministic workflows.

Choose keys that represent workflow facts

Useful keys include the user request, classification, tool results, validation errors, approval status, accumulated messages, and a loop or attempt counter. Keep transient implementation details inside a node unless another step genuinely needs them.

Select the merge behavior deliberately

A replacement strategy is appropriate for a current classification or latest validation result. An append strategy fits a message history or audit list. A custom merge policy may be needed when parallel branches contribute separate fields or when updates must be reconciled. The strategy determines what later nodes see after an update, so document it with the state schema.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep state serializable

OverAllState is a serializable snapshot used for checkpointing and resumption. Store values that can be reconstructed or transported by the configured persistence mechanism; do not make a node depend on an in-memory object that cannot be represented in the state snapshot.

How do I implement nodes that call models and business services?

Make each node one meaningful operation with a narrow contract. A model node can read a prompt and context from state, call a Spring AI client, and return generated content. A business node can validate an order, query a service, or transform data without involving a model.

Separate side effects from decisions where possible. For example, one node can call a tool and write its result to state, while a later conditional edge decides whether the result is acceptable. This keeps the graph readable and makes the routing rule testable without rerunning the side effect.

Rank #2
AMD Ryzen™ AI Halo - Personal AI Desktop Computer - Developer Platform - Linux OS
  • Built for Local AI Development: AMD Ryzen AI Halo is designed for local AI development and inference, featuring 128GB unified memory and support for up to 200B parameter models to build and run intensive AI workloads locally.
  • 128GB Unified Memory: Features 128GB LPDDR5x unified memory at 8000 MT/s with 256 GB/s memory bandwidth, providing a shared memory pool across the CPU, GPU, and NPU to support larger AI models.
  • AMD Ryzen AI Max+ 395 Processor: Features 16 cores, 32 threads, and Zen 5 architecture, paired with AMD Radeon 8060S integrated graphics featuring 40 RDNA 3.5 compute units and an AMD XDNA 2 NPU with up to 50 TOPS.
  • Linux AI Developer Platform: Purpose-built for Linux-based AI development with full AMD ROCm software support and preloaded tools, models, and workflows optimized for local AI development.
  • Compact, Connected Design: Includes a 2TB M.2 SSD, 10GbE LAN, Wi-Fi 7, Bluetooth 5.4, USB-C connectivity, and HDMI 2.1b.

For asynchronous nodes, define how completion and failure are represented in state or runtime errors. Downstream routing should have an explicit path for missing, invalid, or failed results rather than assuming every call succeeds.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do fixed edges, conditional edges, and loops work?

Use a fixed edge when the next node is always known. Use a conditional edge when the current state determines the route. The routing function returns a label, and the label map translates that label into a node name.

Conditional branching

A classifier can write classification to state. A routing function then maps values such as an approval-required category, a tool-needed category, or a completed category to the corresponding node. Keep the map explicit so a reader can see every supported path and so an unexpected label fails visibly instead of silently skipping work.

Bounded loops

A loop is simply a conditional edge that points back to an earlier node. For example, a validation route can send an escalate label back to a revision node, while a stop label goes to END. Add a clear termination condition, such as a successful validation result or an attempt limit stored in state, so malformed model output cannot create an endless run.

Failure and fallback paths

Represent recoverable failures as deliberate routes when the workflow can retry, request clarification, or escalate. Reserve an unrecoverable error for conditions that should stop execution and be surfaced to the caller. This distinction is especially important when a graph is streamed or resumed later, because the operator needs to know whether the run is waiting, retrying, or finished.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do I compile a graph and catch structural mistakes?

Compile as soon as the basic topology exists, before adding a large number of nodes. Compilation validates the graph structure and produces the executable CompiledGraph.

At compile time, provide checkpoint settings when a run may pause, fail, or require approval. Configure interruption points for nodes that need human control. A named interruption such as interruptBefore('human_review') causes execution to stop before that node rather than entering it automatically.

Compilation cannot prove that a model will return a useful label or that a tool will be available at runtime. Test those behavioral assumptions separately, but use early compilation to catch missing registrations, invalid transitions, and incomplete entry or terminal paths.

How do I run a compiled graph with invoke or streaming?

Use invoke when the caller wants the completed result of a run. Supply the initial OverAllState values and runtime configuration, including the thread identifier used for checkpoint lookup.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
GMKtec EVO-X2 AI Mini PC Ryzen Al Max+ 395 Superchip 128GB LPDDR5X 2TB SSD | Gaming PC AI Supercomputer, AMD RADEON 8090S iGPU, 4K/8K HDMI 2.1, DP1.4, Dual USB4 Ports, SD Card Reader 4.0, WIFI7, BT5.4
  • EVOLUTION RYZEN AI MAX+ 395 MINI PC - GMKtec EVO-X2 is the next evolution in AI mini PC Ryzen Strix Halo series. Thanks to AMD Simultaneous Multithreading (SMT) the core-count is effectively doubled, to 32 threads. Ryzen AI Max+ 395 has 64 MB of L3 cache and can boost up to 5.1 GHz, depending on the workload. The Ryzen AI Max+ 395 is currently rated as the "most powerful x86 APU" on the market for AI computing.
  • AI NPU with XDNA 2 ARCHITECTURE - Powered by 16 “Zen 5” CPU cores, 50+ peak AI TOPS XDNA 2 NPU and a truly massive integrated GPU driven by 40 AMD RDNA 3.5 CUs, the Ryzen AI MAX+ 395 is a transformative upgrade and delivers a significant performance boost over the competition. The Ryzen AI Max+ 395 excels in consumer AI workloads like the llama.cpp-powered application: LM Studio. Shaping up to be the must-have app for client LLM workloads, LM Studio allows users to locally run the latest language model without any technical knowledge required and unleash their creativity and productivity.
  • AMD RADEON 8090S iGPU GAMING PC - The AMD Radeon RX 8060S offers all 40 CUs with up to 2.9 GHz graphics clock and uses the new RDNA 3.5 architecture. The powerful iGPU is positioned between an RTX 4060 and 4070 laptop GPU and therefore enables gaming in FHD at maximum details in most demanding games. The 8060S can also utilize the full 128GB pool, which is perfect for running LLMs such as Deepseek 70B Q8, which runs comfortably on this machine.
  • EIGHT CHANNEL LPDDR5X - LPDDR5X is a new ground breaking memory small form factor installed on-board. With blazing speeds up to to 8000MT/s, it runs 1.5x faster than the DDR5 SODIMMs; 90% better performance over DDR5 SODIMMs in video conferencing and photo editing; 30% better performance in productivity apps; 12% better performance in digital content workloads.
  • QUAD SCREEN 8K DISPLAY SUPPORT - EVO-X2 AI Mini PC support 4-screen 4K/8K output via HDMI 2.1 (8K@60Hz), DisplayPort 1.4 (4K@60Hz), and dual USB 4 40Gbps Transfer speed (supporting PD3.0/DP1.4/DATA). Ideal for gaming, video editing, and multitasking, it provides expansive and crisp multi-display support.

Use a streaming API when the caller needs progress before the entire workflow finishes. Spring AI Alibaba Graph supports streaming at the graph runtime level, and a node can wrap Spring AI ChatClient streaming content. These are different signals:

  • Model-token streaming delivers partial generated text from a model call, useful for responsive user interfaces.
  • Node or graph event streaming reports workflow progress such as a node starting, completing, or producing a state update, useful for orchestration views and operations.

Design the consumer around the signal it needs. A chat interface may display tokens, while an administrator console may need node-level events even when a node produces no user-facing text.

How do I pause a graph for human review and resume it?

Configure a checkpoint saver and an interruption before the review node. The run can then stop with its current state available for inspection, approval, or editing.

  1. Configure MemorySaver in the graph’s compile settings for the review workflow.
  2. Set an interruption before the node that represents human review, for example human_review.
  3. Start the graph with a stable thread identifier and stream or invoke until the interruption is reached.
  4. Read the saved current state for that thread.
  5. Apply the reviewer’s approval or edits with updateState.
  6. Resume the compiled graph using the same thread identifier so execution continues from the checkpoint rather than starting over.

The lower-level InterruptableAction interface provides hooks before and after node execution. Use those hooks when approval must surround a particular action or when a policy check belongs immediately before or after node execution.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What does persistence mean for long-running workflows?

Persistence turns a transient method call into a resumable workflow. The state snapshot records intermediate results and the current position, allowing an operator or a later request to inspect and continue a thread.

A thread identifier is therefore part of the runtime contract, not just a logging value. Reuse it when resuming the same logical run; generate a different identifier for an independent run. Keep identifier creation and ownership outside individual nodes so retries do not accidentally fork the workflow.

MemorySaver is useful for a quick start and for demonstrating the checkpoint API. For a production deployment, select and configure a saver appropriate to the required durability, retention, access control, and operational recovery model; the graph’s state and thread semantics remain the same.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When should I use nested graphs or parallel branches?

Use a nested graph when a part of the workflow has its own internal topology and should be treated as one reusable operation by the parent graph. This keeps a large system from becoming one flat collection of nodes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use parallel execution when branches are independent and can progress without one another’s intermediate results. Before merging them, define how each branch writes state and how conflicting keys are resolved. Parallelism increases throughput only when the work is genuinely independent; a branch that needs another branch’s output belongs after a synchronization point instead.

How should I structure a graph project for testing and operations?

Keep topology, node logic, state definitions, and runtime configuration separable. This lets you test each concern without invoking a full model run.

  • State tests: verify replacement, append, and custom merge behavior for every key.
  • Node tests: supply representative state and assert the returned updates, including invalid and failed inputs.
  • Routing tests: feed each supported state condition to the routing function and confirm the expected label and destination.
  • Termination tests: prove that success, escalation, retry exhaustion, and error paths all reach a defined outcome.
  • Resume tests: interrupt before human review, inspect the checkpoint, apply an update, and verify that the same thread continues at the intended point.
  • Streaming tests: distinguish token payloads from node events so a client does not treat orchestration metadata as model text.

Give nodes observable names and keep routing decisions in edges. When a run behaves unexpectedly, inspect the state after each node, identify the edge label selected, and check the thread’s checkpoint before changing prompts or business logic.

What are the main trade-offs of a graph-based workflow?

A graph adds design overhead compared with a linear service method, but it makes state transitions and long-running behavior explicit. The following capabilities are the practical decision points.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Capability Why it matters Design question
Durable state and resume Interrupted work can continue without replaying every prior step. Which saver and retention policy fit the deployment?
Routing expressiveness Fixed, conditional, and looping paths model real business rules. Are all labels mapped and are loops bounded?
Human interruption Approval or editing can occur between automated steps. Where should execution pause, and what state may the reviewer change?
Streaming Users and operators receive output or progress before completion. Does the client need model tokens, node events, or both?
Nested and parallel graphs Large workflows can be composed and independent work can run concurrently. Which subflows have stable boundaries and non-conflicting state?
Spring integration Nodes can use Spring AI clients alongside ordinary Java services. Which concerns belong in the graph and which remain in application services?
Observability Explicit nodes and state snapshots make progress and failures easier to inspect. Are node names, thread identifiers, and state changes recorded safely?

What mistakes most often break a Spring AI Alibaba graph?

  • Unclear state ownership: two nodes overwrite the same key with incompatible meanings. Assign ownership and a merge policy before implementation.
  • Routing hidden inside nodes: a node both performs work and secretly chooses the next operation. Move the choice to a conditional edge so the topology remains visible.
  • No terminal path: a branch can return a label that never reaches END. Map every supported label and test unexpected values.
  • Unbounded retries: a loop sends every validation failure back to the same node. Store an attempt count or another explicit stop condition.
  • Missing thread continuity: a resume request uses a new identifier and starts a fresh run. Persist and reuse the identifier for the logical workflow.
  • Confusing streams: a UI expects tokens but receives node events, or an operations view ignores events because it only reads text. Define the event contract for each consumer.
  • Compiling too late: structural errors are discovered only after all business logic is written. Compile a minimal graph first, then grow it incrementally.

How do I decide whether Graph is the right abstraction?

Choose Spring AI Alibaba Graph when the application needs more than one model call: shared state across steps, conditional routing, bounded loops, checkpointed execution, human review, streaming progress, nested subflows, or parallel branches. Keep a simpler service method for a genuinely linear operation with no need to resume or inspect intermediate state. The decisive question is whether the workflow’s state and transitions deserve to be explicit, testable runtime objects.

Frequently Asked Questions

Can a graph node perform non-AI work, such as a database update?

Yes. Nodes can run ordinary Java business logic as well as Spring AI calls. Treat external writes as deliberate side effects, make retries safe where possible, and return the result or status needed by downstream routing.

How can I stop a conditional loop from running forever?

Put a bounded condition in the shared state, such as an attempt counter or deadline, and route the exhausted case to an explicit stop or escalation path. Test the counter and the successful exit independently from the model or tool implementation.

Should I use one thread identifier for every user session?

Use an identifier for one logical workflow instance, not automatically for an entire account or session. A new request that must not inherit prior checkpoints should receive a new identifier, while an approval or retry of the same run must retain the original.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When is parallel execution a poor choice?

Avoid parallel branches when one operation depends on another branch’s intermediate result or when several branches update the same state key without a defined merge policy. In those cases, a sequential edge or an explicit synchronization step is easier to reason about.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

AI workflowsHuman-in-the-LoopJavamulti-agent systemsSpring AI AlibabaStateGraph

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.