LangChain4j

One idiomatic Java API for LLM apps and agents on the JVM, with swappable model and vector-store providers.

Stars
★ 13k
Last updated
today
FARS reviewed
Dec 01, 2026
License
Apache-2.0
Primary language
Java

At a glance

How it runs
Library / SDKFramework
Works with
Universal · cross-platformOpenAI API · Claude API
Cost
Free software; you pay for model usage
Setup effort
Medium · a few setup steps
You'll need
Java 17 or newerNetwork accessMCP Server
Typical use
Java backend teams already running Spring Boot who want to add a support assistant that declares an interface and looks up order status through a @Tool method.
Not a fit if
  • Teams that cannot run Java 17+ on a JVM
  • Users wanting a ready-made chat UI or no-code agent builder
  • Teams expecting to reuse Python LangChain tutorials and plugins directly
Website
docs.langchain4j.dev ↗ set on GitHub
Maintenance
Commits in the last 30 dayslast commit 2026-12-01

What does this agent do, and when should you use it?

LangChain4j is an open-source (Apache-2.0) Java library for building LLM-powered applications and agents on the JVM, requiring Java 17 or newer. A single API spans 20+ LLM providers and 40+ embedding (vector) stores, so you can change model or store without rewriting business code. The building blocks are AI Services (declare a Java interface, the library implements it), tools and MCP, RAG pipelines, agent workflows, structured outputs, chat memory, input/output and tool guardrails, observability and testing support. You consume it as a Maven dependency (dev.langchain4j:langchain4j, version 1.24.1 in the README) inside your own Java project, wiring a ChatModel and AiServices through builders. It integrates with Quarkus, Spring Boot, Helidon, Micronaut and Jakarta EE, and states explicitly that it is not a Java port of LangChain (Python).

You declare an interface, annotate a method with @SystemMessage, and let AiServices.builder(Assistant.class).chatModel(model).tools(new OrderTools()).build() generate the implementation. When you call assistant.chat(...), the library sends the message to the model; if the model asks for a @Tool-annotated Java method, the library runs it, feeds the result back, and returns the model's final answer. Methods can return text, your own classes or records, or a stream of tokens, covering structured outputs and streaming/non-blocking calls. On the RAG side it loads, splits, embeds and retrieves documents, from a few lines of Easy RAG to a fully customized pipeline. On the agent side it offers sequence, loop, parallel and conditional workflows, supervisor agents, human-in-the-loop steps, A2A, and runs that can be suspended, persisted and resumed. Guardrails check inputs, outputs, and tool calls/results with model retries; observability exposes listeners for model calls, tools, RAG and AI Service events plus Micrometer metrics; testing provides mock models and model-as-a-judge checks.

  1. Java backend teams already running Spring Boot who want to add a support assistant that declares an interface and looks up order status through a @Tool method.
  2. Teams building retrieval-augmented Q&A over internal documents, embedding and searching in pgvector, Elasticsearch, Milvus or another supported store.
  3. Platform teams avoiding single-vendor lock-in who need to switch between OpenAI, Anthropic, Gemini, Bedrock or Ollama without rewriting code.
  4. Teams building agent workflows with human approval steps and long-running runs that can be paused, persisted and resumed.
  5. Enterprises on Quarkus, Micronaut, Helidon or Jakarta EE that need LLM integration that fits their dependency-injection container.
  6. Engineers who want fast unit tests in CI using mock models instead of calling a real provider on every run.

Key setup facts

Pulled from the install and usage notes below. The project README has the current values.

Environment variables
OPENAI_API_KEY
Runtime
Java 17

How do you install or deploy this agent?

Java 17 or newer is required. Add the core module and one provider module to your Maven build (the README pins 1.24.1):

<dependency>
    <groupId>dev.langchain4j</groupId>
    <artifactId>langchain4j</artifactId>
    <version>1.24.1</version>
</dependency>
<dependency>
    <groupId>dev.langchain4j</groupId>
    <artifactId>langchain4j-open-ai</artifactId>
    <version>1.24.1</version>
</dependency>

Use langchain4j-bom to keep module versions aligned, including the Spring Boot starters; community integrations have their own langchain4j-community-bom. Spring Boot users get dedicated starters for Spring Boot 3.5+ and 4, while Quarkus users should use the LangChain4j version shipped by the Quarkus platform.

How do you use this agent?

Export your provider key, build a ChatModel, and bind it to an AI Service interface:

export OPENAI_API_KEY=your-key-here
interface Assistant {

    @SystemMessage("You are a friendly support agent of an online shop.")
    String chat(String userMessage);
}

class OrderTools {

    @Tool("Returns the delivery status of an order")
    String getOrderStatus(String orderId) {
        return "Order " + orderId + ": shipped, arrives tomorrow";
    }
}

ChatModel model = OpenAiChatModel.builder()
        .apiKey(System.getenv("OPENAI_API_KEY"))
        .modelName("gpt-6-luna")
        .reasoningEffort("none")
        .build();

Assistant assistant = AiServices.builder(Assistant.class)
        .chatModel(model)
        .tools(new OrderTools())
        .build();

String answer = assistant.chat("Where is my order 12345?");

To switch providers, add that integration's dependency (for example Ollama for a local model) and change how model is constructed; the Assistant interface stays the same. The model and its integration must support the features you rely on, such as tool calling — check the official language-models comparison table.

Safety boundaries, hardening & integrations

Operational blast radius, source-verified safety controls, and first-run hardening steps before connecting this agent to real workspaces.

Declared capability surface (blast radius)

Outbound network access

Makes outbound requests; verify telemetry settings and model data routing on private repos.

External MCP tool bridge

Inherits capabilities of connected MCP servers; audit third-party servers before enabling.

FARS trust-control audit

Not found in source — apply before daily use
  • rollback or recovery path — Back up first, or work on a git branch or snapshot, so its changes can be undone.

What are this agent's strengths and limitations?

Pros
  • One API across 20+ LLM providers and 40+ embedding/vector stores, so swapping a model or store does not force a rewrite.
  • Java-native design: interfaces, annotations, POJOs and records, and fluent builders; AI Services generate the implementation from an interface instead of a bespoke DSL.
  • Agent support goes beyond single-turn tool calls: sequence/loop/parallel/conditional workflows, supervisor agents, human-in-the-loop, and runs that can be suspended, persisted and resumed.
  • Layered RAG story from a few lines of Easy RAG to a fully customized pipeline, backed by document loaders, parsers, re-ranking models and web search engines.
  • Documented integration paths for Quarkus, Spring Boot, Helidon, Micronaut and Jakarta EE, fitting existing enterprise Java stacks.
  • Apache-2.0 licensed and already used in released versions by projects such as Apache Camel, Camunda, Kestra and WildFly.
Limitations
  • JVM-only and requires Java 17 or newer, so it cannot be reused from other language stacks.
  • Modules versioned with a -beta suffix (e.g. 1.24.1-beta34) and APIs marked @Experimental may still change in future releases, so version pinning matters.
  • The library is free, but running anything real requires your own paid model API key or a self-deployed local runtime such as Ollama.
  • Many integrations live in the separate langchain4j-community repository with their own BOM, so version alignment takes extra bookkeeping.
  • The name invites confusion with Python LangChain: the API, internals and release cycle are independent, so Python tutorials and plugins do not carry over.

How does this agent compare with similar options?

The README explicitly names LangChain (Python): despite the name, LangChain4j is not a Java port of it but was designed from the ground up for Java — type safety, POJOs, annotations, interfaces, dependency injection and fluent APIs — with its API, internals and release cycle independent of the Python project. Teams with Python LangChain experience should not expect one-to-one concepts or reusable plugins, while Java teams do not need a Python runtime to build LLM features.

Key facts side by side with the most closely related agents.

Agent Source review Form / cost Stars Updated Language Full support on
LangChain4j This agent 52 · Major gaps Library / SDKFree + model costs ★ 13k today Java OpenAI API · Claude API
ai4j — Java AI Agentic SDK 60 · Some gaps Library / SDKFree + model costs ★ 443 today Java OpenAI API · Claude API
ReachAI Enterprise Agent Platform 67 · Some gaps Self-hosted serviceFree + model costs ★ 1.1k 2d ago Java OpenAI API
Spring AI Application and Agent Examples 42 · Major gaps Framework ★ 156 4mo ago Java —

How does FollowAgents rate this agent?

FollowAgents source review · FARS-2.1
Major gaps
52/ 100 5-point scale 2.6 / 5
Trust 11/29
Reliability 6/14
Adaptability 12/18
Convention 12/18
Effectiveness 7/13
Verifiability 4/8
Why each dimension lost points
Trust11 / 29 · 1.9/5

README shows tools/MCP can let the model call Java methods and MCP tools; guardrails/tool guardrails and human-in-the-loop are mentioned; the example reads the API key from an environment variable, and SECURITY.md provides vulnerability reporting and a signing key. Deductions: no default least-privilege/sandbox/tool allowlist, no concrete user confirmation before tool calls, data-flow and sensitive-data/PII handling are only high-level, no rollback for external side effects, and dependency security evidence is limited to SHA-pinned actions and a BOM with no scanning/SBOM. Source attribution has Apache-2.0 and documentation/example links, but no NOTICE in the packet.

Reliability6 / 14 · 2.1/5

README is internally consistent and gives Java 17, Maven coordinates, a BOM, and release cadence; dependencies are available from Maven Central. Deductions: no source/tests in the packet to verify runtime consistency, no failure-message/error-code documentation, and no offline or lockfile evidence for dependency availability.

Adaptability12 / 18 · 3.3/5

README clearly targets JVM/Java developers and covers plain Java, Quarkus, Spring Boot, Helidon, Micronaut, and Jakarta EE; it states that models/integrations must support the features used, that beta/@Experimental APIs may change, and that it is not a Python LangChain port. Deductions: no agent trigger/activation precision mechanism (AI Services are explicit interface calls), and capability boundaries are not exhaustive.

Convention12 / 18 · 3.3/5

README has clear information architecture with Maven quick start, Java 17, BOM, framework integrations, examples/tutorial links, release cadence, and beta notes; LICENSE is the full Apache-2.0 text. Deductions: install notes are Maven-centric, naming stability has no explicit policy, FAQ is absent, maintenance responsibility/governance is unclear, and no changelog is in the packet.

Effectiveness7 / 13 · 2.7/5

The quick start gives a readable Java interface plus tool-calling example, and the README lists structured outputs, streaming, RAG, and agents; marginal value comes from a unified multi-provider/vector-store API and framework integrations. Deductions: static review cannot verify actual output quality, and there is no cost/token-budget control, so cost-benefit depends on external LLM pricing.

Verifiability4 / 8 · 2.5/5

Most capability claims in README link to documentation, comparison tables, and release notes, and SECURITY/LICENSE/workflows provide cross-source corroboration. Deductions: main source and tests are absent from the packet, some marketing-style claims cannot be traced in-packet, and facts are mixed with inference/guidance without explicit evidence labels.

Risks and how to mitigate them
  • Not found in source: rollback or recovery pathBack up first, or work on a git branch or snapshot, so its changes can be undone.
  • Tools/MCP/experimental shell capabilities can execute Java methods or commands; before production, configure tool allowlists, sandboxing, guardrails, and human confirmation, and do not expose high-privilege tools directly.
  • No rollback mechanism for external side effects was found; suspend/persist/resume is not rollback, so design compensation/idempotency at the business layer.
  • Sensitive data and secrets: the example only uses an environment variable, with no PII redaction or log/observability retention policy; implement your own secret management and data governance.
  • Dependency-security evidence is limited: SHA-pinned actions, npm --ignore-scripts, and a BOM are present, but no dependency scanning/SBOM is shown; run SCA before adoption.
  • No failure-message/error-handling source or documentation is in the packet; test error paths yourself.
  • Publisher identity is unverified, and maintenance responsibility/governance is unclear; confirm support and update paths before adoption.
  • The SKILL.md files in test resources include a python-script example; they are test fixtures and should not be treated as production skill instructions.
Evidence confidence: Low Reviewed Dec 01, 2026 Reviewed revision b6f4283db94d
See the full review method →
Maintain this project? Add the FARS badge to your README

The badge shows the current review score and verdict and links back to this page. It refreshes about once an hour after a re-review.

FARS

[![FARS review](https://followagents.com/badge/langchain4j.svg)](https://followagents.com/en/agents/langchain4j)
<a href="https://followagents.com/en/agents/langchain4j"><img src="https://followagents.com/badge/langchain4j.svg" alt="FARS review"></a>

FAQ

Does LangChain4j cost anything?
The library itself is free under Apache-2.0. Costs come from the model side: you supply your own cloud provider API key and pay per use, or switch to a local model such as Ollama and carry the hardware and deployment cost yourself.
Can it run fully offline?
You can avoid cloud API calls by using a local model integration such as Ollama, and the docs mention embedding models that run inside your JVM. Whether a given setup works offline depends on the provider integration and the features you need (for example tool calling) — check the official language-models comparison table.
Will upgrading break my code?
A new minor version ships roughly every three weeks, and the README states that -beta modules and APIs marked @Experimental can still change in a future release. Align versions with langchain4j-bom and watch the release notes.
Do I need Spring Boot or Quarkus to use it?
No. It works in a plain Java project as a Maven dependency; Quarkus, Spring Boot, Helidon, Micronaut and Jakarta EE are additional integration paths (with Quarkus tracking the version shipped by the Quarkus platform).
How do I report a security issue?
The README asks you to follow SECURITY.md rather than opening a public issue. Feature requests and bugs go through GitHub Issues or Discussions.
Was this page helpful?
View on GitHub ↗ Install ↓

Compare agents like this one

The same FARS review applied across the shortlist this agent qualifies for.

Related concepts