zcbot/tests
caoqianming 7d6109b932 feat(delegate): §8.11 最小子循环——上下文隔离的检索子助手(bump 0.58.30)
触发条件已满足(diag_tool_repeat.py 实测 document_search 122 次地毯搜 /
mp_search 562 次占主上下文大头)。形态 = 一个工具 delegate(instruction):
复用现成 AgentLoop 起空上下文子循环,只注只读/落盘检索白名单,硬轮数上限 20,
固定降 flash 档,跑完只把文字结论返主循环。主循环视角 = 一次普通 tool call
(零并行/零状态共享/深度 1 禁递归)。

对标 Claude Code / Agent SDK subagent:照抄 fresh-context / allowlist 工具 /
只返回最终消息 / maxTurns;有意砍掉并行与嵌套(§6 拒编排),采纳 per-subagent
模型 override 思路(降 flash)。

实现:
- core/delegate.py(新):DELEGATE_ALLOWED 白名单 + FilteredExecutor(包父
  executor 只暴露白名单∩已注册,backend 无关、delegate 不入表天然禁递归)+
  run_delegate(懒加载 AgentLoop 避 litellm 导入/循环 import)
- tools/delegate.py(新):DelegateTool schema 载体,execute 防御性 no-op
- core/loop.py:_run_delegate + _execute_tool_call 内建拦截(拦在 executor 前,
  要读活的 self.llm/caps/executor)+ usage_kind(记账 kind 区分)+
  delegate_model_factory(降档失败降级父模型)+ 内存态子循环禁折叠守卫
  (防 persist_fold 按主 task_id 污染主上下文状态)
- core/session.py:persist=False 内存态(复用主 task_id 计费归主 task、
  消息不入库不污染主流不撞 idx)
- core/agent_builder.py:注册工具 + _delegate_model 工厂(载 deepseek_v4.flash)

落地决策:① 白名单给"落盘检索"(document_download/mp_get_*)写口、不给
write/edit/run_python/shell;② 不引 Redis 抗重启(run 本进程绑定,值钱抓取数据
已落 FS,真要抗重启走 §8.12 bg-proc);③ 未收敛显式标注不当完成。

前端零结构改动(既有工具卡 spinner+跳秒覆盖不冻屏),只加 toolActivityLabel 的
delegate case。skills/brief 加 delegate 引导。tests/test_delegate.py +8
(FilteredExecutor 过滤/拒穿透/交集 + 白名单不变量 + Session persist);loop 全
路径要 litellm 本机跑不了靠生产手验(同 salvage)。DESIGN §8.11 标 。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-15 14:43:04 +08:00
..
frontend_task_progress.test.mjs fix(web): 进度条自愈——回放层强制单调完成(d1285247 复盘,bump 0.36.2) 2026-07-03 11:16:34 +08:00
test_broker_redis.py feat(broker): 外置 Redis pub/sub——蓝绿跨实例 SSE/cancel 可达(bump 0.42.0) 2026-07-06 14:51:39 +08:00
test_changelog.py feat(changelog): 用户版更新日志 CHANGELOG.md + /v1/changelog + 点版本号弹层(bump 0.55.0) 2026-07-09 16:49:26 +08:00
test_context_compaction.py fix(context): 发送期补齐悬空 tool_calls,断中断 run 留下的协议崩 + bump 0.20.2 2026-06-21 15:08:20 +08:00
test_context_fold.py feat(context): §8.8 Phase 2 长会话中段折叠摘要 + 头部压缩指示环(bump 0.54.1) 2026-07-09 12:39:31 +08:00
test_delegate.py feat(delegate): §8.11 最小子循环——上下文隔离的检索子助手(bump 0.58.30) 2026-07-15 14:43:04 +08:00
test_disk_quota.py Stage C 收尾包:资源 yaml + 磁盘配额 + 网络放开 + 容器内源持久化 2026-05-27 08:35:53 +08:00
test_executor_docker.py fix(exec): run_python script_path 宿主预检+前缀容错+code 落盘回退(bump 0.58.22) 2026-07-13 16:41:43 +08:00
test_load_skill.py feat(skills): 用户私有 skill(.skills)+ 创作工具 + skill-creator + Web 查看页 2026-06-11 09:46:39 +08:00
test_loop_malformed_retry.py feat(ops): 畸形 tool_call 进工具失败聚集 + 巡检邮件只发活跃聚集(bump 0.58.19) 2026-07-13 12:04:22 +08:00
test_loop_repeat_guard.py feat(loop): 停机判据从"步数"解耦为"是否在推进" 2026-06-10 13:22:02 +08:00
test_pptx_guard.py fix(guard): ppt 伪导出根治三层——平台机检门 + 禁令去菜谱 + 脚本 hint 纪律(bump 0.40.0) 2026-07-06 13:40:54 +08:00
test_pptx_render.py feat(preview): pptx 在线预览 —— LibreOffice→PDF + 复用 PDF iframe(DESIGN §8.3 Stage 1) 2026-06-09 13:04:02 +08:00
test_rendering.py feat(rendering): 平台渲染层 rendering/ 统一三 skill docx + chromium md→pdf + bump 0.21.0 2026-06-23 13:07:19 +08:00
test_run_python_script_path.py fix(exec): run_python script_path 宿主预检+前缀容错+code 落盘回退(bump 0.58.22) 2026-07-13 16:41:43 +08:00
test_salvage.py feat(loop): 畸形 tool_call arguments 就地抢救(salvage)省一次非流式重试(bump 0.58.24) 2026-07-15 09:20:38 +08:00
test_sandbox_check.py Stage C Step 5: main.py sandbox check + lifespan fs quota WARN 2026-05-26 16:41:16 +08:00
test_secret_host_tools.py feat(mp): mp_search_summary 批量入参 formulas[] 定点解检索烧 token(bump 0.58.28) 2026-07-15 10:49:35 +08:00
test_shortcuts.py feat(shortcuts): 加快捷指令(触发词→完整指令,入口层确定性展开)(bump 0.35.0) 2026-07-01 14:58:55 +08:00
test_skill_model_pinning.py feat(skill): skill 定向模型——ppt 触发自动热切 GLM-5.2(bump 0.39.0) 2026-07-06 08:57:32 +08:00
test_static_vendor.py Disable static asset caching 2026-06-08 09:16:31 +08:00
test_svg_alignment_check.py feat(ppt): 反纯文字页+图表落地硬门(7aa49195 二代陶瓷 deck 复盘,bump 0.38.0) 2026-07-03 13:34:51 +08:00
test_system_prompt_paths.py test(prompt): 锁住 docker 下 system prompt 不漏宿主路径(药3 复核收口) 2026-06-09 11:30:32 +08:00
test_task_progress_tool.py Add task progress tool 2026-06-08 08:44:16 +08:00
test_tool_output_compaction.py Reduce chat context token usage 2026-06-04 16:41:14 +08:00
test_toolfail_malformed.py feat(ops+web): run 级错误持久提示+失败聚集+provider 致命错误即时告警(bump 0.58.21) 2026-07-13 14:06:29 +08:00
test_usage_accounting.py feat(usage): 记账给前缀缓存命中折价 + 前端体现缓存命中/真实成本 2026-06-05 08:26:09 +08:00
test_user_skills.py feat(skills): 用户私有 skill(.skills)+ 创作工具 + skill-creator + Web 查看页 2026-06-11 09:46:39 +08:00