Local Agent 技术方案设计

💡 Brainstorm 完成 · 2026-01-29 · Seed 🌱 & 哥哥

背景与目标

实现一个类似 Cowork 的 Local Agent:

Cowork 架构参考

┌─────────────────────────────────────┐
│          Mac App (Swift)            │
├─────────────────────────────────────┤
│        Apple Virtualization         │
│  ┌───────────────────────────────┐  │
│  │     Linux VM (Sandbox)        │  │
│  │  ┌─────────────────────────┐  │  │
│  │  │     Claude Code         │  │  │
│  │  │   (stdio 通信)          │  │  │
│  │  └─────────────────────────┘  │  │
│  │  + 项目文件挂载              │  │
│  └───────────────────────────────┘  │
└─────────────────────────────────────┘

核心架构

为什么用 Coding Agent 做 Orchestration?

Coding Agent 已经内置了你需要的一切:

💡 你只需要:1) 把任务发给它 2) 接收结果和进度 3) 做 UI 展示

目标架构

┌────────────────────────────────────────┐
│           Local Agent App              │
│         (Mac 原生 / Electron)          │
├────────────────────────────────────────┤
│         Orchestration 逻辑             │
│    - 接收用户输入                      │
│    - 通过 ACP 协议与 Agent 通信        │
│    - 处理 sessionUpdate 更新 UI        │
│    - 权限审批                          │
├────────────────────────────────────────┤
│       Sandbox (Docker/Lima/VM)         │
│  ┌──────────────────────────────────┐  │
│  │  OpenCode / Copilot CLI          │  │
│  │  (ACP over TCP, port 8080)       │  │
│  └──────────────────────────────────┘  │
│  + 项目文件挂载                        │
│  + MCP 工具扩展                        │
└────────────────────────────────────────┘

Coding Agent 方案对比

可选方案

方案特点评分
OpenCode完整 Agent, 多模型, 开源, 支持 ACP⭐⭐⭐⭐⭐
Copilot CLI完整 Agent, Claude/Codex/Copilot, 支持 ACP⭐⭐⭐⭐⭐
Codex CLI完整 Agent, OpenAI only, 开源⭐⭐⭐
Aider完整 Agent, 多模型, 开源, 无 ACP⭐⭐⭐
Goose完整 Agent, 多模型, 开源, 无 ACP⭐⭐

推荐策略

  1. 开发/调试阶段:OpenCode — 开源,可看源码,可调试
  2. 生产/体验阶段:Copilot CLI — 官方支持,流式完整,多模型

💡 关键:两者都支持 ACP,切换成本 = 改一行命令


ACP 协议详解

什么是 ACP?

ACP = Agent Client Protocol — GitHub 发布的标准协议,用于外部程序控制 Coding Agent。

协议作用
MCPModel ↔ 工具 通信协议
ACPAgent ↔ 客户端 通信协议

类比 LSP(Language Server Protocol)对编辑器的意义。

通信方式

方式 1:stdio

opencode acp
# 通过 stdin/stdout 通信

方式 2:TCP(推荐用于 Sandbox)

opencode --acp --port 8080
# 或
copilot --acp --port 8080

协议消息格式

基于 JSON-RPC 2.0:

发送 Prompt

→ {
  "jsonrpc": "2.0",
  "id": 1,
  "method": "session/prompt",
  "params": {
    "sessionId": "session_123",
    "content": [{"type": "text", "text": "帮我写个函数"}]
  }
}

流式更新(Notification)

// Agent 思考中
← {
  "method": "session/update",
  "params": {
    "sessionId": "session_123",
    "update": {
      "sessionUpdate": "agent_thought_chunk",
      "chunk": "让我分析一下..."
    }
  }
}

// 工具调用开始
← {
  "method": "session/update",
  "params": {
    "update": {
      "sessionUpdate": "tool_call",
      "toolCallId": "call_456",
      "title": "bash",
      "status": "pending"
    }
  }
}

// Agent 输出片段
← {
  "method": "session/update",
  "params": {
    "update": {
      "sessionUpdate": "agent_message_chunk",
      "chunk": "函数写好了..."
    }
  }
}

sessionUpdate 类型

SDK 使用

npm install @agentclientprotocol/sdk
import { Client } from '@agentclientprotocol/sdk'

const client = new Client()
await client.connect('tcp://sandbox:8080')

const session = await client.createSession({ cwd: '/workspace' })

// 监听更新
session.on('update', (update) => {
  console.log('Progress:', update)
})

const response = await session.prompt('帮我写个函数')

通信方案对比

裸 stdio vs ACP

对比项裸 stdioACP
协议标准❌ 每个 agent 不同✅ 统一标准
Agent 可替换❌ 换 agent 要改代码✅ 只改启动命令
Session 管理❌ 自己实现✅ 协议内置
开发成本❌ 高✅ 低(用 SDK)

ACP stdio vs ACP TCP

对比项stdioTCP
多客户端❌ 一对一✅ 可多对一
跨机器❌ 不行✅ 可以
Sandbox 集成⚠️ 需要 exec✅ 端口映射即可
调试❌ 难✅ 可 curl 测试

💡 迁移成本:OpenCode ACP → Copilot CLI ACP = 改一行命令


Copilot 订阅福利

Agent HQ(2025.10 GitHub Universe 发布)

一个 Copilot 订阅可用:

定价

计划价格包含
Copilot Individual$10/月全部 Agent
Copilot Business$19/月+ 企业功能
Copilot Enterprise$39/月+ 知识库

💡 Max 计划准备中(GitHub COO 暗示)


其他考虑点

1. Sandbox 配置

2. 权限管理

3. MCP 工具扩展

Coding Agent 默认有:文件读写、Bash 执行、Git 操作

可能需要加:

4. UI/UX


下一步计划

Phase 1: 验证可行性

Phase 2: 基础功能

Phase 3: 完善体验


相关资源

Brainstorm with Seed 🌱 — 2026-01-29