Repolode
LnYo-Cly

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. 1

    Add the Maven Central dependency to your project

    implementation 'io.github.lnyo-cly:ai4j:2.8.1'
  2. 2

    Set your OpenAI API key as an environment variable

    export OPENAI_API_KEY=your-api-key
  3. 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