spring-ai-alibaba-graph-core/README.md
Spring AI Alibaba Graph is a workflow and multi-agent framework for Java developers to build complex applications composed of multiple AI models or steps.
Spring AI Alibaba Graph serves as the underlying core engine of the Agent Framework. It provides atomic components for building intelligent agents with interruptible and orchestratable capabilities, offering high flexibility but also relatively high learning costs. In contrast, the Agent Framework is built atop Graph, abstracting away the underlying complexities through concepts like ReactAgent and SequentialAgent.
Please check the documentation on official website for mote details
Graph is deeply integrated with the Spring Boot ecosystem, providing a declarative API to orchestrate workflows. This allows developers to abstract each step of an AI application as a node (Node) and connect these nodes in the form of a directed graph (Graph) to create a customizable execution flow. Compared to traditional single-agent (one-turn Q&A) solutions, Spring AI Alibaba Graph supports more complex multi-step task flows, helping to address the issue of a single large model being insufficient for complex tasks.
The core of the framework includes: StateGraph (the state graph for defining nodes and edges), Node (node, encapsulating a specific operation or model call), Edge (edge, representing transitions between nodes), and OverAllState (global state, carrying shared data throughout the flow). These designs make it convenient to manage state and control flow in the workflow.
interrupt() (before execution) and interruptAfter() (after execution).
Useful for human-in-the-loop scenarios, approval workflows, and multi-turn conversations.Spring AI Alibaba Graph supports interrupting workflow execution at specific points, enabling human-in-the-loop scenarios.
public interface InterruptableAction {
// Called BEFORE node execution - can prevent execution
Optional<InterruptionMetadata> interrupt(String nodeId, OverAllState state, RunnableConfig config);
// Called AFTER node execution - can inspect results and interrupt
default Optional<InterruptionMetadata> interruptAfter(String nodeId, OverAllState state,
Map<String, Object> actionResult, RunnableConfig config) {
return Optional.empty();
}
}
public class ReviewAction implements AsyncNodeActionWithConfig, InterruptableAction {
@Override
public CompletableFuture<Map<String, Object>> apply(OverAllState state, RunnableConfig config) {
return CompletableFuture.completedFuture(Map.of("result", "generated_content"));
}
@Override
public Optional<InterruptionMetadata> interrupt(String nodeId, OverAllState state, RunnableConfig config) {
return Optional.empty(); // Don't interrupt before execution
}
@Override
public Optional<InterruptionMetadata> interruptAfter(String nodeId, OverAllState state,
Map<String, Object> actionResult, RunnableConfig config) {
// Interrupt after execution for human review
return Optional.of(InterruptionMetadata.builder(nodeId, state)
.addMetadata("reason", "needs_review")
.addMetadata("content", actionResult.get("result"))
.build());
}
}