4.9 KiB
4.9 KiB
pipeline-core Agent 架构设计:可插拔产线能力 + 对齐 Hermes CLI
目标:pipeline-core 是产线无关的通用 agent 内核,产线能力(工具+prompt+handler) 以「能力包」形式可插拔注册;agent 可多实例,实例间能力按产线隔离。 通过 gateway 服务层 + bricks 适配,在 Web 界面用 AgentIO 提供与 Hermes CLI 相同的交互。
1. 核心原则
- core 产线无关:pipeline-core 只提供通用 agent 内核,不含任何具体产线(SDLC/KTV/...)的能力。
- 能力可插拔:产线能力 = PipelineAbility(工具定义 + prompt 片段 + handler),独立注册。
- 多实例能力隔离:AgentExecutor 按 pipeline_id 从注册表挂载能力,A 产线 agent 与 B 产线 agent 工具集不同。
2. 分层架构
┌────────────────────────────────────────────────────────────┐
│ L4 交互层 pipeline-sdlc / bricks │
│ AgentIO + slash 命令菜单 + 流式工具预览 + 会话列表 │
├────────────────────────────────────────────────────────────┤
│ L3 Gateway 层 pipeline-core / pipeline-service │
│ 常驻服务 + 会话生命周期 + 通道抽象(Web AgentIO 为第一通道)│
├────────────────────────────────────────────────────────────┤
│ L2 执行引擎 pipeline-service AgentExecutor │
│ 多轮工具循环 + native function calling + 上下文压缩 │
│ _execute_tool: registry → ability(按pipeline_id) → 通用 │
├────────────────────────────────────────────────────────────┤
│ L1 能力定义 pipeline-core │
│ GENERAL_TOOLS(通用工具) + DEFAULT_AGENT_CONFIG(通用心智)│
│ PipelineAbility 注册表 + ToolRegistry + Skill + Memory │
└────────────────────────────────────────────────────────────┘
3. 能力包模型(PipelineAbility)
# 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)}
register_ability(ability) # 注册(幂等)
get_ability(pipeline_id) # 按产线取能力包
- handler 签名统一:
async def handler(sor, params, ctx) -> str,ctx = {project_id, user_id, workspace_dir, model_name, config}。 - 依赖方向:pipeline-core(纯定义+注册表)← pipeline-service(sdlc_ability 注册 SDLC 能力)。
- 扩展 B 产线:新增
b_ability.py+register_ability(...),零侵入 core / AgentExecutor。
4. 通用工具 vs 产线工具
GENERAL_TOOLS(core 内核,任何产线 agent 都有,11 个): switch_project / create_project / run_command / ask_user / delegate_subtask / read_file / write_file / list_files / search_files / session_search / todo
SDLC 能力包(pipeline_service/sdlc_ability.py,14 个): 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. 已落地 vs 待办
| 项 | 状态 |
|---|---|
| core 剥离 SDLC(GENERAL_TOOLS + DEFAULT_AGENT_CONFIG) | ✅ 已落地 |
| PipelineAbility 注册表 + 动态挂载 | ✅ 已落地 |
| sdlc_ability.py(SDLC 能力包) | ✅ 已落地 |
| AgentExecutor 按 pipeline_id 挂载(多实例隔离) | ✅ 已落地 |
| 诚实降级 / 能力自省 / ask_user | ✅ 已落地 |
| 通用工具集(terminal/file/search/session/todo/delegate) | ✅ 已落地 |
| 阶段2:slash 命令 + AgentIO 交互对齐 | ⏳ 待办 |
| 阶段3:gateway 服务层(会话生命周期 + 通道抽象) | ⏳ 待办 |
6. 安全约束
- terminal/file 工具必须在 workspace 目录内操作(
_resolve_ws_path越界拦截 +_ALLOWED_WORKDIRS白名单) - 危险命令(rm -rf 等)需确认(requires_confirmation)
- 陌生用户入口(Wterm 等)沙箱化 + 最小权限
7. 验证标准
每个阶段完成后:浏览器端到端实测 agent 完整交互流程,不靠声称通过。