Open-source AI agent application platform built on Java, LangChain4j, Spring Boot and Vue 3, covering models, agents, RAG, Skills, MCP and text-to-SQL analysis.
LnYo-Cly/ai4j
A Java 8+ SDK for building AI agents, with unified access to multiple LLM platforms, tool calling, MCP, RAG, and a built-in coding agent CLI/TUI.
- Stars
- 437
- Forks
- 56
- Open issues
- 4
- Last commit
- 24 days ago
What is it?
ai4j is a Java SDK for building LLM-based applications and agents. It exposes one factory interface for chat, responses, and messages protocols across providers such as OpenAI, Anthropic, DashScope, Doubao, DeepSeek, Zhipu, and Ollama, and switching providers mainly means changing the platform type and its config. Function calling, streaming, embeddings, and image, audio, and video generation services are also provided behind the same entry point.
On top of model access, the project includes agent execution modes (ReAct, CodeAct, Deep Research), a StateGraph for orchestration, subagent delegation, and a RAG pipeline with document loading, chunking, several vector store adapters, and reranking. It also implements MCP client and server over stdio, SSE, and Streamable HTTP, plus A2A support. A Spring Boot starter provides an injectable AiService.
The repository also ships ai4j-cli, a coding agent available as a CLI, a TUI, or an ACP endpoint for IDE integration, and it can be embedded as a dependency. An extension SPI lets plugins add tools, commands, skills, and prompts, loaded through ServiceLoader and enabled explicitly.
Key features
- 01Unified access to many LLM providers through one factory, with Chat, Responses, and Messages protocols.
- 02Agent execution with ReAct, CodeAct, and Deep Research modes, plus StateGraph orchestration.
- 03Built-in RAG with document parsing, chunking, multiple vector store adapters, and reranking.
- 04MCP client and server over Stdio, SSE, and Streamable HTTP, and A2A agent collaboration.
- 05Spring Boot starter that injects AiService with a few lines of configuration.
- 06Coding Agent available as CLI, TUI, and ACP entry points.
Use cases
- Adding LLM chat, embeddings, or multimodal generation to a Java or Spring Boot backend.
- Building retrieval-augmented question answering over internal documents with a Java stack.
- Exposing internal systems as tools for agents through MCP or custom plugins.
- Running a local coding agent from the terminal or embedding one in a Java tool.
Quick start
- 1
Add the Maven Central dependency to your project
implementation 'io.github.lnyo-cly:ai4j:2.8.1' - 2
Set your OpenAI API key as an environment variable
export OPENAI_API_KEY=your-api-key - 3
Create the first chat program from the README example and run it
Things to know
- The 30-second example requires an OpenAI API key or a configured alternative platform.
In collections
Topics
FAQ
- What is ai4j?
- A Java 8+ SDK for building AI agents, with unified access to multiple LLM platforms, tool calling, MCP, RAG, and a built-in coding agent CLI/TUI. ai4j is a Java SDK for building LLM-based applications and agents. It exposes one factory interface for chat, responses, and messages protocols across providers such as OpenAI, Anthropic, DashScope, Doubao, DeepSeek, Zhipu, and Ollama, and switching providers mainly means changing the platform type and its config. Function calling, streaming, embeddings, and image, audio, and video generation services are also provided behind the same entry point.
- Is ai4j free to use? What license does it have?
- ai4j is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
- Is ai4j still maintained?
- Actively maintained. The last commit to ai4j was on Oct 13, 2026.
- What can I use ai4j for?
- Adding LLM chat, embeddings, or multimodal generation to a Java or Spring Boot backend. Building retrieval-augmented question answering over internal documents with a Java stack. Exposing internal systems as tools for agents through MCP or custom plugins. Running a local coding agent from the terminal or embedding one in a Java tool.
- How do I install ai4j?
- Add the Maven Central dependency to your project: implementation 'io.github.lnyo-cly:ai4j:2.8.1' Set your OpenAI API key as an environment variable: export OPENAI_API_KEY=your-api-key Create the first chat program from the README example and run it
- Where can I get ai4j?
- The source code and installation instructions are on GitHub: https://github.com/LnYo-Cly/ai4j
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A Python library and CLI that lets any supported LLM (OpenAI, Anthropic, Ollama, LMStudio) call tools on one or more MCP servers via natural language.
An open-source agent harness in TypeScript for building stateful LLM agents, with a built-in coding agent, CLI, Web UI, and SDKs.
A free, open-source Chinese-language book on AI Agent design principles and engineering practice, with 109 companion experiments and downloadable PDF/EPUB.
A Java framework for building agentic, workflow and multi-agent AI applications on top of Spring AI.
Self-hosted Java/Spring Boot AI assistant platform with multi-user workspaces, multi-provider model failover, an LLM Wiki, MCP and Skills, and IM channel integrations.