Skip to content

[Priority: Med] [Feature] 暴露 OpenCode subagent/subtask/task tool 扩展能力 #338

@liujuanjuan1984

Description

@liujuanjuan1984

🔍 发现的问题 / 原始需求描述

上游 opencode 已经具备明确的 subagent / subtask / task tool 能力:内建 generalexploresubagent,会话执行过程中还会生成 subtask part,并通过 task tool 驱动子任务执行。当前 opencode-a2a 虽然能承接主聊天、session control 和 MCP/tool discovery,但并没有把“这个运行时具备子 agent 编排能力”作为独立 extension 对外声明,也没有给消费方稳定暴露 subtask/tool 执行语义、能力边界和机器可发现契约。

🛠️ 详细实施方案 (必须包含涉及的文件路径和核心逻辑/伪代码)

  1. 新增 subagent/subtask 能力扩展声明。
    涉及文件:
  • src/opencode_a2a/contracts/extensions.py
  • src/opencode_a2a/server/agent_card.py
  • src/opencode_a2a/profile/runtime.py
  • docs/guide.md

建议新增一个 provider-private extension URI,例如:

  • urn:opencode-a2a:subagent-orchestration/v1

建议声明内容至少包括:

  • 支持 subagent / subtask 的运行时能力
  • 是否支持并行 subtask
  • 子任务是否复用同一 workspace / session 上下文
  • task tool 的稳定语义字段,例如 subagent_typedescriptioncommand
  • 与 shared stream hints 的关系
  1. 让 Agent Card 和文档明确说明 subtask/tool 执行如何在流式事件中体现。
    涉及文件:
  • src/opencode_a2a/server/agent_card.py
  • docs/guide.md
  • src/opencode_a2a/execution/stream_runtime.py

伪代码:

extension.params = {
  supported_agents: [...],
  execution_model: "subtask_via_task_tool",
  stream_metadata_fields: {
    subagent_type: "...",
    command: "...",
    status: "...",
  }
}
  1. 评估是否需要补一个只读查询面,帮助客户端识别可用 subagent。
    涉及文件:
  • src/opencode_a2a/contracts/extensions.py
  • src/opencode_a2a/jsonrpc/dispatch.py
  • src/opencode_a2a/jsonrpc/handlers/subagent_discovery.py (new)
  • src/opencode_a2a/opencode_upstream_client.py

可选方法:

  • opencode.subagents.list

实现上可先复用上游 /agent,再过滤出 mode=subagent 的 agent,避免和普通 agent 列表混淆。

  1. 明确和现有 issue 的边界。
    涉及文件:
  • docs/guide.md

建议本 issue 只解决“能力声明、发现、语义暴露”,不直接定义“客户端如何显式发起一个 subtask”请求契约;后者单独跟进,避免 discovery 和 invocation 混在同一个 issue 中。

🧪 回归测试建议

  • 为 Agent Card / extension params 增加契约测试,验证 subagent orchestration extension 被正确声明。
  • 为流式输出增加回归测试,确保 subtask / task tool 的关键字段可稳定观察。
  • 如果新增 opencode.subagents.list,补齐成功、空列表、上游 payload mismatch、上游失败等 handler 测试。
  • 运行 ./scripts/doctor.sh

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:todoPlanned but not started

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions