编辑
2026-06-01
项目
00

目录

mobile-open-claw:基于 Google ADK 构建移动端 AI Agent 应用的全栈实践
一、项目定位
二、核心架构
2.1 整体分层
2.2 DDD 六模块划分
三、Agent 装配流水线:声明式配置 → 运行时 Agent
3.1 YAML 配置示例
3.2 装配流水线
3.3 责任链节点设计
四、多智能体工作流
4.1 并行执行(Parallel)
4.2 串行执行(Sequential)
4.3 循环执行(Loop)
五、MCP 协议集成
六、REST API 接口
七、技术栈一览
八、快速启动
环境要求
三步运行
Docker 一键部署
九、项目结构
十、致谢
🔗 相关链接

mobile-open-claw:基于 Google ADK 构建移动端 AI Agent 应用的全栈实践

GitHub 仓库lechan775/mobile-open-claw ⚠️ 私有仓库
后端:Spring Boot 3.4.3 + Google ADK 0.5.0 + D Domain-Driven Design
前端:Android Jetpack Compose + Nginx 静态 Web 页面
核心能力:多智能体自动装配 · MCP 协议集成 · 并行/串行/循环工作流 · SSE 流式对话


一、项目定位

mobile-open-claw 是一套移动端 AI Agent 全栈应用,解决的核心问题是:如何在一套工程框架内,以声明式配置(YAML)快速定义、装配和运行多个 AI Agent,并通过统一的 REST API 对外暴露对话能力

它的设计初衷是降低 AI Agent 应用的工程门槛——你只需要写一份 YAML 配置文件,就可以得到一个拥有 MCP 工具调用、多智能体协作能力、且同时支持 Web 和 Android 客户端的完整应用。


二、核心架构

2.1 整体分层

graph TB
    subgraph Clients["客户端层"]
        Web["🌐 Nginx 静态页面<br/>login.html + index.html"]
        Android["📱 Android App<br/>Jetpack Compose + Material3"]
    end

    subgraph Trigger["触发器层 (Trigger)"]
        Controller["AgentServiceController<br/>REST API + SSE Stream"]
    end

    subgraph App["应用编排层 (App)"]
        AutoConfig["AiAgentAutoConfig<br/>启动时自动装配 Agent"]
    end

    subgraph Domain["领域层 (Domain) - 核心"]
        Armory["🔧 ArmoryService<br/>Agent 装配流水线"]
        Chat["💬 ChatService<br/>会话管理与对话调度"]
        MCP["🔌 MCP 协议<br/>Stdio / SSE / Local"]
        Skills["📦 Skills 技能系统"]
        Workflow["⚙️ Agent 工作流<br/>Parallel / Sequential / Loop"]
    end

    subgraph Infra["基础设施层 (Infrastructure)"]
        DAO["MyBatis DAO"]
        Gateway["外部 Gateway"]
        Redis["Redis 缓存"]
    end

    Web --> Controller
    Android --> Controller
    Controller --> Chat
    AutoConfig --> Armory
    Armory --> Workflow
    Armory --> MCP
    Armory --> Skills
    Chat --> Armory
    Domain --> Infra

2.2 DDD 六模块划分

模块职责关键类
api接口契约定义IAgentService, DTOs
app应用启动 & 自动装配Application, AiAgentAutoConfig
domain领域模型 & 核心逻辑ArmoryService, ChatService, Agent 节点树
infrastructure数据访问 & 外部集成DAO, Gateway, Redis
triggerHTTP 控制器 & 事件监听AgentServiceController
types公共枚举/常量/异常ResponseCode, AppException

三、Agent 装配流水线:声明式配置 → 运行时 Agent

这是整个项目最核心的设计——基于责任链模式的 Agent 自动装配引擎

3.1 YAML 配置示例

yaml
ai: agent: config: enabled: true tables: myAgent: app-name: MyAssistant agent: agent-id: 100001 agent-name: 通用助手 agent-desc: 支持百度搜索的通用对话助手 module: ai-api: base-url: https://apis.xxx.cn api-key: sk-xxx completions-path: v1/chat/completions chat-model: model: gpt-4.1 tool-mcp-list: # MCP 工具列表 - sse: name: baidu-search base-uri: http://appbuilder.baidu.com/v2/ai_search/mcp/ sse-endpoint: sse?api_key=xxx - local: name: myToolCallbackProvider # 本地工具 tool-skills-list: # Skills 技能 - type: resource path: agent/skills agents: - name: assistant description: 通用AI助手 instruction: | 你是一个全能的AI助手,可以使用百度搜索获取最新信息。 runner: agent-name: assistant

3.2 装配流水线

应用启动时,AiAgentAutoConfig 监听 ApplicationReadyEvent,触发以下装配流程:

flowchart LR
    Start(["🚀 应用启动"]) --> Config["读取 YAML 配置<br/>AiAgentAutoConfigProperties"]
    Config --> Factory["DefaultArmoryFactory<br/>构建责任链"]
    Factory --> AiApi["AiApiNode<br/>创建 OpenAI API 客户端"]
    AiApi --> ChatModel["ChatModelNode<br/>装配 ChatModel + MCP + Skills"]
    ChatModel --> Agent["AgentNode<br/>逐条注册 LlmAgent"]
    Agent --> Workflow{"存在 AgentWorkflow?"}
    Workflow -->|Parallel| PNode["ParallelAgentNode<br/>并行执行"]
    Workflow -->|Sequential| SNode["SequentialAgentNode<br/>串行执行"]
    Workflow -->|Loop| LNode["LoopAgentNode<br/>循环迭代"]
    Workflow -->|无| Runner["RunnerNode<br/>注册 InMemoryRunner"]
    PNode --> Runner
    SNode --> Runner
    LNode --> Runner
    Runner --> Done(["✅ Agent 就绪"])

3.3 责任链节点设计

java
// 每个 Node 继承 AbstractArmorySupport,实现策略路由 @Service public class ChatModelNode extends AbstractArmorySupport { @Override protected AiAgentRegisterVO doApply(ArmoryCommandEntity param, DynamicContext ctx) { // 1. 构建 Spring AI ChatModel // 2. 注入 MCP 工具回调(Stdio/SSE/Local) // 3. 注入 Skills 技能 // 4. 路由到下一个节点 return router(requestParameter, dynamicContext); } @Override public StrategyHandler<...> get(...) { return agentNode; // 下一站:AgentNode } }

责任链模式来自 xfg-wrench-starter-design-framework(@小傅哥的设计模式框架),每个 Node 只关心自己的装配逻辑,通过 router() 传递到下一节点。


四、多智能体工作流

mobile-open-claw 支持三种 Agent 编排模式,直接封装自 Google ADK:

4.1 并行执行(Parallel)

多个子 Agent 同时运行,互不依赖,适用于多维度信息收集:

yaml
agent-workflows: - type: parallel name: ParallelResearch sub-agents: - RenewableEnergyResearcher # 研究可再生能源 - EVResearcher # 研究电动车技术 - CarbonCaptureResearcher # 研究碳捕获

4.2 串行执行(Sequential)

Agent 按顺序执行,后续 Agent 可引用前置 Agent 的输出(通过 output-key + {} 占位符):

yaml
agent-workflows: - type: sequential name: ResearchAndSynthesis sub-agents: - ParallelResearch # 先并行研究 - SynthesisAgent # 再汇总生成报告

4.3 循环执行(Loop)

子 Agent 迭代执行直到收敛或达到 maxIterations

yaml
agent-workflows: - type: loop name: SelfImprovingWriter max-iterations: 3 sub-agents: - DraftAgent - ReviewAgent

五、MCP 协议集成

支持三种 MCP (Model Context Protocol) 工具接入模式,覆盖本地到远程的全部场景:

模式通信方式实现类适用场景
Stdio标准输入输出进程StdioToolMcpCreateService本地命令行工具
SSEHTTP Server-Sent EventsSSEToolMcpCreateService远程 MCP Server
LocalJVM 直接调用LocalToolMcpCreateServiceSpring Bean 方法
java
// SSE 模式核心实现 HttpClientSseClientTransport transport = HttpClientSseClientTransport .builder(baseUri) .sseEndpoint(sseEndpoint) .build(); McpSyncClient client = McpClient.sync(transport) .requestTimeout(Duration.ofMillis(500000)) .build(); ToolCallback[] callbacks = SyncMcpToolCallbackProvider.builder() .mcpClients(client) .build() .getToolCallbacks();

六、REST API 接口

基础路径:/api/v1/ | 端口:8091 | CORS:全部开放

方法路径说明
GET/api/v1/query_ai_agent_config_list获取可用 Agent 列表
POST/api/v1/create_session创建对话会话
POST/api/v1/chat提交对话(同步)
POST/api/v1/chat_stream流式对话(SSE)

统一响应结构:

json
{ "code": "0000", "info": "成功", "data": { "content": "..." } }

七、技术栈一览

层级技术版本
AI 编排引擎Google ADK0.5.0
AI 框架Spring AI1.1.0-M3
LangChain4j1.4.0
后端框架Spring Boot3.4.3
语言Java17
ORMMyBatis3.0.4
数据库MySQL8.x
缓存Guava Cache32.1.3-jre
Android UIJetpack Compose + Material3
Web 前端原生 HTML/CSS/JS (Nginx)
容器化Docker + Docker Compose

八、快速启动

环境要求

  • Java 17+
  • Maven 3.8+
  • MySQL 8.x
  • Docker(可选)

三步运行

bash
# 1. 克隆仓库 git clone https://github.com/lechan775/mobile-open-claw.git cd mobile-open-claw/mobile-open-claw # 2. 配置 application-dev.yml 中的数据库连接 & API Key # 3. 启动 cd mobile-open-claw-app mvn spring-boot:run -Dspring-boot.run.profiles=dev

访问 http://localhost:8091 即可使用。

Docker 一键部署

bash
cd docs/dev-ops docker-compose -f docker-compose-environment.yml up -d # MySQL 等基础设施 docker-compose -f docker-compose-app.yml up -d # Nginx + 应用

九、项目结构

openclaw_andro/ ├── mobile-open-claw/ # 🔧 后端 (Spring Boot + DDD) │ ├── mobile-open-claw-api/ # API 接口契约层 │ ├── mobile-open-claw-app/ # 应用启动 & 自动配置 │ ├── mobile-open-claw-domain/ # 领域核心(Agent/Workflow/MCP/Skills) │ ├── mobile-open-claw-infrastructure/ # 基础设施(DAO/Gateway/Redis) │ ├── mobile-open-claw-trigger/ # HTTP 控制器 & 事件触发 │ ├── mobile-open-claw-types/ # 公共类型 & 异常 │ └── docs/ # 部署脚本 & 开发文档 │ └── mobileopenclawgateway/ # 📱 Android 前端 (Jetpack Compose) └── app/ └── src/main/java/cn/bugstack/ai/mobileopenclawgateway/

十、致谢

  • 后端 DDD 脚手架及设计模式框架来自 @小傅哥xfg-frame-archetype v2.2
  • Agent 编排能力基于 Google ADK
  • AI 对话能力由 Spring AI & LangChain4j 社区驱动

🔗 相关链接


本文发布于 2026 年 5 月,项目持续迭代中。

如果对你有用的话,可以打赏哦
打赏
ali pay
wechat pay

本文作者:williams

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!