跪拜 Guibai
← All articles
Backend

LangChain4j Connects Java to LLMs; LangGraph4j Orchestrates the Agents That Use Them

By 苏三说技术 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Java shops building AI agents face the same integration-versus-orchestration split that microservices tooling forced years ago. Picking the wrong layer for the job means either hand-rolling state machines inside LangChain4j or over-engineering simple prompts with a graph framework.

Summary

LangChain4j is a Java LLM framework that unifies access to 20+ models, embeddings, RAG, and tool calling behind a declarative AiServices API. It solves the integration problem — getting a model to call a Java method with a single @Tool annotation. LangGraph4j is a state-graph orchestration engine that compiles flowcharts into runnable programs, enforcing a shared AgentState across nodes and supporting conditional branching, loops, parallel execution, and checkpoint recovery.

The two frameworks combine naturally: LangChain4j handles model invocation and RAG, while LangGraph4j manages multi-agent workflows, supervisor patterns, fan-out parallelism, and human-in-the-loop pauses. A code-review pipeline that loops through analyze-review-improve-approve with dynamic routing and retry limits is trivial in LangGraph4j but requires manual state management in LangChain4j alone.

Version maturity differs — LangChain4j sits at 1.11.0 with a broad Spring Boot ecosystem, while LangGraph4j is at 1.7.10/1.8-beta and depends on LangChain4j or Spring AI for actual model calls. The decision hinges on workflow complexity: single-agent tool use stays simple with LangChain4j; multi-step decisions, multi-agent collaboration, and long-running tasks that need crash recovery push toward LangGraph4j.

Takeaways
LangChain4j provides a unified interface to 20+ LLMs, embeddings, vector stores, and tool calling, with a declarative AiServices API that turns AI calls into plain Java interfaces.
LangGraph4j compiles directed state graphs into executable workflows, enforcing a shared, type-safe AgentState across all nodes and supporting conditional edges, loops, and parallel execution.
Checkpointing in LangGraph4j serializes full state and execution context after every update, enabling precise crash recovery without rerunning the entire workflow.
Supervisor, fan-out, and human-in-the-loop patterns are built into LangGraph4j, covering most enterprise multi-agent scenarios without custom orchestration code.
LangGraph4j is framework-agnostic at its core; it adapts to LangChain4j or Spring AI for model access, so switching the underlying AI library does not require rewriting the graph.
LangChain4j alone is sufficient for single-agent tool use, RAG, and quick prototypes; LangGraph4j becomes necessary when workflows involve multi-step decisions, loops, or multiple collaborating agents.
LangChain4j 1.11.0 and LangGraph4j 1.7.10/1.8-beta are the current versions as of early 2026, with LangGraph4j still maturing toward production stability.
Conclusions

Framing these as competitors misses the point entirely — one is a parts catalog, the other is an assembly line, and most production systems will need both.

The real cost of using LangChain4j for complex workflows isn't missing features but the invisible state-management code developers end up writing and debugging themselves.

LangGraph4j's checkpointing isn't just a reliability feature; it changes the economics of long-running agent tasks by making partial reruns cheap instead of forcing full restarts.

Java's AI agent story now mirrors Python's, but the split between access and orchestration layers is sharper because Java developers expect type safety and explicit state contracts that Python's dynamic style often glosses over.

The three-question decision framework — how many steps, how many agents, can you afford full reruns — applies to any language ecosystem evaluating agent orchestration, not just Java.

Concepts & terms
AiServices (LangChain4j)
A declarative API that lets developers define an AI service as a Java interface; the framework auto-generates the implementation, handling model calls, message construction, and response parsing.
StateGraph (LangGraph4j)
The core abstraction of LangGraph4j — a directed graph where nodes represent agent behaviors, edges define transitions, and a shared AgentState object carries data between nodes.
AgentState
A type-safe, versioned, immutable-snapshot-capable data object that all nodes in a LangGraph4j workflow read from and write to, eliminating direct node-to-node communication.
Checkpointing
Automatic serialization of full workflow state and execution context after each node update, persisted to Redis or PostgreSQL, enabling crash recovery from the last successful step.
Supervisor Pattern
A multi-agent orchestration pattern where a master agent analyzes intent and delegates sub-tasks to specialized worker agents, often running them in parallel.
Human-in-the-Loop (HITL)
A workflow pause mechanism that halts execution at sensitive steps, pushes state for human approval, and resumes only after receiving a human response.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗