QihuAI Design
|
33d0f9c32e
|
feat(workflow #874): NodeRegistry 统一工作流节点抽象 + 双 Claw 事件对齐
#874 P3 工作流引擎 NodeRegistry 统一(加速带「工具即节点」思想落地,零源码拷贝重写):
- app/core/node_registry.py(新增):把 skill / MCP / Agent / DAG 四套割裂表达收敛为
单一 Node 抽象。BaseNode(Protocol) 定义 node_type/name/input_schema/output_schema/
risk_level + async run(ctx);NodeContext 携带 db/tenant_id/claw_type/trace_id/黑板/emit;
NodeResult.to_blackboard() 与既有 orchestrator 黑板结构无缝互转。内建八型节点
llm/reduce/local/external/agent/skill/mcp/loop,均继承 NodeBase 公共生命周期
(发 start 步骤 -> 执行 -> ok/fail 覆盖同 index),异常统一归一为 NodeError(带结构化
diagnosis)。SkillNode 用 asyncio.to_thread 包裹同步执行器避免阻塞事件循环;
LoopNode 硬限流 20 次迭代 / 并发上限 5,子节点经 ctx.child() 复用同一 StepCounter 与
emit,保证步骤序号全图唯一。CapabilitySnapshot 统一承载 skills/mcp_servers/agents/
function_definitions/mcp_tool_map,供 _build_system_prompt、run_graph、yaml 校验三处
共用同一份能力真相。normalize_claw() 将 im_wechat/im_platform 归一为 "im",避免
Grafana 维度碎片化。
- app/core/capability_discovery.py:新增 discover_agents(),与 discover_skills 同构的
三级降级策略(显式安装 -> published 兜底 -> rank_by_query 裁剪),补齐 Agent 维度的
统一能力发现,杜绝各处内联第二份发现逻辑(#866 回退事故教训)。
- app/core/orchestrator.py:VALID_NODE_TYPES 与 validate_graph 改为运行期读
registry.node_types()/requires_agent(),注册表成为节点类型的单一真相源;_run_node 改为
拼装 NodeContext 后委托 registry.get(ntype).run(ctx),本体只保留调度与拓扑;run_graph
新增 on_event/claw_type/tenant_id/snapshot 参数,编排全过程以统一 EngineEvent 下发。
- app/core/yaml_workflow.py:valid_node_types() 实时读注册表;validate_yaml 补 skill/mcp/
loop 必填校验;yaml_to_orchestration / orchestration_to_yaml 双向透传节点扩展字段
(label/skill_id/func_name/tool/server_id/args/body/items/split/max_iterations/
concurrency/join),修复配置往返丢字段。
- app/core/engine_event.py:make_step 新增 node 参数,以 step["node"]={id,type,label}
承载节点身份。设计书原文的 EngineEvent(kind="node") 与前端仅识别 thinking/skill/mcp/
agent/kb/media 的现状冲突(未知 kind 会被静默丢帧),故映射为已知 kind + 附加字段,
线格式对旧前端字节兼容。
- app/api/chat_service.py:Web Claw 编排调用点透传 on_event/claw_type/tenant_id,
租户与通道标签复用 #875 的 ContextVar(get_route_ctx),不再新增一层参数透传。
IM Claw 经 EngineCore 自动继承同一事件流(单引擎原则,im_llm.py 零改动)。
- tests/test_node_registry.py(新增):R-NODE-1~11 确定性哨兵,无网络无外部依赖。守卫
内建八型齐全、注册表为单一真相源(orchestrator 与 yaml 校验实时同源)、describe 契约、
双 Claw 事件对齐(SseAdapter 与 BufferAdapter 逐键相等且均带 node 身份)、claw 归一与
tenant 标签、新节点必填校验、YAML 往返不吞字段、Loop 限流聚合、失败结构化诊断两端可见、
禁止第二份能力发现、register 拒绝非法节点。
验证:容器内 py_compile 全通过;pytest tests/ 退出码 0(85 项 = 83 passed + 2 skipped,
0 FAILED/ERROR),含 R-NODE 16 项与 R-DUAL 双 Claw 哨兵。
safe-align: 仅复制 7 个 git-tracked 文件,未触碰 secrets/.venv/node_modules/dist/caches。
本地提交不 push。
|
2026-08-04 15:16:00 +08:00 |
|
QihuAI Design
|
037c965c26
|
feat(engine): #873 dual-Claw event contract + SseAdapter/BufferAdapter + chat.py SSE delegate + im_llm EngineCore thin-shell (gray-gated)
- app/core/engine_event.py (#880): EngineEvent dataclass + make_* factories, single construction entry, byte-compatible wire with legacy ChatPage.tsx
- app/core/claw_adapters.py (#884): SseAdapter (hot frames zero-metadata, terminal keeps trace_id) + BufferAdapter (assemble() preserves __media__)
- app/api/chat.py (#881): /messages/stream now delegates to SseAdapter; wire bytes unchanged (46B delta / done+message_id)
- app/api/im_llm.py (#883): IM_USE_ENGINE_CORE gray gate; _call_engine_core reuses EngineCore via BufferAdapter (default OFF, preserves media fast-path)
- app/api/chat_service.py: capture 3 container-ahead fixes (stray import asyncio removed, logger.info format, LiteLLM master key)
|
2026-08-04 12:25:12 +08:00 |
|