番外篇一:《Spring AI Alibaba 到底是啥?一张图理清两者关系》

这是专栏的番外篇。前面 16 篇我们把 Spring AI 从写诗一路写到了 RAG 知识库;从本篇起,开启一段番外------聊聊站在 Spring AI 肩膀上的 Spring AI Alibaba。先别急着学新 API,咱们把"Spring AI"和"Spring AI Alibaba"这对容易搞混的概念,彻底掰扯清楚。

一、懵圈现场

先说个我自己的真实状态。

前不久我也把 Spring AI 啃完了:第 1 篇让 AI 写了首诗,第 5 篇用 @Tool 让 AI 自己查天气,第 8 篇接了 GitHub 的 MCP Server,第 12~16 篇一路把 RAG 知识库从 Embedding 写到查询改写。

然后我信心满满点开 Spring AI Alibaba 的官方文档,迎面就是:

  • ReactAgent
  • Graph 工作流
  • 多智能体编排(Sequential / Parallel / Routing / Loop)
  • 人机协同(HITL)
  • A2A 跨服务通信

我当场就懵了:这堆东西跟我刚学的 Spring AI 到底啥关系?是不是又得从零学一遍?

二、一句话定调

Spring AI Alibaba 不是"另一个 Spring AI",而是站在 Spring AI 肩膀上的"智能体编排层"。

打个大家一定秒懂的后端老鸟比方:

  • Spring AI ≈ JDBC 。它定义了一套统一的标准接口:ChatClientMessageToolVectorStore......不管底下是 OpenAI 还是通义千问,写的代码长一个样。前 16 篇折腾的全是这一层。
  • Spring AI Alibaba ≈ 在 JDBC 之上长出来的"业务编排框架" 。它不重新发明模型 / 工具 / 向量库(那些还是 Spring AI 的原子能力),而是给你更高级的"拼装件":Agent(会自己思考调工具)、Graph(把多个步骤编排成有向图)、多智能体(多个 Agent 协作)

所以结论先拍这儿:前面学的 Spring AI,100% 不会白学,全部复用。 Alibaba 只是在它上面又叠了一层。

三、官方眼里的三层架构

官方文档地址:java2ai.com/docs/overvi...

翻开 java2ai.com 的概览,人家自己就把项目拆成了三层(从上到下):

复制代码
┌─────────────────────────────────────────────┐
│  Agent Framework 层                          │
│  ReactAgent / 多智能体 / 上下文工程 / 人机协同 │
├─────────────────────────────────────────────┤
│  Graph 层(运行时基座)                       │
│  有向图编排:条件路由 / 并行 / 嵌套 / 状态管理 │
├─────────────────────────────────────────────┤
│  Augmented LLM 层 = Spring AI 原子抽象        │
│  Model / Tool / MCP / Message / VectorStore   │
└─────────────────────────────────────────────┘

这时候大家也看明白了?

  • 最底下那层,就是已经掌握的 Spring AI。 模型、工具、MCP、消息、向量库,一个没多。
  • 中间 Graph 层,是 Alibaba 自己写的"图运行时"。 它才是 ReactAgent 真正跑的地方。
  • 最上面 Agent Framework 层,是把下面两层包起来的"易用壳"。 ReactAgent.builder() 几行代码,框架帮你把上下文工程、工具调度、多轮推理全管了。

四、直接上手体验

光说概念虚,我直接把正在写的 demo 工程 yunxi-spring-ai-alibaba 的依赖贴出来:

xml 复制代码
    <dependencies>
        <dependency>
            <groupId>com.alibaba.cloud.ai</groupId>
            <artifactId>spring-ai-alibaba-agent-framework</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud.ai</groupId>
            <artifactId>spring-ai-alibaba-starter-dashscope</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.alibaba.cloud.ai</groupId>
                <artifactId>spring-ai-alibaba-bom</artifactId>
                <version>1.1.2.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.ai</groupId>
                <artifactId>spring-ai-bom</artifactId>
                <version>1.1.2</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>com.alibaba.cloud.ai</groupId>
                <artifactId>spring-ai-alibaba-extensions-bom</artifactId>
                <version>1.1.2.1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

看见没?starter-dashscope 就是通义千问的接入包,它产出的就是标准 ChatModel------也就是Spring AI 第 1 篇里那个 ChatModel

再看我是怎么造 Agent 的:

scss 复制代码
@Bean
public ReactAgent reactAgent(ChatModel chatModel, WeatherTools weatherTools) {
    return ReactAgent.builder()
            .name("demo-react-agent")
            .model(chatModel)            // ← 直接喂认识的 ChatModel
            .instruction("你是一个智能助手......")
            .methodTools(weatherTools)   // ← 第5篇的 @Tool 直接挂上
            .enableLogging(true)
            .build();
}

ChatModel 是旧的, @Tool 是旧的,只有 ReactAgent 是新的。 这就是"复用"二字最直白的证明。

六、番外篇怎么排

番外篇我也不知道该怎么写,只能抽时间慢慢写吧,我打算这么排:

  1. 番外一(本篇):Spring AI vs Alibaba 关系定位
  2. 番外二:ReactAgent 十分钟上手
  3. 番外三:扒开 ReactAgent 的 Graph 内核
  4. 番外四:StateGraph 并行 / 分支 / 状态编排实战
  5. 番外五:HITL------让 Agent 在关键时刻等人工拍板
  6. 番外六:四种多智能体模式(Sequential / Parallel / Routing / Loop)开箱即用
  7. 番外七:用 Nacos 玩转 Agent 间通信(A2A)
  8. 番外八:上生产前的坑------状态持久化、检查点、流式、错误处理
  9. 番外九:综合实战------把 RAG 和 Agent 焊在一起

收尾

回头看开头的懵圈------其实答案特简单:Spring AI 教你"造零件",Spring AI Alibaba 教你"用零件拼出会思考、会协作、能让人把关的智能体"。 你手里的 Spring AI 功夫,一字没废。

下一篇,咱们用十行代码真把 ReactAgent 跑起来。

相关推荐
吴佳浩1 小时前
Function Calling 为什么不够用?深入拆解 MCP 标准协议的设计哲学
agent·ai编程·mcp
吴佳浩2 小时前
从零手写一个生产级 MCP Server:鉴权、流式传输与状态管理
agent·ai编程·mcp
孟健5 小时前
Jev是什么AI模型?不做自然语言生成为何引发热议
ai编程
why-geo8 小时前
Hermes Agent 与 Python 的会产生什么样的碰撞
人工智能·python·ai编程
小虎AI生活10 小时前
从提效到增收,企业级 Agent 的落地路径与实践拆解
ai编程
ServBay10 小时前
ChatGPT Pro 20X 限时回归
gpt·chatgpt·openai
RSABLOCKCHAIN10 小时前
antigravity运行vibecoding一般工作原理
ai编程
wangruofeng10 小时前
9 款主流 AI Agent CLI 对比:安装、版本查询与升级命令
aigc·agent·ai编程
全栈弄潮儿10 小时前
AI 生成的代码,哪些地方最容易埋坑?
aigc·openai·ai编程
MayBaymax11 小时前
Spring AI Alibaba Graph 实战:客服工单智能处理
java·ai·ai编程