feat: 深挖子智能体执行核(issue #54) #58
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feature/54-delegate-subagent-core"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #54
这个 PR 做了什么
实现 issue #54「深挖子智能体执行核:隔离任务上下文 + 多轮工具循环」。这是深挖任务委托(issue #52 PRD)的后台执行体——本片只交付执行核本身,不接前台触发(issue #55 的
delegate_task工具)也不接完成后的送回(issue #53 的 Callback)。隔离任务上下文(
subagent.py)assemble_task_context:安全基线 + 任务执行指令 + 任务描述三段——不带 persona/画像/关系网/情感态/历史对话(ADR-0020"隔离任务上下文,不隔离人格")。无 IO 纯函数,同drive_tick.py::assemble_light_context既有测试模式多轮工具调用循环
run_delegated_task:工具集恒为get_tools("background")返回的 host 工具(RuntimeContext.background这个既有契约取值首次被真正接入调用点)——从不调用build_tool_schemas(),子智能体的可见工具集结构性只包含 host 工具,不含任何 core 自己的输出类工具(send_message/self_recall/edit/delegate_task本身)arise_delegate_max_rounds(不复用前台arise_run_limit):超过即撤走工具集、追加一次无工具调用逼模型收尾——用它自己对已收集信息的综合当蒸馏结果,不是简单拼接原始 tool_responsellm_client.complete()本身调用异常时 fail-closed 收尾(同reflection.py/persona_drift_guard.py既有先例),不让异常无声打断后台任务消除重复(承接 issue #53 review 的同一条纪律)
llm.py/tool_port.py:把 tool-calling 协议序列化的小助手函数(assistant message / tool result / host tool schema)从runtime_loop.py私有作用域提升为公开函数,RuntimeLoop与新的 subagent 执行核共用同一套tool_port.py新增call_host_tool(调用 host 工具 + 错误包装),同样两处共用测试
新增 3 个测试文件:纯函数(
assemble_task_context结构断言)、ScriptedLLMClient驱动的多轮循环(单轮/多轮工具调用、失败工具、未知工具名、超硬顶强制收尾、LLM 调用异常 fail-closed、只提供 background 工具不含核心输出工具)。全部 822 个测试通过,
ruff check/ruff format干净。Code review
跑过
/code-review(Standards + Spec 两轴并行子智能体):run_delegated_task的 LLM 调用缺 fail-closed 处理(不同于reflection.py/persona_drift_guard.py同类先例);②RuntimeLoop._handle_host_tool与 subagent 循环内的错误包装逻辑重复,抽出call_host_tool共用;③(次要)导入别名import X as _y掩盖了函数已跨模块公用的事实,改为直接用公开名