█

AI/TLDR

Buy me a coffee
Buy me a coffee

LangChain4j

Idiomatic Java library for building LLM-powered apps on the JVM

Agent Frameworks & BuildersOpen source
Language
Java
License
Apache-2.0
IN SHORT

What is LangChain4j?

LangChain4j is an open-source Java library that makes it easier to add large language models to Java applications. It sits in the Agent Frameworks & Builders category of the Agents & Automation tools and is open-source, written in Java and licensed Apache-2.0. To get started: add the dependencies.

Overview

LangChain4j is an open-source Java library that makes it easier to add large language models to Java applications. It gives you a single, unified API so you can call many different LLM providers and embedding (vector) stores without learning each provider's own API. If you want to try a different model or store, you can switch with minimal code changes.

Despite the name, it is not a Java port of the Python LangChain project. It is built from the ground up for Java, using familiar conventions like type safety, POJOs, annotations, interfaces, and fluent builders. It ships first-class integrations for Quarkus, Spring Boot, Helidon, and Micronaut, and offers ready-made building blocks for prompt templating, chat memory, function calling, RAG, and agents.

What it does

  • One unified API across 20+ popular LLM providers (such as OpenAI and Google Vertex AI), so you can swap models without rewriting your code
  • Built-in support for 30+ embedding (vector) stores like Pinecone and Milvus for retrieval workloads
  • A toolbox covering low-level pieces (prompt templating, chat memory, function calling) up to high-level patterns like RAG and agents
  • Designed around Java conventions: type safety, POJOs, annotations, interfaces, and fluent APIs
  • First-class integrations with Quarkus, Spring Boot, Helidon, and Micronaut
  • A large set of runnable examples in the separate langchain4j-examples repository to help you start quickly

Getting started

LangChain4j is published to Maven Central. It needs JDK 17 or newer. Add the core library and the integration module for the provider you want to use (here, OpenAI), then call a model.

Add the dependencies

Add the core LangChain4j library and the OpenAI integration module to your Maven project. Use the latest version shown on Maven Central.

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

Call a model

Build a chat model with your API key and model name, then send a message. The chat method returns the model's reply as a String.

javajava
String apiKey = System.getenv("OPENAI_API_KEY");

OpenAiChatModel model = OpenAiChatModel.builder()
    .apiKey(apiKey)
    .modelName("gpt-4o-mini")
    .build();

String answer = model.chat("Say 'Hello World'");
System.out.println(answer);

Explore more examples

The langchain4j-examples repository contains runnable samples in plain Java and for Quarkus, Spring Boot, Helidon, and Micronaut, covering chatbots, RAG, and more. The full docs live at docs.langchain4j.dev.

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

When to use it

  • Building chatbots and assistants inside Java and Spring Boot or Quarkus applications
  • Creating RAG pipelines that ground answers in your own documents using embedding stores
  • Adding function calling and agent-style workflows so an LLM can use tools and take actions
  • Staying portable across LLM providers by switching models behind one unified API

How LangChain4j compares

LangChain4j alongside other open-source agent frameworks & builders tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
DeepSeek Harness★ 289kDeepSeek AI's open-source agent harness (dsh), built on Cordis, where models, tools, skills, sessions, sandboxes, storage and the UI are all plugins composed through profiles.
AutoGPT★ 188kOne of the earliest autonomous agent projects, now a platform for building and running agents from reusable blocks and workflows.
DeerFlow★ 86kByteDance's open-source super agent harness built on LangGraph: skills, sub-agents, sandboxes, a filesystem and long-term memory for long-horizon research, coding and content tasks.
nanobot★ 50.5kLightweight self-hosted personal AI agent framework in Python, with a WebUI, terminal and chat-app channels, tools, long-term memory, MCP and scheduled automations.
LangGraph★ 45.6kA library from the LangChain team for building stateful, graph-based agent workflows with explicit control over steps, memory, and human-in-the-loop checkpoints.
Agno★ 43.3kA fast Python framework (formerly Phidata) for building agents with memory, tools, and multimodal inputs, plus a runtime for deploying them in production.
AgentGPT★ 36.3kAgentGPT lets you name a custom AI, give it a goal, and watch it plan tasks, run them, and learn from the results, all from a web browser.
LangChain4j★ 13.5kIdiomatic Java library for building LLM-powered apps on the JVM