langgraph4j/langgraph4j

โ–ฒ 2 stars todayโ˜… 2,086โ‘‚ 296

๐Ÿš€ 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.

About langgraph4j/langgraph4j

langgraph4j/langgraph4j is an open-source project on GitHub, mainly written in Java. ๐Ÿš€ LangGraph for Java is a library for Graph Engineering, designed to build sophisticated AI agentic architectures within the Java ecosystem. It currently holds 2,086 stars and 296 forks with 20 open issues, and was last pushed on 2026-11-03 (repository created 2024-03-18).

Project Overview

AI Homed tracks it on the Today's Trending board, currently at rank #64 with 2 new stars today.

GitHub Repository Details

Repository langgraph4j/langgraph4j ยท default branch main ยท size 91197 KB ยท watchers 29 ยท source: GitHub REST API and repository README

README

avatar๏ธ Welcome to LangGraph4j

Enabling Graph Engineering for Agentic AI Workflows in Java

License: MIT [docs][documentation] DeepWiki [Static Badge][snapshots] [Maven Central][releases]discord

LangGraph for Java. A library for building stateful, multi-agents applications with LLMs, built for work with [langchain4j] and [Spring AI]

It is inspired by [LangGraph] solution, part of [LangChain AI project].

Releases

โ€ผ๏ธ the repo has been updated to 1.9, the version 1.8 has been moved to the branch support/1.8.x.. Take a look to What's new in release 1.9

| Date | Release | info |--------------|----------------| --- | Nov 4, 2026 | 1.9.8 | last release

| Release line | Java baseline | Notes | |---|---|---| | 1.9.x | Java 17+ | Release with new (experimental) features and improvements for preparing move to 2.0 | | 1.9-SNAPSHOT development builds | Java 17+ | Snapshot users should expect active development and pre-release changes | | 1.8.x LTS release | Java 17+ | This release will be maintained for LTS support in branch support/1.8.x. Only bugfix and/or minor improvement |

Star History

https://github.com/langgraph4j/langgraph4j/blob/HEAD/Star History Chart

Getting Started

Welcome to LangGraph4j! This guide will help you understand the core concepts of LangGraph4j, install it, and build your first application.

Introduction

LangGraph4j is a Java library for building stateful, multi-agent applications with Large Language Models (LLMs). It is inspired by the Python library LangGraph and is designed to work seamlessly with popular Java LLM frameworks like Langchain4j and Spring AI.

At its core, LangGraph4j allows you to define cyclical graphs where different components (agents, tools, or custom logic) can interact in a stateful manner. This is crucial for building complex applications that require memory, context, and the ability for different "agents" to collaborate or hand off tasks.

Core Features & Benefits

LangGraph4j offers several features and benefits:

Pattern Matrix

| Pattern | Best for | Main abstraction | Start here | |---|---|---|---| | First graph / linear flow | Learning the core execution model | StateGraph, normal edges, shared state | ## Your First Graph - A Simple Example | | Conditional routing | Router-style decisions and dynamic control flow | Conditional edges | ### Edges | | Stateful checkpointed flow | Long-running or resumable workflows | CheckpointSaver, CompileConfig | ### Checkpoints (Persistence) | | Framework-integrated agents | Using LangGraph4j with Java AI frameworks | LangChain4j / Spring AI integrations | ## BONUS: built-in integrations | | Visual debugging and inspection | Observing and iterating on graphs interactively | Studio | ## Studio ๐Ÿคฉ - Running Your Graph visually |

Core Concepts Explained

Understanding these concepts is key to using LangGraph4j effectively:

StateGraph

The StateGraph is the primary class you'll use to define the structure of your application. It's where you add nodes and edges to create your graph. It is parameterized by an AgentState.

AgentState

The AgentState (or a class extending it) represents the shared state of your graph. It's essentially a map (Map) that gets passed from node to node. Each node can read from this state and return updates to it.

Nodes

Nodes are the building blocks of your graph that perform actions. A node is typically a function (or a class implementing NodeAction or AsyncNodeAction) that: 1. Receives the current AgentState as input. 2. Performs some computation (e.g., calls an LLM, executes a tool, runs custom business logic). 3. Returns a Map representing updates to the state. These updates are then applied to the AgentState according to the schema's reducers.

Nodes can be synchronous or asynchronous (CompletableFuture).

Edges

Edges define the flow of control between nodes.

Compilation

Once you've defined all your nodes and edges in a StateGraph, you compile() it into a CompiledGraph. This compiled graph is an immutable, runnable representation of your logic. Compilation validates the graph structure (e.g., checks for orphaned nodes).

Checkpoints (Persistence)

LangGraph4j allows you to save (Checkpoint) the state of your graph at any step. This is extremely useful for:

You'll typically use a CheckpointSaver implementation (e.g., MemorySaver for in-memory storage, or you can implement your own for persistent storage).

Useful starting points for persistence:

If you only want to see the minimal integration point first, look for CompileConfig.builder().checkpointSaver(...) in the saver module examples before diving into the full storage details.

Project Structure

langgraph4j/
โ”œโ”€โ”€ langgraph4j-bom/                     # LangGraph4j dependency management
โ”œโ”€โ”€ langgraph4j-core/                    # LangGraph4j core components
โ”œโ”€โ”€ langgraph4j-opentelemetry/           # LangGraph4j Hook & OpenTelemetry integration module
โ”œโ”€โ”€ langgraph4j-mysql-saver              # LangGraph4j persistent checkpoint saver based on MySQL
โ”œโ”€โ”€ langgraph4j-oracle-saver             # LangGraph4j persistent checkpoint saver based on OracleDB
โ”œโ”€โ”€ langgraph4j-postgres-saver           # LangGraph4j persistent checkpoint saver based on PostgresSQL
โ”œโ”€โ”€ langgraph4j-dynamodb-saver           # LangGraph4j persistent checkpoint saver based on Amazon DynamoDB
โ”œโ”€โ”€ langgraph4j-cockroachdb-saver        # LangGraph4j persistent checkpoint saver based on CockroachDB
โ”œโ”€โ”€ langgraph4j-mongodb-saver            # LangGraph4j persistent checkpoint saver based on MongoDB
โ”œโ”€โ”€ langgraph4j-redis-saver              # LangGraph4j persistent checkpoint saver based on Redis
โ”œโ”€โ”€ langgraph4j-hazelcast-saver          # LangGraph4j persistent checkpoint saver based on Hazelcast
โ”œโ”€โ”€ langgraph4j-sqlite-saver             # LangGraph4j persistent checkpoint saver based on SQLite
โ”œโ”€โ”€ langgraph4j-dsl                      # LangGraph4j domain-specific language (DSL) module
โ”œโ”€โ”€ ag-ui                                # AG UI protocol integration
โ”‚   โ”œโ”€โ”€ langgraph4j-ag-ui-json           # LangGraph4j AG UI JSON module
โ”‚   โ”œโ”€โ”€ langgraph4j-ag-ui-sdk            # LangGraph4j AG UI SDK module
โ”‚   โ””โ”€โ”€ langgraph4j-ag-ui-springboot     # LangGraph4j AG UI Spring Boot module
โ”œโ”€โ”€ langchain4j/                         # LangChain4j integration
โ”‚   โ”œโ”€โ”€ langchain4j-core/                # LangChain4j core components (integration required)
โ”‚   โ””โ”€โ”€ langchain4j-agent/               # LangChain4j agent executor
โ”œโ”€โ”€ spring-ai/                           # Spring AI integration
โ”‚   โ””โ”€โ”€ spring-ai-core/                  # Spring AI core components (integration required)
โ”‚   โ””โ”€โ”€ spring-ai-agent/                 # Spring AI agent executor
โ”œโ”€โ”€ studio/                              # LangGraph4j Studio (web UI)
โ”‚   โ””โ”€โ”€ base/                            # Base classes and interfaces
โ”‚   โ””โ”€โ”€ jetty/                           # Jetty server implementation
โ”‚   โ””โ”€โ”€ quarkus/                         # Quarkus server implementation
โ”‚   โ””โ”€โ”€ springboot/                      # Spring Boot implementation
โ”œโ”€โ”€ how-tos/                             # How-tos and examples
โ”œโ”€โ”€ javelit/                             # LangGraph4j & Javelit

Installation

To use LangGraph4j in your project, you need to add it as a dependency.

Maven:

Make sure you are using Java 17 or later.

Latest Stable Version (Recommended):


    1.9.8

org.bsc.langgraph4j langgraph4j-bom ${langgraph4j.version} pom import

org.bsc.langgraph4j langgraph4j-core

(Note: Always check the Maven Central Repository for the latest version number.)

Development Snapshot Version: If you want to use the latest unreleased features, you can use a snapshot version.


    org.bsc.langgraph4j
    langgraph4j-core
    1.9.8

You might need to configure your settings.xml or pom.xml to include the Sonatype OSS snapshots repository:

    
        sonatype-oss-snapshots
        https://central.sonatype.com/repository/maven-snapshots
        
            true

Your First Graph - A Simple Example

Let's create a very simple graph that has two nodes: greeter and responder. The greeter node will add a greeting message to the state. The responder node will add a response message based on the greeting.

Before you start, the shortest path is:

1. Make sure you are on Java 17+ and have added langgraph4j-core to your project. 2. Copy the example below exactly once to understand the basic StateGraph + shared-state flow. 3. Run the graph locally and confirm you can see the state evolve across the two nodes. 4. After that first success, jump to the built-in integrations or checkpointing sections depending on whether you want framework integration or persistence next.

1. Define the State: Our state will hold a list of messages.

// Define the state for our graph
class SimpleState extends AgentState {
    public static final String MESSAGES_KEY = "messages";

// Define the schema for the state. // MESSAGES_KEY will hold a list of strings, and new messages will be appended. public static final Map> SCHEMA = Map.of( MESSAGES_KEY, Channels.appender(ArrayList::new) );

public SimpleState(Map initData) { super(initData); }

public List messages() { return this.>value("messages") .orElse( List.of() ); } }

2. Define the Nodes:

// Node that adds a greeting
class GreeterNode implements NodeAction {
    @Override
    public Map apply(SimpleState state) {
        System.out.println("GreeterNode executing. Current messages: " + state.messages());
        return Map.of(SimpleState.MESSAGES_KEY, "Hello from GreeterNode!");
    }
}

// Node that adds a response class ResponderNode implements NodeAction { @Override public Map apply(SimpleState state) { System.out.println("ResponderNode executing. Current messages: " + state.messages()); List currentMessages = state.messages(); if (currentMessages.contains("Hello from GreeterNode!")) { return Map.of(SimpleState.MESSAGES_KEY, "Acknowledged greeting!"); } return Map.of(SimpleState.MESSAGES_KEY, "No greeting found."); } }

3. Define and Compile the Graph:

public class SimpleGraphApp {
    
    public static void main(String[] args) throws GraphStateException {
        // Initialize nodes
        GreeterNode greeterNode = new GreeterNode();
        ResponderNode responderNode = new ResponderNode();

// Define the graph structure var stateGraph = new StateGraph<>(SimpleState.SCHEMA, initData -> new SimpleState(initData)) .addNode("greeter", node_async(greeterNode)) .addNode("responder", node_async(responderNode)) // Define edges .addEdge(START, "greeter") // Start with the greeter node .addEdge("greeter", "responder") .addEdge("responder", END) // End after the responder node ; // Compile the graph var compiledGraph = stateGraph.compile();

// Run the graph

compiledGraph.stream(inputs, config) // start streaming outputs from the graph execution .forEachAsync( output -> // process each output as it is produced System.out.println("Step executed: " + output)) .thenApply( GraphResult::from ) // holds final result in GraphResult .thenAccept( result -> { // process the final result if (result.isStateDataOrCheckpointSaverTag()) { System.out.println("Final state: " + result.asStateDataOrLastCheckpointStateData()); } else if (result.isInterruptionMetadata()) { System.out.println("Graph interrupted: " + result.asInterruptionMetadata()); } });

} }

Explanation:

This example demonstrates the basic workflow: define state, define nodes, wire them with edges, compile, and run.

Running Your Graph

As shown in the example, you typically run a compiled graph using one of its execution methods:

The RunnableConfig can be used to pass in runtime configuration.

Studio ๐Ÿคฉ - Running Your Graph visually

Langgraph4j Studio is an embeddable web application for visualizing and experimenting with graphs:

To explore the Langgraph4j Studio go to [studio]

BONUS: built-in integrations

Integration Paths

| Integration | Best for | Quick links | |---|---|---| | LangChain4j | Projects already using LangChain4j chat models, tools, and agent patterns | langchain4j/README.md, langchain4j/langchain4j-agent/README.md | | Spring AI | Spring Boot and Spring-native MCP / agent applications | spring-ai/README.md, spring-ai/spring-ai-agent/README.md |

LangChain4j

As default use case to proof [LangChain4j] integration, We have implemented AgentExecutor (aka ReACT Agent) using LangGraph4j. In the [project's module][agent-executor], you can the complete working code with tests. Feel free to checkout and use it as a reference. Below usage example of the AgentExecutor.

Define Tools

public class TestTool {

@Tool("tool for test AI agent executor") String execTest(@P("test message") String message) { return format( "test tool ('%s') executed with result 'OK'", message); }

@Tool("return current number of system thread allocated by application") int threadCount() { return Thread.getAllStackTraces().size(); }

}

Run Agent


var model OllamaChatModel.builder()
                .modelName(  )
                .baseUrl("http://localhost:11434")
                .supportedCapabilities(Capability.RESPONSE_FORMAT_JSON_SCHEMA)
                .logRequests(true)
                .logResponses(true)
                .maxRetries(2)
                .temperature(0.0)
                .build();

var agent = AgentExecutor.builder() .chatModel(model) .toolsFromObject(new TestTool()) .build() .compile();

agent.stream( Map.of( "messages", "perform test twice and return number of current active threads" ) ) .forEachAsync( item -> System.out.println( item ));

Spring AI

As default use case to proof [Spring AI] integration, We have implemented AgentExecutor (aka ReACT Agent) using LangGraph4j. In the [project's module][spring-ai-agent], you can the complete working code with tests. Feel free to checkout and use it as a reference. Below usage example of the AgentExecutor.

Define Tools

public class TestTool {

@Tool(description = "tool for test AI agent executor") String execTest( @ToolParam(description ="test message") String message ) { return format( "test tool ('%s') executed with result 'OK'", message); }

@Tool(description = "return current number of system thread allocated by application") int threadCount() { return Thread.getAllStackTraces().size(); }

}

Run Agent


var model = OllamaChatModel.builder()
                    .ollamaApi(OllamaApi.builder()
                            .baseUrl("http://localhost:11434")
                            .build())
                    .options(OllamaChatOptions.builder()
                            .model(model)
                            .temperature(0.0)
                            .build())
                    .build();

var agent = AgentExecutor.builder() .chatModel(model) .toolsFromObject(new TestTool()) .build() .compile() ;

agent.stream( Map.of( "messages", "perform test twice and return number of current active threads" ) ) .forEachAsync( item -> System.out.println( item ));

Key Capabilities Overview

LangGraph4j is packed with features to build sophisticated agentic applications:

GitHub Stars & Activity

2,086Stars
296Forks
20Open issues
JavaLanguage

GitHub Popularity

GitHub stars2,086
Forks296
Open issues20
Primary languageJava
LicenseMIT
Stars gained today2
Created2024-03-18
Last pushed2026-11-03

Trending History

Daily boardrank #64 ยท โ–ฒ 2 stars

Related AI Projects

1

alibaba / spring-ai-alibaba

Javaโ˜… 11,111โ‘‚ 2,470โ–ฒ 3 stars
โ†’
2

agentscope-ai / agentscope-java

Javaโ˜… 6,265โ‘‚ 1,570โ–ฒ 18 stars
โ†’
3

Stonewuu / ai-fusion-video

Javaโ˜… 1,710โ‘‚ 359โ–ฒ 10 stars
โ†’
4

zed-0xff / ZombieBuddy

Javaโ˜… 314โ‘‚ 80โ–ฒ 6 stars
โ†’
5

morluto / rea

TypeScriptโ˜… 433,866โ‘‚ 0
โ†’
6

mattpocock / skills

Shellโ˜… 314,911โ‘‚ 26,376โ–ฒ 2,053 stars
โ†’
7

affaan-m / ECC

JavaScriptโ˜… 297,760โ‘‚ 0
โ†’
8

deepseek-ai / deepseek-harness

TypeScriptโ˜… 273,692โ‘‚ 0
โ†’

More AI Rankings