2026 年了,Java 做 AI 不再是"能不能"的问题,而是"用哪个"的问题。
Spring AI、LangChain4j 等框架都给出了自己的答案。
这篇文章整理了 7 个主流框架的实际数据、代码示例和选型判断。
| GitHub Stars | ||||||
| 最新版本 | ||||||
| 框架依赖 | ||||||
| Java 版本 | Java 8~26 | |||||
| 模型支持 | ||||||
| RAG | ||||||
| Agent | ||||||
| Skill | ||||||
| 可观测性 |
定位:Spring 官方推出的 AI 框架,把 Spring 的设计哲学(依赖注入、自动配置、POJO 编程)带到 AI 开发中。
GitHub:https://github.com/spring-projects/spring-ai | Stars:8,854 | 最新版本:2.0.0-M8
支持模型:OpenAI、Anthropic、DeepSeek、Google Gemini、Ollama、Amazon Bedrock、Azure OpenAI、阿里通义 等 10+。
支持向量库:PGVector、Chroma、Pinecone、Redis、Milvus、Weaviate、Elasticsearch、MongoDB Atlas、Cassandra、Qdrant、Oracle 等 15+。
Maven 依赖(Spring Boot 3.5.x + Spring AI 1.1.x):
xml <dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-openai-spring-boot-starter</artifactId><version>1.1.7</version></dependency>
application.yml:
yaml spring:ai:openai:api-key:${OPENAI_API_KEY}chat:options:model:gpt-4o
ChatClient 使用:
java @RestControllerclassChatController {privatefinal ChatClient chatClient;publicChatController(ChatClient.Builder builder) {this.chatClient = builder.build(); }@GetMapping("/chat") String chat(@RequestParam String message) {return chatClient.prompt() .user(message) .call() .content(); }}
带 RAG 的 ChatClient:
java @RestControllerclassRagController {privatefinal ChatClient chatClient;publicRagController(ChatClient.Builder builder, VectorStore vectorStore) {this.chatClient = builder .defaultAdvisors(newVectorStoreChatMemoryAdvisor(vectorStore),newQuestionAnswerAdvisor(vectorStore, SearchRequest.defaults()) ) .build(); }@GetMapping("/rag") String chat(@RequestParam String message) {return chatClient.prompt() .user(message) .call() .content(); }}
无原生 Skill 抽象。 Spring AI 不支持通用的 Skill/SKILL.md 机制。其等价能力仅通过 Tool Calling 实现:
@Tool 注解FunctionToolCallbackToolContext
// 注册一个工具@Tool(description = "查询天气")String getWeather(String city) { ... }// 通过 ChatClient 调用chatClient.prompt() .tools(getWeather) .user("北京天气?") .call();
但 Tool 不具备渐进式披露能力(元信息列表→按需加载),也没有标准化的 SKILL.md 目录结构。需要 Skill 机制时需配合 LangChain4j 或 Spring AI Alibaba 使用。
Agent 能力相对基础。Spring AI 的 Agent 模式基于 Advisors 链:
缺乏 LangChain4j 或 Spring AI Alibaba 那样的声明式 Agent 接口和自循环推理机制。
定位:社区最活跃的 Java AI 框架,没有之一。框架中立,不绑 Spring,Quarkus、Micronaut、Helidon、纯 Java 都能用。
GitHub:https://github.com/langchain4j/langchain4j | Stars:12,196 | 最新版本:1.15.1
langchain4j-agentic 模块,支持 Workflow 和 Pure AgentMaven 依赖:
xml <dependency><groupId>dev.langchain4j</groupId><artifactId>langchain4j</artifactId><version>1.15.1</version></dependency><dependency><groupId>dev.langchain4j</groupId><artifactId>langchain4j-open-ai</artifactId><version>1.15.1</version></dependency>
基础对话:
java ChatLanguageModelmodel= OpenAiChatModel.builder() .apiKey(System.getenv("OPENAI_API_KEY")) .modelName("gpt-4o") .build();Stringanswer= model.generate("Java 8 和 Java 17 有什么区别?");
AI Service 声明式编程(核心特色):
java interfaceCustomerSupportAgent {@SystemMessage("你是一个客服助手") String chat(@UserMessage String userMessage);}CustomerSupportAgentagent= AiServices.create(CustomerSupportAgent.class, model);Stringresponse= agent.chat("这款产品的退款政策是什么?");
LangChain4j 通过 langchain4j-agentic 模块提供原生 Skill 支持,遵循 Agent Skills 规范(SKILL.md 格式)。
Skill 目录结构:
skill-name/├── SKILL.md # 必需:YAML frontmatter(name + description)+ 指令正文├── references/ # 可选:参考文档├── examples/ # 可选:示例└── scripts/ # 可选:脚本
SKILL.md 格式:
markdown ---name: docxdescription: Edit and review Word documents using tracked changes---# Word Document EditorInstructions for editing Word documents...
两种使用模式:
模式一:Tool Mode(推荐)
Skill 目录通过 FileSystemSkillLoader 加载为 Tool,直接注入 AI Service。
java Skillsskills= FileSystemSkillLoader.loadSkills(Path.of("skills/"));MyAiServiceservice= AiServices.builder(MyAiService.class) .chatModel(chatModel) .tools(skills) // 所有 Skill 自动注册为 Tool .build();
模式二:Shell Mode(实验性)
通过 ShellSkills 将 Skill 的执行交给 Shell 命令。适合快速原型和第三方技能(如 agentskills.io 生态)。
java ShellSkillsskills= ShellSkills.from( FileSystemSkillLoader.loadSkills(Path.of("skills/")));MyAiServiceservice= AiServices.builder(MyAiService.class) .chatModel(chatModel) .toolProvider(skills.toolProvider()) .systemMessage("You have access to the following skills:\n" + skills.formatAvailableSkills() + "\nWhen the user's request relates to one of these skills, read its SKILL.md before proceeding.") .build();
formatAvailableSkills() 的输出包含 <location> 字段,LLM 可据此定位 SKILL.md 文件路径。
工作方式:
langchain4j-agentic 模块提供两种模式:
Workflow 模式: 预定义编排流程(顺序、并行、条件路由、循环)Pure Agent 模式: 模型自主决策,动态选择工具
java @AgentinterfaceCustomerSupportAgent { String chat(@UserMessage String userMessage);}
MCP 集成:langchain4j-agentic-mcp 模块支持 MCP 工具作为 Agent 节点。
⚠️ 说明:Spring AI Alibaba 是阿里推出的 独立项目(
alibaba/spring-ai-alibaba),与 Spring Cloud Alibaba 无关。后者是微服务中间件。
定位:阿里出的独立项目,专攻多智能体系统和工作流编排。深度集成 Spring AI 生态,核心跑在 Graph Runtime 上。
GitHub:https://github.com/alibaba/spring-ai-alibaba | Stars:9,871 | 版本:1.1.2.0
官方文档:https://java2ai.com/docs/overview
Maven 依赖:
xml <dependency><groupId>com.alibaba.cloud.ai</groupId><artifactId>spring-ai-alibaba-agent-framework</artifactId><version>1.1.2.0</version></dependency><dependency><groupId>com.alibaba.cloud.ai</groupId><artifactId>spring-ai-alibaba-starter-dashscope</artifactId><version>1.1.2.1</version></dependency>
构建 ReactAgent:
java DashScopeApidashScopeApi= DashScopeApi.builder() .apiKey(System.getenv("AI_DASHSCOPE_API_KEY")) .build();ChatModelchatModel= DashScopeChatModel.builder() .dashScopeApi(dashScopeApi) .build();// 定义工具ToolCallbackweatherTool= FunctionToolCallback.builder("get_weather", newWeatherTool()) .description("Get weather for a given city") .inputType(String.class) .build();// 创建 ReactAgentReactAgentagent= ReactAgent.builder() .name("weather_agent") .model(chatModel) .tools(weatherTool) .build();Stringresult= agent.run("北京的天气怎么样?");
Spring AI Alibaba 通过 SkillRegistry + SkillsAgentHook 提供原生 Skill 支持,同样遵循 Agent Skills 规范。
核心组件:
SkillRegistrySkillsAgentHookread_skill 工具和技能列表到 System PromptFileSystemSkillRegistrySkill 目录结构(与 LangChain4j 完全一致):
skills/├── pdf-extractor/│ ├── SKILL.md # YAML frontmatter(name + description)+ 指令│ ├── references/ # 可选│ └── scripts/ # 可选├── code-reviewer/│ └── SKILL.md
SKILL.md 格式(完全一致):
markdown ---name: pdf-extractordescription: Extract structured data from PDF documents---# PDF ExtractorInstructions for extracting data from PDF files...
在 Agent 中使用:
java SkillRegistryregistry= FileSystemSkillRegistry.builder() .projectSkillsDirectory(System.getProperty("user.dir") + "/skills") .build();SkillsAgentHookhook= SkillsAgentHook.builder() .skillRegistry(registry) .build();ReactAgentagent= ReactAgent.builder() .name("skills-agent") .model(chatModel) .saver(newMemorySaver()) .hooks(List.of(hook)) .build();agent.call("请介绍你有哪些技能");
工作方式:
read_skill(skill_name) 加载完整 SKILL.md单 Agent(ReactAgent): ReAct 范式,思考→行动→观察循环多 Agent 工作流:
SequentialAgentParallelAgentLlmRoutingAgentLoopAgent高级编排(Graph Core): DAG 工作流 + 条件路由 + 状态管理 + PlantUML/Mermaid 可视化
A2A(Agent-to-Agent): 通过 Nacos 实现分布式 Agent 间通信
定位:全场景轻量级 Java AI 框架。无需框架容器,纯 JDK 即可运行,支持 Java 8 到 Java 26。
GitHub:https://github.com/opensolon/solon | Stars:2,745 | AI 版本:v3.9.0+(v3.10.7)
AI 模块体系:
solon-aisolon-ai-skillssolon-ai-ragsolon-ai-flowsolon-ai-agentsolon-ai-harnesssolon-ai-mcp
xml <dependency><groupId>org.noear</groupId><artifactId>solon-ai</artifactId><version>3.10.7</version></dependency>
java @ControllerpublicclassAIController {@Injectprivate ChatClient chatClient;@Mapping("/chat")public String chat(String msg) {return chatClient.prompt(msg).call().content(); }}
Solon AI Skills 是其独立模块 solon-ai-skills(v3.9.0+),概念原型参考了 Claude Code Agent Skills 的设计思想。
核心特色:
Skill 类型体系:
| CliSkill | |
| RestApiSkill | |
| ToolGatewaySkill | |
| Text2SqlSkill | |
| Remote Skill |
Tool 与 Skill 的区别:Tool 是功能型(执行原子操作),Skill 是知识型(包含指令/SOP/上下文)。Skill 可以包含多个 Tool 调用和决策逻辑。
Solon AI Agent 模块 solon-ai-agent 提供三种 Agent 类型:
另有 solon-ai-harness Harness 马具框架,提供智能体脚手架能力。solon-ai-flow 提供 AI 工作流编排(类似 Spring AI Alibaba 的 Graph Core)。
定位:面向企业的 Java AI 应用开发框架,强调私有化部署、全链路可追溯、AgentRAG。
网站:https://jboltai.com
无原生 Skill 抽象。 但提供平台级替代方案:
Agent 方面,AgentRAG 框架实现完整的推理链路,过程透明可追溯。
定位:面向生产环境的智能体运行平台,阿里通义实验室出品。提供 ReAct 推理、Harness 工程化基础设施、多智能体编排与 MCP/A2A 协议支持。
GitHub:https://github.com/agentscope-ai/agentscope-java | Stars:3,457
AgentScope-Java 通过 SkillRepository 提供原生 Skill 支持,同样遵循 Agent Skills 规范。
两大来源:
workspace/skills/ 共享 / <userId>/skills/ 按用户隔离Skill 目录结构(完全一致):
code-reviewer/├── SKILL.md # YAML frontmatter(name + description)+ 指令正文├── references/ # 参考文档,agent 按需读取│ └── style-guide.md└── scripts/ # agent 可通过 shell 调用的脚本 └── run-checks.sh
SKILL.md 格式(完全一致):
markdown ---name: code-reviewerdescription: 当用户需要代码评审、风格反馈或 PR 审核时使用。---# Code Reviewer步骤:1. 读 `references/style-guide.md` 获取项目规范2. 跑 `scripts/run-checks.sh <目标路径>`
多后端支持:
java // Git 技能仓库HarnessAgentagent= HarnessAgent.builder() .name("assistant") .model(model) .workspace(workspace) .skillRepository(newGitSkillRepository("https://github.com/your-org/team-skills.git")) .build();// Nacos 技能市场NacosSkillRepositorymarket=newNacosSkillRepository(aiService, "namespace");HarnessAgent.builder() .skillRepository(market) .build();// MySQL 技能注册表MysqlSkillRepositoryregistry= MysqlSkillRepository.builder(dataSource) .databaseName("agentscope") .skillsTableName("skills") .createIfNotExist(true) .writeable(true) .build();
自学习闭环:
workspace/skills/HarnessAgent: Middleware + Toolkit 两个扩展通道,把工作区、记忆、沙箱、子 Agent、技能与计划模式打包。
子智能体: 在 Markdown 里声明子 agent 规格,运行时按需 agent_spawn / agent_send,支持同步阻塞与后台委派。后台任务终态通过 system-reminder 反向推送。
多 Agent 协作: 支持 Pipeline、Broadcast、Sequential 等协作模式。
A2A + MCP: 跨进程 Agent 编排与工具集成。
当只需要简单调用某个模型 API 时使用。无 Skill/Agent 抽象。
Skill(技能)定义为:遵循 Agent Skills 规范的可复用能力包——一个包含
SKILL.md(YAML frontmatter + 指令)的目录,支持渐进式披露(先列元信息,按需加载详情)。
| Solon AI | 20个预置技能、CliSkill/RestApiSkill/ToolGatewaySkill/Text2SqlSkill、分布式、多态、优先级 | ||||
| LangChain4j | |||||
| Spring AI Alibaba | |||||
| AgentScope-Java | |||||
| Spring AI | |||||
| JBoltAI | |||||
| 官方 SDK |
四个框架(LangChain4j、Spring AI Alibaba、AgentScope-Java、Solon AI)均实现了原生 Skill 支持,差异在于规范遵循和接入方式:
| 遵循规范 | ||||
| 注册方式 | ||||
| 加载方式 | ||||
| 与 Agent 结合 | ||||
| Skill 类型 | ||||
| 预置技能 | ||||
| 生态兼容 | ||||
| 同一切换不同后端 |
| Spring AI | |||||
| LangChain4j | |||||
| Spring AI Alibaba | |||||
| Solon AI | |||||
| JBoltAI | |||||
| AgentScope-Java | |||||
| 官方 SDK |
Spring Boot 重度用户 → Spring AI
只做基础对话/RAG 的话,Spring AI 上手最快。需要 Skill 和 Agent 就在它上面叠 Spring AI Alibaba 或 LangChain4j。
需要 Skill + Agent 全栈 → LangChain4j 或 Solon AI
两个都是功能很全的选择。LangChain4j 框架中立,社区大(12k+ Stars)。Solon AI 轻量,Java 8~26 都兼容。看技术栈偏好:Spring 生态选前者,纯 Java 或非 Spring 选后者。
需要多 Agent 编排 + Skill + Spring 生态 → Spring AI Alibaba
团队在用 Spring Boot 的话,这是最自然的选择。兼容 Spring AI,自带 Graph 工作流,不用额外搭编排层。
需要企业级生产部署 + Skill 系统 → AgentScope-Java
沙箱执行、快照恢复、多后端 Skill 市场、自学习闭环、多租户隔离——Harness 的工程化能力确实是其他框架没做的。Skill 支持 Git/Nacos/MySQL 三种后端。
非 Spring 技术栈 / 极致轻量 → Solon AI
纯 JDK 就能跑,Java 8~26 兼容,IoT 和边缘计算场景下比 Spring 系实在太多。
企业私有化部署 → JBoltAI / AgentScope-Java
JBoltAI 有可视化编排和审计日志,AgentScope-Java 有沙箱执行和 Harness 工程化。看你是要"好用"还是要"可靠"。
Spring Boot 项目想要全套能力:
Spring AI(基础 Chat/RAG + 可观测性) + Spring AI Alibaba(Agent 编排 + Skill 支持)
非 Spring 项目想要轻量全栈:
Solon AI(全模块:Chat + Agent + Skill + Flow + Harness)
LangChain4j 和 Spring AI Alibaba 有功能重叠,选一个就行。AgentScope-Java 的 Skill Repository 和沙箱执行可以当补充层加进来。