feat(subagent-runtime): subagent tool - #453
Open
openjiuwen-sync-bot[bot] wants to merge 13 commits into
Open
Conversation
新增 openjiuwen/harness/subagent_runtime/,包含: - 运行时配置与 wait 超时常量 - 状态、Op、Metadata、展示名解析、Spawn/Wait DTO - task_id / subagent_id 生成 - StatusChannel + StatusReceiver 进程内发布订阅 尚未包含 registry、instance、worker、control。
在 subagent_runtime 中落地单实例运行与父会话级名额管理,使子代理 可在 asyncio 队列上串行消费输入、调用 DeepAgent 完成 invoke,并对外 暴露可订阅的生命周期状态。 主要变更: - 新增 SubagentRegistry / SpawnReservation:同步名额计数与元数据索引,支持 reserve/commit/rollback 三段式占位,避免创建中途失败导致名额泄漏; 提供 touch、lru_candidates 等查询能力 - 新增 SubagentInstance:常驻 Session + serial worker,支持 enqueue(UserInputOp/ShutdownOp)、interrupt、shutdown;共享 Semaphore 限制跨实例并发 invoke;cancel 路径保证 finalize/commit - 新增 errors 模块,并补充三个 DeepAgent 段 StatusCode(实例不存在、 名额已满、运行时错误) - 扩展包导出与单元测试,覆盖主路径、interrupt/shutdown、Semaphore 串行及 Registry+Instance 流程 case
- 实现 subagent 编排层:SubagentControl 提供 spawn/wait/close等对外 API - SubagentSessionManager 负责子 agent session 生命周期名额 LRU 淘汰 - 修正 Instance.is_evictable,使 COMPLETED 后 finalize期间仍可被驱逐。
- 在 enable_subagent_runtime 下注册常驻子代理三件套,替代 task_tool / sessions_* 的 runtime 模式。 - 新增 SubagentSpawnTool / SubagentWaitTool / SubagentListTool 及 build_subagent_tools - 新增 _control_registry,按父会话在 DeepAgent 上缓存 SubagentControl - SubagentRail 支持 runtime 三分支,注入 SUBAGENT_TOOLS prompt section - Control 补充 capacity、describe_live、cancel_all;Instance 支持 turn 超时 - DeepAgent 在 stream 取消与 abort 时 release_subagent_control - 贯通 enable_subagent_runtime 配置(config / spec / factory / extension_binder) - 补充工具层、registry、Rail 与 runtime 单测
- 将subagent实例状态投影为 subagent_updated 事件写入父 Session 输出流, 供消费侧更新subagent卡片;不发工具卡(由 Swarm Rail 负责)。 - 新增 status_events:内部状态映射为 running/closed,build_subagent_updated_payload、emit_subagent_updated - Control 新增 describe_one、emit_status_update;describe_live 与之字段对齐 - spawn/wait 返回前 emit;Instance 终态经 on_status_changed 回调自动 emit - SubagentMetadata 补 task_description 与时间戳;展示字段支持 AgentCard 回退 - get_subagent_control 传入 parent_session 供 worker 写流
扩展 openjiuwen/harness/subagent_runtime/ 与 tools/prompts,包含: - ClosedSubagentRecord + _closed_records:close/LRU 后保留元数据,供 resume 与 close 状态推送 - SubagentControl.send_input() / resume() / close() 增强(_evict_from_memory) - SessionManager.restore():session_exists 校验后复用 create,历史由 pre_run 恢复 - SubagentInstance.has_pending_work():修复多轮 send_input 后 wait 过早返回 - 三工具 subagent_send_input / subagent_close / subagent_resume + prompt 元数据注册 - 六工具全链路测试及 Control / SessionManager / Tool 分层用例
- 将子 agent 记录与协作轮次写入父 session state(subagents 桶),支持 flush/hydrate/snapshot,进程重启或会话恢复后可 resume 与回看历史。 - 新增 persistence.py:读写/合并/裁剪 subagents 桶 - models:SubagentRecord、SubagentTurn、SubagentSnapshot - SubagentControl:flush/hydrate/snapshot;worker 终态时追加 SubagentTurn - _control_registry:创建时 hydrate,释放时 flush - 移除 ClosedSubagentRecord 别名;QaRound 更名为 SubagentTurn - 删除 session_manager.persist() 占位;补充 persistence/control/registry 单测
- subagent_wait 返回 output_files,每轮回答写入
sub_agents/{id}/outputs/{task_id}.md
- 新增 subagent_activity 活动流:投影 tool_call/result/thinking/error,
经有界队列写入父会话流;里程碑活动持久化并纳入 snapshot
- enable_subagent_runtime 开启时,AgentModeRail 跳过 task_tool 动态注册
- 更新 subagent_wait 工具描述与单测
|
head_sha: 🤖 正在生成合并请求摘要,请稍候… |
|
head_sha: 🤖 AI 代码检视正在进行中,请稍候… |
|
|
|
head_sha: |
1 similar comment
|
head_sha: |
父 agent 未传 timeout_ms 时默认从 30s 提升到 600s,与 turn_timeout_s 一致, 并在工具描述与 system prompt 中明确 120s/600s/3600s 的使用建议,避免调研类任务过早 timed_out。
|
head_sha: |
COMPLETED/INTERRUPTED/ERRORED 对外映射为 idle + turn_outcome,仅 CLOSED/NOT_FOUND 为 closed
|
head_sha: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Paired: GitHub #453 ↔ GitCode !2275
What type of PR is this?
/kind
Self-checklist:(请自检,在[ ]内打上x,我们将检视你的完成情况,否则会导致pr无法合入)