# Agents-Flex

> Modular Java framework for LLM calls, tool calling, durable agents, RAG, MCP and Text2SQL

- Category: Agents & Automation / Agent Frameworks & Builders
- Language: Java
- Licence: Apache-2.0
- Repository: https://github.com/agents-flex/agents-flex
- Website: https://agentsflex.com
- Canonical page: https://ai-tldr.dev/tools/agents-flex/
- Updated: 2026-10-28

## In short

Agents-Flex is Modular Java framework for LLM calls, tool calling, durable agents, RAG, MCP and Text2SQL. Most modules run on JDK 8 or later, in plain Java, Spring Boot or other JVM stacks; the MCP module needs JDK 17. 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.

## Overview

Agents-Flex is a lightweight AI application framework for the Java ecosystem, which the project positions as a counterpart to Spring AI. It organises LLM calls, tool calling, agents, RAG, vector stores, embeddings, image generation, audio, MCP, Skills, Text2SQL and related capabilities into separate Maven modules, so an application depends only on the pieces it uses and is not tied to a particular runtime or application framework. Most modules run on JDK 8 or later, in plain Java, Spring Boot or other JVM stacks; the MCP module needs JDK 17.

Provider differences sit behind unified interfaces — ChatModel, EmbeddingModel, ImageModel, RerankModel — with the same Prompt, options, interceptor and context mechanisms for blocking and streaming calls. Chat integrations cover OpenAI-compatible APIs, Qwen, Ollama, DeepSeek and LiteLLM, and the store module covers Redis, Qdrant, Chroma, Pgvector, MariaDB, Milvus, OpenSearch, Elasticsearch and others. Business methods become tools through @ToolDef/@ToolParam annotations or Tool.builder(), and ToolGroup attaches a set of tools only when the latest user message matches.

For agents, AgentRunner advances a turn with tool calls, approval, suspension, resumption and persistence, backed by snapshot recovery and JDBC or Redis stores; subagents, file-system Skills with progressive disclosure, an MCP client (stdio, http-sse and http-stream) and an LLM Wiki tool that lets an agent browse a hierarchical knowledge tree build on the same abstractions. Production concerns — model routing, retry, load balancing, circuit breaking, OpenTelemetry observability and read-only SQL checks for Text2SQL — are built in. The project is Apache-2.0 licensed; v2.3.2 was released on October 28, 2026.

## What it does

- Unified ChatModel / EmbeddingModel / ImageModel / RerankModel abstractions with matching sync and streaming APIs
- Annotation-based or programmatic tool calling, with ToolGroup to attach tools only when a prompt matches
- Durable Agent runtime: snapshot recovery, tool approval, suspend/resume, middleware, event streams and JDBC/Redis persistence
- RAG building blocks: document extraction, splitting, embeddings, ten-plus vector stores, retrieval and rerank
- MCP client, file-system Skills with sandboxed execution, subagents, web search, Text2SQL and an LLM Wiki tool
- Model routing, retry, load balancing, circuit breaking and OpenTelemetry observability; Spring Boot starter

## Getting started

Agents-Flex is published to Maven under the com.agentsflex group. Most modules need JDK 8+, agents-flex-mcp needs JDK 17+.

1. Add the dependency

   Use the aggregate BOM for plain Java, the starter for Spring Boot, or depend on single modules such as agents-flex-chat-openai and agents-flex-store-redis.

```text
<dependency>
    <groupId>com.agentsflex</groupId>
    <artifactId>agents-flex-bom</artifactId>
    <version>2.3.2</version>
</dependency>
```

2. Call a model

   This uses an OpenAI-compatible API; replace endpoint, model and apiKey with your own provider's values.

```text
ChatModel chatModel = OpenAIChatConfig.builder()
    .endpoint("https://ai.gitee.com")
    .provider("GiteeAI")
    .model("Qwen3-32B")
    .apiKey(System.getenv("GITEE_API_KEY"))
    .buildModel();

String reply = chatModel.chat("Introduce Agents-Flex in one sentence.");
System.out.println(reply);
```

3. Expose a method as a tool

   Annotate a business method, register the class on a prompt, and run the tool calls the model asks for before asking again.

```text
public class WeatherTools {
    @ToolDef(name = "get_weather", description = "Query the weather for a given city")
    public static String getWeather(
        @ToolParam(name = "city", description = "City name", required = true) String city
    ) {
        return city + ": sunny";
    }
}

SimplePrompt prompt = new SimplePrompt("What is the weather in Beijing today?");
prompt.addToolsFromClass(WeatherTools.class);

AiMessageResponse response = chatModel.chat(prompt);
if (response.hasToolCalls()) {
    prompt.setToolMessages(response.executeToolCallsAndGetToolMessages());
    System.out.println(chatModel.chat(prompt).getMessage().getContent());
}
```

4. Stream the answer

   The same model streams through a listener.

```text
chatModel.chatStream("Explain the Chain of Responsibility pattern in Java.", new StreamResponseListener() {
    @Override
    public void onMessage(StreamContext context, AiMessageResponse response) {
        System.out.print(response.getMessage().getContent());
    }
});
```

## When to use it

- Add LLM chat, tool calling and agents to an existing Java 8+ or Spring Boot service without changing frameworks
- Build an enterprise knowledge base or customer-service bot on a vector store you already run
- Run long agent tasks that must pause for human approval and resume from a snapshot
- Offer natural-language data analysis over a database with read-only SQL checks

## Version history

- 2026-10-28 v2.3.2: Adds prompt-cache token tracking, OpenTelemetry agent-event spans and metrics aligned with the GenAI conventions, a SoMark OCR document-parsing adapter, and Serply and you.com web-search providers.
