Java AI框架选型指南 – 苏三说技术 – 博客园

Java AI框架选型指南 – 苏三说技术 – 博客园


Preface

A while ago, a golfer told me that his company encountered a particularly typical problem when conducting a technical review.

They were going to build an intelligent customer service system, and the three people in the team were quarreling.

One said to use Spring AI because “it is officially produced by Spring and must be stable”;

One said to use LangChain4j, the reason is that “the ecology is the most complete and everything can be done”;

Another one said to use AgentScope, and the reason was that it was “verified internally by Alibaba and is production-grade.”

All three people are right, but they are not talking about the same thing.

Because these three frameworks do not solve the same problem at all.

This is the biggest pitfall in Java AI framework selection – you think you are choosing “which one is better”, but in fact you are choosing “which one is more suitable for your scenario”.

When it comes to product selection, what I fear the most is comparing the parameters with the function list, only to find out in the end that I selected the wrong layer.

In today’s article, I will dismantle the mainstream AI framework in the Java ecosystem from beginning to end.

Don’t talk nonsense, just talk about one thing:At which level does each framework stand, what problem does it solve, and when should it be used.

Hope it will be helpful to you.

1. How many layers does the Java AI framework have?

When many people choose, they compare Spring AI, LangChain4j, AgentScope, and Embabel together, which is wrong in itself.

They are not on the same level.

Rod Johnson gave a very sharp analogy when he released Embabel:

Hierarchy analogy Representation frame
underlying infrastructure Servlet API Spring AI / LangChain4j
Advanced Application Framework Spring MVC Embable

What’s the meaning?

Spring AI and LangChain4j solve pipeline problems such as “how to connect to LLM, how to manage Embedding, and how to connect to the vector library”.

Embabel solves orchestration problems such as “how to enable intelligent agents to complete multi-step tasks reliably, explainably, and deterministically in complex business processes.”

The two are complementary, not competitive.

Further up, AgentScope solves the problem of “how to make Agent run stably for a long time in an enterprise-level distributed environment.”

Solon AI solves the problem of “how to embed AI capabilities in any framework within the full range of Java 8 to Java 26.”

To put it clearly in one sentence: the first step in selection is not “which frame to choose”, but “figure out which layer of frame you need.”

2. Understand the hierarchical positioning of the Java AI framework with one picture

Java AI框架选型指南 – 苏三说技术 – 博客园

This picture is the skeleton of the entire article.

Below I break it down layer by layer.

3. The first layer: underlying infrastructure

The core problems solved by this layer are:How to integrate basic capabilities such as large models, vector databases, Embedding, and tool calls into your project using Java.

3.1 Spring AI 2.0: Spring official answer

Spring AI 2.0.0 GA was officially released on June 12, 2026, and is built on Spring Boot 4.1 and Spring Framework 7.0.

What’s its biggest change?

In Spring AI 1.x, the boundary between ChatClient and ChatModel is very blurred. Many people use @Autowired ChatModel directly, and tool calls, retries, and memory management are all included.

2.0 has clarified this boundary: ChatClient is a high-level API for users, with a built-in Advisor chain, which is used for daily business development; ChatModel is a bottom-level model abstraction, directly connected to the SDKs of various manufacturers, and only framework developers need to touch it.

More importantly,Refactoring of tool calls。

In 1.x, each ChatModel implementation has its own private tool execution loop embedded – OpenAI has one, Ollama has one, and Anthropic has one, with different code duplication, inconsistent behavior, and bugs.

2.0 eliminates all of these, and the tool execution loop is promoted to the Advisor chain for unified processing.

// Spring AI 2.0的工具调用写法
String response = ChatClient.create(chatModel)
    .prompt("明天是星期几?")
    .tools(new DateTimeTools())
    .call()
    .content();

Clean and concise, tool calls and execution loops are all handled automatically.

The most elegant thing about this design is:Loops are composable。

The Advisor chain supports loop re-entry – the tool can re-enter the downstream chain by calling the Advisor. The same mechanism can also be used to do retry loops, evaluation loops, etc. for structured output.

When to use Spring AI? If your project is Spring Boot 4.x and the team is familiar with the Spring ecosystem and needs to quickly integrate AI capabilities into the existing system – Spring AI is the smoothest choice.

Its automatic configuration, dependency injection, and observability are all Spring’s.

The only price is that the Java version needs to be upgraded to 17+ (2.0 requires 21+).

3.2 LangChain4j: AI toolbox on JVM

LangChain4j has been developed since early 2023 and is currently the framework with the richest model support and vector storage support in the Java ecosystem.

As of September 2026, the latest version is 1.19.0.

What is the core difference between it and Spring AI?

In one sentence:Spring AI pursues “integration efficiency”, while LangChain4j pursues “scenario capabilities” 。

Spring AI excels in its native integration with the Spring ecosystem, including declarative @AiService, automatic configuration, and Spring Boot Starter.

LangChain4j excels in its feature richness and flexibility – it supports 30+ models out of the box and has the widest vector library coverage.

Its Agent mechanism is more mature and handles multi-step logic more stably.

// LangChain4j的声明式AI服务
interface Assistant {
    @SystemMessage("你是一个Java技术顾问,请用中文回答")
    String chat(@UserMessage String question);
}

Assistant assistant = AiServices.create(Assistant.class, model);
String answer = assistant.chat("什么是虚拟线程?");

When to use LangChain4j?

If you need the richest model and vector storage support, or your project is not pure Spring (perhaps using Quarkus, Micronaut or pure Java), LangChain4j is the most flexible choice.

But you have to endure its less concise writing style and the relatively high cost of learning and using it.

An important change in LangChain4j 1.19 is that the MCP protocol enters a stable period。

On July 28, 2026, MCP released a new specification. Streamable HTTP became stateless, the protocol-level session was deleted, and the server no longer relies on session ID to remember who is who.

This means that the integration method of MCP will be more standardized.

3.3 Solon AI: Compatible with all scenarios and all versions

Solon AI is one of the core sub-projects of the Solon project, and its positioning isFull-scenario Java AI development framework。

Its biggest features are two:

First, it is compatible with Java 8 to Java 26.

This is very rare in Java AI frameworks – Spring AI 2.0 requires Java 21+, and LangChain4j requires Java 17+.

Second, any framework can be embedded.

It is not bound to Solon and can be seamlessly embedded into Spring Boot, Vert.x, Quarkus, and JFinal.

// Solon AI的构建式API
ChatModel chatModel = ChatModel.of("
    .provider("ollama")
    .model("qwen2.5:1.5b")
    .build();

AssistantMessage result = chatModel.prompt("杭州今天天气怎么样?")
    .options(op -> op.toolAdd(new WeatherTools()))
    .call()
    .getMessage();

When to use Solon AI?

If your project still runs on Java 8, or you need a “framework-agnostic” AI capability layer – Solon AI is currently the only option.

In terms of the Agent system, it provides a three-level progressive agent architecture: SimpleAgent, ReActAgent, and TeamAgent.

4. Second layer: Agent orchestration

The core problems solved by this layer are:When AI requires multi-step reasoning, tool invocation, and multi-Agent collaboration, how to make the process controllable, explainable, and recoverable.

4.1 Spring AI Alibaba: Enterprise-level multi-agent and workflow orchestration

Spring AI Alibaba is jointly maintained by the Spring open source community and the Alibaba open source community. It will be open sourced in September 2024. Currently, the number of GitHub stars has exceeded10,000。

The project is built on Spring AI and is the best practice of Alibaba Cloud Tongyi series models and services in the field of Java AI application development.

What is its core positioning?

Spring AI Alibaba made based on Spring AIUpward abstraction and functional enhancement。

Spring AI provides basic abstractions for AI applications – model access, function calls, MCP, conversation memory, RAG, and observability.

Spring AI Alibaba adds on this basisAgent orchestration, Graph workflow engine, MCP dual-end support and enterprise-level governance。

Explain the difference in one sentence:Spring AI solves “how to call the model”, and Spring AI Alibaba solves “how to let multiple agents collaborate to complete complex business processes.”

Its architecture is divided into three layers:

  • Agent FrameworkWith ReactAgent as the core, it provides an Agent development framework;
  • GraphIt is a low-level workflow and multi-agent coordination framework, and is the underlying runtime base of Agent Framework;
  • Augmented LLMBased on Spring AI’s atomic abstraction, it provides basic capabilities such as models, tools, MCP, and vector storage.
// Spring AI Alibaba创建Agent
DashScopeApi dashScopeApi = DashScopeApi.builder()
    .apiKey(System.getenv("AI_DASHSCOPE_API_KEY"))
    .build();
ChatModel chatModel = DashScopeChatModel.builder()
    .dashScopeApi(dashScopeApi)
    .build();

ReactAgent agent = ReactAgent.builder()
    .name("weather_agent")
    .model(chatModel)
    .instruction("You are a helpful weather forecast assistant.")
    .build();

agent.call("what is the weather in Hangzhou?");

Spring AI Alibaba 1.1.2.0 version brings two key capability upgrades:

Agent Skills——ReactAgent integrates the Agent Skills capability and supports the progressive disclosure of reusable instructions and context in units of “skills”. In the system prompt, only the skill list is first injected, and the model only loads the complete content when a certain skill is needed, so thatReduce Token consumption and expand capacity scale。

Multi-agent parallel execution——LlmRouting, Supervisor and other modes can either route to a single sub-agent or select multiple sub-agents at once.Parallel executionwhich facilitates parallel query and result summary in multiple fields.

When to use Spring AI Alibaba?

If your project is Spring Boot, you need to buildEnterprise-level multi-agent systemsorWorkflow orchestration——For example, intelligent customer service, approval flow, and data pipelines——Spring AI Alibaba is currently the most complete choice.

It has both the integration advantages of the Spring ecosystem and the deep adaptation of Alibaba Cloud infrastructure (Tongyi Qianwen, Bailian, Higress AI Gateway, Nacos, etc.).

4.2 AgentScope Java 2.0: Enterprise-level distributed Agent base

AgentScope Java 2.0 will be officially released in June 2026. It is the most widely used agent framework (Java & Python) within Alibaba Group and is deeply used in the production environment of more than ten core business lines.

What is its core idea?

Based on the ReActAgent reasoning kernel, add aHarness engineered layer。

Developers can continue to use the lightweight ReAct loop, or enable Workspace, persistent memory, Session, Sandbox, Skill, Subagent and other capabilities as needed to deploy the same set of Agent logic to enterprise-level distributed services.

// AgentScope HarnessAgent
var agent = HarnessAgent.builder()
    .name("coder")
    .model("dashscope:qwen-max")
    .workspace(Paths.get(".agentscope/workspace"))
    .filesystem(new DockerFilesystemSpec())
    .isolationScope(IsolationScope.USER)
    .build();

agent.call(msg, RuntimeContext.builder()
    .sessionId("demo")
    .userId("alice")
    .build()).block();

What is AgentScope’s core differentiating capability?

Three words:Persistent identity, controllable context, and recoverable status。

The workspace is the Agent’s personality and long-term memory, which are automatically injected in each round;

The context is automatically compressed, the results of large tools are automatically placed on the disk, and ContextOverflow tries again;

The complete conversation can be restored across processes with the same sessionId, and the sandbox state can be snapshotted.

When to use AgentScope?

If you want to build an enterprise-level multi-Agent system that requires long-term stable operation, multi-tenant isolation, and tool call permission control – AgentScope is currently the most complete choice in the Java ecosystem.

4.3 Embabel: Take “planning” back from LLM

Embabel is a JVM native agent framework created by Rod Johnson, the father of Spring. The 1.0.0 GA version will be released in August 2026.

What is the core problem it solves?

In Rod Johnson’s own words:“Since I founded Spring, I’ve never been so convinced that a new project is necessary.”

The core design of Embabel is to introduceGOAP (Goal-Oriented Action Planning) goal-oriented planning algorithm—A planning algorithm traditionally used in game AI.

It does not execute according to a script or pre-wired graph, but provides the agent with a set of available Actions, each Action has preconditions and effects, and the planner searches for an action sequence that satisfies the goal.

What is the biggest difference between this and other frameworks?

Planning does not rely on LLM.

The planning step of most AI Agent frameworks is to let the LLM decide “what to do next.”

But LLM is illusory and uncertain. Embabel hands over the planning to the deterministic GOAP algorithm – it calculates the optimal path based on the preconditions and effects of the Action and explains why this path was chosen.

Embabel is built on Spring AI and directly leverages Spring AI’s model connection capabilities, so you can continue to use @Tool and ChatClient in the Spring AI ecosystem.

When to use Embabel?

If your scenario requiresExplainable, auditable, deterministic multi-step task orchestration– Such as financial compliance, medical decision-making, supply chain scheduling – Embabel’s GOAP planning is more reliable than other frameworks’ LLM-driven planning.

5. Understand the positioning of all frames with one table

frame Hierarchy core positioning Java version Framework dependencies most suitable
Spring AI infrastructure Spring ecological AI abstraction layer 21+ Strong dependence on Spring Boot Spring Boot project quickly accesses AI
LangChain4j infrastructure AI toolbox on JVM 17+ frame neutral Need rich model/vector library support
Solon AI infrastructure Full-scenario AI development framework 8-26 Can be embedded into any framework Java 8 projects, framework-independent scenarios
Alibaba’s Spring AI Agent orchestration Enterprise-level multi-agent and workflow 17+ Based on Spring AI Multi-Agent collaboration and workflow orchestration
AgentScope Agent orchestration Enterprise-level distributed agent 17+ frame neutral Multi-Agent collaboration, production-level deployment
Embable Agent orchestration Deterministic GOAP orchestration 17+ Based on Spring AI Auditable, deterministic process orchestration

6. Decision-making logic of selection

At this point, you should have discovered:There is no “best framework”, only “the framework that best matches your scene”.

Let me sort it out for you according to common decision-making paths.

6.1 First question: What is the technology stack of your project?

image

6.2 Second question: What does your scene require?

image

6.3 Three key judgments

Judgment 1: What is your Java version?

If you are still on Java 8 or 11, neither Spring AI 2.0 nor LangChain4j can be used.

Solon AI is the only option.

Judgment 2: Is your project monolithic or distributed?

If it is a single application or simple microservice, Spring AI or LangChain4j is enough.

If you want to build an enterprise-level multi-Agent distributed system, the engineering layer of Spring AI Alibaba or AgentScope is a must.

Judgment 3: Does your scenario require “certainty”?

If you need auditing and compliance in finance, medical, government, etc. scenarios, Embabel’s GOAP planning is more reliable than LLM-driven planning——Because every step of its decision-making is traceable and explainable。

7. Advantages and Disadvantages

Spring AI 2.0

advantage:Officially produced by Spring, deeply integrated with Spring Boot 4.x; the advisor chain is elegantly designed, and tool calls can be combined; automatic configuration and perfect observability.

shortcoming: Strongly dependent on Spring Boot 4.x and Java 21+; does not support Java 8/11/17; non-Spring projects are inconvenient to use.

Applicable scenarios: Spring Boot 4.x projects can quickly access AI.

LangChain4j

advantage: 30+ models are available out of the box, with the widest vector library coverage; framework neutral, can be used with any Java framework; MCP protocol support is mature.

shortcoming: The writing method is not concise enough, and the learning cost is high; the version iteration is fast, and the API stability is not as good as Spring AI.

Applicable scenarios: Requires rich model/vector library support, or non-Spring projects.

Solon AI

advantage:The only framework that supports Java 8 to Java 26; Can be embedded in Spring Boot, Vert.x, Quarkus; three-level Agent architecture.

shortcoming: The ecology and community scale are not as good as Spring AI and LangChain4j; the documents are mainly in Chinese.

Applicable scenarios: Java 8/11 projects, or those that require a framework-independent AI capability layer.

Alibaba’s Spring AI

advantage:A complete combination of Spring AI + Alibaba Cloud infrastructure; Agent Framework + Graph workflow engine; Agent Skills support, progressive disclosure reduces token consumption; multi-agent parallel execution; deep adaptation to Tongyi Qianwen, Bailian, Higress AI gateway, Nacos, etc.

shortcoming: Relatively new (open source in September 2024), the ecosystem is still under construction; it is mainly oriented to the Spring ecosystem, and is inconvenient to use for non-Spring projects.

Applicable scenarios: The Spring Boot project builds enterprise-level multi-agent systems and workflow orchestration.

AgentScope

advantage: Production verification for more than ten Alibaba business lines; Harness engineering layer provides Workspace, persistent memory, sandbox isolation, permission control; distributed deployment support.

shortcoming: There are many concepts and the learning curve is steep; it is mainly oriented to enterprise-level scenarios, and simple scenarios may be over-designed.

Applicable scenarios: Enterprise-level multi-Agent distributed system.

Embable

advantage: GOAP deterministic planning does not rely on LLM; it is interpretable and auditable; it is built on Spring AI and can be directly reused.

shortcoming: The core is written in Kotlin (but fully compatible with Java); it is relatively new and the ecosystem is still under construction.

Applicable scenarios: Financial compliance, medical decision-making and other scenarios that require deterministic orchestration.

8. Write at the end

Back to the original question:How to choose a Java AI framework?

My suggestion isthree steps:

Step one: Figure out which floor you’re on.

Do you want to “connect to AI” (infrastructure layer), or “organize AI to work” (Agent orchestration layer)? The answers to the two questions are completely different.

Step 2: Figure out your constraints.

What is the Java version? What is a framework? What is the team familiar with? What are the data compliance requirements? Listing these constraints immediately reduces the range of options by half.

Step 3: Figure out your core scene.

RAG, multi-Agent collaboration, workflow orchestration, deterministic orchestration, simple access – the matching framework for each scenario is different.

The most taboo way to select a model is to compare the function list with the parameters.

“Spring AI has 15 vector libraries and LangChain4j has 30, so LangChain4j is better” – this comparison is meaningless.

You may only use one of the 30 vector libraries, and the extra 15 are just a burden.

The real question to ask is: What capabilities do my projects need most, and which framework is the strongest at this capability?

Selecting a frame is the same as selecting a tool.The right one is the best。

Recommended open source projects:



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *