
LangChain4j
LLM integration written in Java conventions — annotated interfaces, POJOs, type safety
What is LangChain4j?
The headline feature is AI Services: you declare a Java interface, annotate it, and the library supplies the implementation that builds the prompt, calls the model and maps the reply back onto your return type. Underneath, a plain ChatModel API is there whenever the declarative layer gets in the way, and RAG, tool calling and integrations for Spring Boot, Quarkus, Micronaut and Helidon are first-party. Despite the name it is not a port of the Python library, so material from that ecosystem does not transfer.
What can you do with LangChain4j?
- Declare an interface and get the implementation — AI Services turn an annotated Java interface into a working client: the prompt template, the model call and the conversion of the reply into your declared return type are all generated, so the calling code stays ordinary Java.
- Drop to the primitives when you need to — ChatModel with UserMessage and AiMessage gives direct control over the exchange. The two layers coexist, so the declarative shortcut is never a one-way door.
- Let the model call your methods — Tool calling binds Java methods to the model's function-calling interface, including code the model generates at run time, with the arguments arriving as typed parameters.
- Build retrieval without leaving the JVM — Document loading, splitting, embedding, storage and retrieval are covered in one library, along with re-ranking and query transformation, across more than thirty embedding stores.
- Wire it into the framework you already run — Spring Boot, Quarkus, Micronaut and Helidon all have official starters, so configuration, dependency injection and lifecycle follow the conventions of the host framework rather than the library's.
Before you choose LangChain4j
- Despite the name it is not a port of the Python LangChain but an independent design, so chains, tutorials and community examples from that ecosystem do not carry across.
Star history
21 Aug to 30 Oct · +406
Frequently asked questions
Is LangChain4j free for commercial use?
LangChain4j is released under the Apache-2.0 licence — OSI-approved open source, which permits commercial use.
How can LangChain4j be deployed?
LangChain4j is available as Self-hosted / Runs locally.