langgraph4j/langgraph4j

🚀 LangGraph for Java is a library for Graph Engineering, designed to build sophisticated AI agentic architectures within the Java ecosystem. It works seamlessly with both Langchain4j and Spring AI.

What it solves

LangGraph4j provides a way to build stateful, multi-agent AI applications in Java. It solves the limitation of traditional directed acyclic graphs (DAGs) by supporting cyclical graphs, which are necessary for agentic workflows where an AI might need to loop back to a previous step, retry a task, or ask for clarification.

How it works

The library uses a graph-based approach to define AI workflows:

  • StateGraph: The primary structure where developers define nodes (actions) and edges (transitions).
  • AgentState: A shared state (essentially a map) that is passed between nodes. Reducers determine how new data is merged into this state (e.g., overwriting or appending to a list).
  • Nodes: Individual units of logic that receive the current state, perform a computation (like calling an LLM), and return updates to the state.
  • Edges: Control the flow. Normal edges are unconditional, while conditional edges use logic to dynamically decide the next node based on the current state.
  • Persistence: Through CheckpointSaver, the graph's state can be saved to various databases (MySQL, PostgreSQL, Redis, etc.), allowing for long-running processes and the ability to resume or debug workflows.

Who it’s for

It is designed for Java developers building complex LLM-powered applications who want a structured way to manage agent collaboration, memory, and control flow, specifically those already using frameworks like LangChain4j or Spring AI.

Highlights

  • Cyclical Graph Support: Enables loops and iterative agent reasoning.
  • State Management: Shared, reducer-based state for context awareness across nodes.
  • Persistence: Built-in support for multiple database backends to save and resume graph states.
  • Visual Debugging: Includes a Studio web UI for visual inspection and running of graphs.
  • Framework Integration: Seamlessly works with LangChain4j and Spring AI.
  • Async/Streaming: Supports non-blocking operations and streaming results from LLMs.

Related

  • Project
  • Project
  • Project
  • Project
  • Project