langgraph4j/langgraph4j

🚀 LangGraph for Java. A library for develop AI Agentic Architectures in the Java ecosystem. Designed to work seamlessly with both Langchain4j and Spring AI.

What it solves

LangGraph4j provides a way to build complex, stateful, multi-agent AI applications in Java. It solves the limitation of traditional linear workflows by allowing developers to create cyclical graphs where agents, tools, and custom logic can loop back, retry tasks, or collaborate while maintaining a shared memory (state) across the entire process.

How it works

The library uses a graph-based architecture where the application logic is split into:

  • StateGraph: The primary structure where nodes and edges are defined.
  • AgentState: A shared map-like object that travels between nodes. It uses "reducers" to determine how new data (like chat messages) is merged into the existing state.
  • Nodes: Individual units of work (functions or classes) that receive the current state, perform an action (like calling an LLM), and return updates to the state.
  • Edges: The connectors that define the flow. "Normal edges" are unconditional transitions, while "Conditional edges" use logic to dynamically decide which node to visit next based on the current state.
  • Compilation: The graph is validated and compiled into an immutable CompiledGraph for execution.

Who it’s for

Java developers building AI agents or multi-agent systems who want a structured way to manage state and control flow, especially those already using frameworks like LangChain4j or Spring AI.

Highlights

  • Cyclical Workflows: Supports loops, which are essential for agentic behaviors like self-correction or iterative refinement.
  • Ckeckpointing: Ability to save and restore the state of a graph at any point for debugging or resuming long-running processes.
  • Persistence: Built-in savers for MySQL, PostgreSQL, Redis, OracleDB, DynamoDB, CockroachDB, and Hazelcast.
  • Visual Debugging: Includes "LangGraph4j Studio," a web UI for visually inspecting and running graphs.
  • Framework Integration: Native support for LangChain4j and Spring AI.