docs: 更新架构设计——可插拔能力包模型+多实例隔离

This commit is contained in:
yumoqing 2026-08-15 09:27:31 +08:00
parent 9635825164
commit c3fcc35e08

View File

@ -1,22 +1,16 @@
# pipeline-core Agent 架构设计:对齐 Hermes CLI 能力
# pipeline-core Agent 架构设计:可插拔产线能力 + 对齐 Hermes CLI
> 目标:让 pipeline-core 的 agent 达到 Hermes CLI 的能力水平,通过 gateway 服务层 + bricks 适配,
> 在 Web 界面用 AgentIO 提供与 Hermes CLI 相同的交互体验。
> 目标pipeline-core 是产线无关的通用 agent 内核,产线能力(工具+prompt+handler
> 以「能力包」形式可插拔注册agent 可多实例,实例间能力按产线隔离。
> 通过 gateway 服务层 + bricks 适配,在 Web 界面用 AgentIO 提供与 Hermes CLI 相同的交互。
## 1. 现状盘点
## 1. 核心原则
pipeline-core 已有"对照 Hermes 重构"的骨架:
1. **core 产线无关**pipeline-core 只提供通用 agent 内核不含任何具体产线SDLC/KTV/...)的能力。
2. **能力可插拔**:产线能力 = PipelineAbility工具定义 + prompt 片段 + handler独立注册。
3. **多实例能力隔离**AgentExecutor 按 pipeline_id 从注册表挂载能力A 产线 agent 与 B 产线 agent 工具集不同。
| 层 | 现状 | 位置 |
|----|------|------|
| 能力定义 | AgentConfig / ToolDefinition / CompressionConfig / MemoryConfig / SkillConfig | pipeline_core/agent_config.py |
| 工具注册 | ToolRegistry / register_tool / to_openai_schema | pipeline_core/tool_registry.py |
| 技能系统 | SkillLoader 三级隔离global/orgs/users | pipeline_core/skill_loader.py |
| 记忆系统 | MemoryStoreMySQL pipeline_user_memory + 缓存) | pipeline_core/memory_store.py |
| 执行引擎 | AgentExecutor多轮 tool-loop + native function calling | pipeline_service/agent_loop_v2.py |
| 通用工具底层 | _run_shell / _write_code_file / _git_* (仅角色 agent 用) | pipeline_service/agent_loop.py |
## 2. 目标架构(四层)
## 2. 分层架构
```
┌────────────────────────────────────────────────────────────┐
@ -28,57 +22,64 @@ pipeline-core 已有"对照 Hermes 重构"的骨架:
├────────────────────────────────────────────────────────────┤
│ L2 执行引擎 pipeline-service AgentExecutor │
│ 多轮工具循环 + native function calling + 上下文压缩 │
│ _execute_tool: registry → ability(按pipeline_id) → 通用 │
├────────────────────────────────────────────────────────────┤
│ L1 能力定义 pipeline-core │
│ AgentConfig + ToolRegistry + SkillLoader + MemoryStore │
│ + 通用工具集terminal/file/session_search/delegation/ │
│ clarify/todo
│ GENERAL_TOOLS通用工具 + DEFAULT_AGENT_CONFIG通用心智
│ PipelineAbility 注册表 + ToolRegistry + Skill + Memory │
└────────────────────────────────────────────────────────────┘
```
## 3. 差距分析
## 3. 能力包模型PipelineAbility
| 能力 | Hermes CLI | pipeline 现状 | 缺口 |
|------|-----------|--------------|------|
| 多轮工具循环 | ✅ | ✅ AgentExecutor | 无 |
| 记忆 / 技能 | ✅ | ✅ 雏形 | 无 |
| 诚实降级 / 澄清 | ✅ | ✅(已修) | 无 |
| 文件工具 read/write/list/search | ✅ | 仅角色 agent 有 | cockpit 缺 |
| shell 执行 | ✅ terminal | ✅ _run_shellrun_command 已接) | 需增强 |
| 会话搜索 | ✅ session_search | ❌ | 缺 |
| 子代理委派 | ✅ delegate_task | delegate_subtask 只有壳 | 缺实现 |
| 任务规划 | ✅ todo | ❌ | 缺 |
| slash 命令 | ✅ 40+ 个 | ❌ | 缺 |
| gateway 层 | ✅ 多平台 | ❌ 只有 Web | 缺 |
| 流式 + 工具预览 + 文件上传 + 模型选择 | ✅ | ✅ 部分 | 需打磨 |
```python
# pipeline_core/ability.py
@dataclass
class PipelineAbility:
pipeline_id: str # 产线标识(对应 pipelines 表 id
name: str # 产线名称
tools: List[ToolDefinition] # 产线专属工具定义
system_prompt: str # 产线专属 prompt 片段
handlers: Dict[str, Callable] # {tool_name: async handler(sor, params, ctx)}
## 4. 分阶段计划
register_ability(ability) # 注册(幂等)
get_ability(pipeline_id) # 按产线取能力包
```
### 阶段1通用工具集让 agent 能"干活"
新增工具cockpit AgentExecutor 暴露):
- `read_file` / `write_file` / `list_files` / `search_files` —— 复用 agent_loop.py 底层,加 workspace 沙箱限制
- `run_command` —— 已有,增强(超时/输出截断已具备)
- `session_search` —— 搜 pipeline_conversations 表
- `delegate_subtask` —— 真正实现spawn 子 AgentExecutor 独立执行
- `ask_user` —— 已修好(合法终止动作)
- `todo` —— 会话内任务列表(内存态)
- **handler 签名统一**`async def handler(sor, params, ctx) -> str`ctx = {project_id, user_id, workspace_dir, model_name, config}。
- **依赖方向**pipeline-core纯定义+注册表)← pipeline-servicesdlc_ability 注册 SDLC 能力)。
- **扩展 B 产线**:新增 `b_ability.py` + `register_ability(...)`,零侵入 core / AgentExecutor。
交付物pipeline-core 新增 GENERAL_TOOLS 定义 + pipeline-service 实现 handler。
## 4. 通用工具 vs 产线工具
### 阶段2slash 命令 + AgentIO 交互对齐
- 后端:解析 /new /model /tools /skills /status /reset 等 slash 命令
- 前端AgentIO 支持 slash 命令 + 工具调用过程完整展示 + 会话列表
**GENERAL_TOOLScore 内核,任何产线 agent 都有11 个)**
switch_project / create_project / run_command / ask_user / delegate_subtask /
read_file / write_file / list_files / search_files / session_search / todo
### 阶段3gateway 服务层
- 常驻服务抽象 + 会话生命周期管理 + 通道抽象
- 第一通道 = Web AgentIObricks预留多通道接口
**SDLC 能力包pipeline_service/sdlc_ability.py14 个)**
create_task / list_tasks / task_detail / start_agents / diagnose_project /
list_deliverables / view_deliverable / list_questions / answer_question /
add_repo / list_repos / clone_repo / check_progress / add_bug
## 5. 安全约束(贯穿所有阶段)
## 5. 已落地 vs 待办
- terminal/file 工具必须在 workspace 目录内操作(`_is_safe_workdir` 白名单)
- 陌生用户入口Wterm 等)必须沙箱化 + 最小权限
| 项 | 状态 |
|----|------|
| core 剥离 SDLCGENERAL_TOOLS + DEFAULT_AGENT_CONFIG | ✅ 已落地 |
| PipelineAbility 注册表 + 动态挂载 | ✅ 已落地 |
| sdlc_ability.pySDLC 能力包) | ✅ 已落地 |
| AgentExecutor 按 pipeline_id 挂载(多实例隔离) | ✅ 已落地 |
| 诚实降级 / 能力自省 / ask_user | ✅ 已落地 |
| 通用工具集terminal/file/search/session/todo/delegate | ✅ 已落地 |
| 阶段2slash 命令 + AgentIO 交互对齐 | ⏳ 待办 |
| 阶段3gateway 服务层(会话生命周期 + 通道抽象) | ⏳ 待办 |
## 6. 安全约束
- terminal/file 工具必须在 workspace 目录内操作(`_resolve_ws_path` 越界拦截 + `_ALLOWED_WORKDIRS` 白名单)
- 危险命令rm -rf 等需确认requires_confirmation
- 陌生用户入口Wterm 等)沙箱化 + 最小权限
## 6. 验证标准
## 7. 验证标准
每个阶段完成后:浏览器端到端实测 agent 完整交互流程,不靠声称通过。