CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-bsc-langgraph4j--langgraph4j-core

A library for building stateful, multi-agents applications with LLMs

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

LangGraph4j Core

LangGraph4j is a Java library for building stateful, multi-agent applications with Large Language Models (LLMs). It provides a framework for creating cyclical graphs where different components (agents, tools, or custom logic) can interact in a stateful manner, enabling complex AI applications with memory, context awareness, and sophisticated control flow patterns.

Package Information

  • Package Name: langgraph4j-core
  • Package Type: maven
  • Language: Java
  • Group ID: org.bsc.langgraph4j
  • Artifact ID: langgraph4j-core
  • Installation: Add to Maven dependencies:
<dependency>
    <groupId>org.bsc.langgraph4j</groupId>
    <artifactId>langgraph4j-core</artifactId>
    <version>1.6.4</version>
</dependency>

Core Imports

import org.bsc.langgraph4j.*;
import org.bsc.langgraph4j.action.*;
import org.bsc.langgraph4j.state.*;
import org.bsc.langgraph4j.checkpoint.*;

Basic Usage

import org.bsc.langgraph4j.*;
import org.bsc.langgraph4j.action.AsyncNodeAction;
import org.bsc.langgraph4j.state.AgentState;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

// Define a custom state class
class MyState extends AgentState {
    public MyState(Map<String, Object> initData) {
        super(initData);
    }
}

// Create a state graph
StateGraph<MyState> workflow = new StateGraph<>(MyState::new);

// Add nodes with actions
workflow.addNode("start_node", (state) ->
    CompletableFuture.completedFuture(Map.of("processed", true))
);

workflow.addNode("end_node", (state) ->
    CompletableFuture.completedFuture(Map.of("finished", true))
);

// Add edges between nodes
workflow.addEdge("start_node", "end_node");
workflow.addEdge("end_node", StateGraph.END);

// Set entry point
workflow.addEdge(StateGraph.START, "start_node");

// Compile and run
CompiledGraph<MyState> app = workflow.compile();
Optional<MyState> result = app.invoke(Map.of("input", "Hello World"));

Architecture

LangGraph4j is built around several key components:

  • State Management: AgentState and Channel system for managing application state with configurable update patterns
  • Graph Structure: StateGraph for defining workflows and CompiledGraph for execution
  • Action System: Synchronous and asynchronous action interfaces for node logic
  • Checkpoint System: Persistent state snapshots for debugging, resuming, and time travel
  • Configuration: Fine-grained control over execution with CompileConfig and RunnableConfig
  • Streaming: Real-time execution monitoring with streaming output support

Capabilities

Graph Construction and Management

Core functionality for building and managing stateful workflow graphs. Supports nodes, edges, conditional routing, and subgraphs.

class StateGraph<State extends AgentState> {
    StateGraph<State> addNode(String id, AsyncNodeAction<State> action);
    StateGraph<State> addNode(String id, AsyncNodeActionWithConfig<State> action);
    StateGraph<State> addEdge(String sourceId, String targetId);
    StateGraph<State> addConditionalEdges(String sourceId, AsyncCommandAction<State> condition, Map<String, String> mappings);
    CompiledGraph<State> compile();
    CompiledGraph<State> compile(CompileConfig config);
}

Graph Construction

Graph Execution and Control

Execute compiled graphs with sophisticated control flow, streaming, and state management. Support for synchronous execution, streaming outputs, and state snapshots.

class CompiledGraph<State extends AgentState> {
    Optional<State> invoke(Map<String, Object> inputs);
    Optional<State> invoke(GraphInput input, RunnableConfig config);
    AsyncGenerator<NodeOutput<State>> stream(Map<String, Object> inputs, RunnableConfig config);
    AsyncGenerator<NodeOutput<State>> streamSnapshots(Map<String, Object> inputs, RunnableConfig config);
}

Graph Execution

State Management System

Comprehensive state management with channels, serialization, and update strategies. Handles complex state updates with merge functions and conflict resolution.

class AgentState {
    Map<String, Object> data();
    <T> Optional<T> value(String key);
    static Map<String, Object> updateState(Map<String, Object> state, Map<String, Object> partialState, Map<String, Channel<?>> channels);
}

interface Channel<T> {
    Object update(String key, Object currentValue, Object newValue);
}

State Management

Action System and Node Logic

Define node behavior with synchronous and asynchronous actions. Support for configuration-aware actions and complex routing logic.

@FunctionalInterface
interface AsyncNodeAction<S extends AgentState> {
    CompletableFuture<Map<String, Object>> apply(S state);
    static <S extends AgentState> AsyncNodeAction<S> node_async(NodeAction<S> syncAction);
}

@FunctionalInterface
interface AsyncCommandAction<S extends AgentState> {
    CompletableFuture<Command> apply(S state, RunnableConfig config);
}

Actions and Node Logic

Checkpoint and Persistence

Persistent state management with checkpointing for debugging, resuming execution, and implementing human-in-the-loop workflows.

interface BaseCheckpointSaver {
    Collection<Checkpoint> list(RunnableConfig config);
    Optional<Checkpoint> get(RunnableConfig config);
    RunnableConfig put(RunnableConfig config, Checkpoint checkpoint) throws Exception;
    Tag release(RunnableConfig config) throws Exception;
}

class Checkpoint {
    String getId();
    String getNodeId();
    String getNextNodeId();
    Map<String, Object> getState();
}

Checkpoints and Persistence

Configuration and Runtime Control

Configure graph compilation and execution behavior with interrupts, thread management, and metadata handling.

class CompileConfig {
    Optional<BaseCheckpointSaver> checkpointSaver();
    Set<String> interruptsBefore();
    Set<String> interruptsAfter();
    boolean releaseThread();
    static Builder builder();
}

class RunnableConfig {
    Optional<String> threadId();
    Optional<String> checkPointId();
    Optional<String> nextNode();
    StreamMode streamMode();
    Optional<Object> metadata(String key);
}

Configuration

Prebuilt Components

Ready-to-use components for common patterns like message handling and specialized state management.

class MessagesState<T> extends AgentState {
    List<T> messages();
    Optional<T> lastMessage();
    Optional<T> lastMinus(int n);
    static final Map<String, Channel<?>> SCHEMA;
}

class MessagesStateGraph<T> extends StateGraph<MessagesState<T>> {
    MessagesStateGraph();
    MessagesStateGraph(StateSerializer<MessagesState<T>> stateSerializer);
}

Prebuilt Components

Types

// Core state type
abstract class AgentState {
    static final Object MARK_FOR_REMOVAL;
    static final Object MARK_FOR_RESET;
}

// Command for routing control
class Command {
    String gotoNode();
    Map<String, Object> update();
}

// Graph input types
interface GraphInput {}
class GraphArgs implements GraphInput {
    Map<String, Object> value();
}
class GraphResume implements GraphInput {}

// Execution output
interface NodeOutput<State extends AgentState> {
    String node();
    State state();
}

// Stream modes
enum StreamMode {
    VALUES, SNAPSHOTS
}

// Diagram generation
enum GraphRepresentation.Type {
    PLANTUML, MERMAID
}

// Exception types
class GraphStateException extends RuntimeException {}
class GraphRunnerException extends RuntimeException {}
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.bsc.langgraph4j/langgraph4j-core@1.6.x
Publish Source
CLI
Badge
tessl/maven-org-bsc-langgraph4j--langgraph4j-core badge