feat(sdk): add sub-agent support to Python SDK and maxSubagentDepth to both SDKs - #6467
feat(sdk): add sub-agent support to Python SDK and maxSubagentDepth to both SDKs#6467juhuan wants to merge 1 commit into
Conversation
… to both SDKs Python SDK: - Add SubagentConfig and RunConfig TypedDicts - Add `agents` option to QueryOptions (sent via initialize payload) - Add `max_subagent_depth` option (maps to --max-subagent-depth CLI flag) - Validate agents (name, description, systemPrompt required) and max_subagent_depth (1-100) TypeScript SDK: - Add `maxSubagentDepth` to TransportOptions, QueryOptions, and Zod schema - Pass through to ProcessTransport.buildCliArguments as --max-subagent-depth The TS SDK already had `agents` support via SubagentConfig and the initialize payload; this PR adds the missing `maxSubagentDepth` option.
|
Thanks for the PR! Template: uses "Summary" / "Test plan" instead of the standard template headings ("What this PR does", "Why it's needed", "Reviewer Test Plan", "Risk & Scope", "Linked Issues"). Content is clear, but worth aligning with the template for future PRs. Problem: this is a feature addition — exposing Direction: aligns with the project's sub-agent / multi-agent roadmap. The CLI already supports Size: 92 additions, 0 deletions, 8 files. All in Approach: minimal and focused. Each change is a direct wire-through: type definition → validation → CLI arg / initialize payload. No over-abstraction, no scope creep. One minor note: the Python Moving on to code review. 🔍 中文说明感谢贡献! 模板:使用了 "Summary" / "Test plan" 而非标准模板标题("What this PR does"、"Why it's needed"、"Reviewer Test Plan"、"Risk & Scope"、"Linked Issues")。内容清晰,但建议后续 PR 对齐模板格式。 问题:这是功能新增——在 Python SDK 中暴露 方向:与项目的子代理 / 多代理路线图一致。CLI 已经支持 规模:92 行新增,0 行删除,8 个文件。全部在 方案:最小化且聚焦。每处改动都是直接贯通:类型定义 → 校验 → CLI 参数 / initialize payload。无过度抽象,无范围蔓延。一个小注:Python 的 进入代码审查 🔍 — Qwen Code · qwen3.7-max |
2a. Code ReviewThe diff is clean and focused — each change is a direct wire-through from SDK types to CLI args / initialize payload. No correctness bugs, no security issues, no over-abstraction. One gap worth noting: the PR adds new validation logic ( Otherwise, the implementation follows project conventions well:
2b. Real-Scenario TestingSDK test suites (worktree, PR diff applied): Manual validation probe (Python SDK, tmux): All five validation cases behave correctly. CLI integration: could not run TUI: N/A — SDK-only changes, no user-visible output. 中文说明2a. 代码审查diff 干净且聚焦——每处改动都是从 SDK 类型到 CLI 参数 / initialize payload 的直接贯通。无正确性 bug,无安全问题,无过度抽象。 一个值得注意的缺口: PR 新增了验证逻辑( 其余方面,实现很好地遵循了项目规范:
2b. 真实场景测试SDK 测试套件(worktree,已应用 PR diff): 手动验证探测(Python SDK,tmux): 所有五个验证用例行为正确。 CLI 集成: 无法运行 TUI: 不适用——仅 SDK 变更,无用户可见输出。 — Qwen Code · qwen3.7-max |
|
This PR does exactly what it should: wire SDK types → validation → CLI args / initialize payload for sub-agent configuration. The implementation is minimal, follows project conventions, and every line in the diff serves the stated goal. The one thing I'd ask the author to consider before merge: adding tests for the new validation branches (depth range, bool rejection, agent required fields) and CLI argument generation. The validation logic is correct — I verified it manually — but having it under test prevents regressions. Not blocking, but it would make this a stronger contribution. Everything else checks out: existing test suites pass (1163 TS + 58 Python), types align with the CLI's actual Approving. ✅ 中文说明这个 PR 做了它该做的事:将 SDK 类型 → 验证 → CLI 参数 / initialize payload 贯通到子代理配置。实现最小化,遵循项目规范,diff 中的每一行都服务于声明的目标。 唯一想请作者在合并前考虑的:为新验证分支(深度范围、bool 拒绝、agent 必填字段)和 CLI 参数生成添加测试。验证逻辑是正确的——我手动验证过——但有测试覆盖可以防止回归。不是阻塞项,但会让贡献更完善。 其余一切正常:现有测试套件通过(1163 TS + 58 Python),类型与 CLI 实际的 批准 ✅ — Qwen Code · qwen3.7-max |
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
LGTM, looks ready to ship. ✅
|
|
||
|
|
||
| class SubagentConfig(TypedDict, total=False): | ||
| """Configuration for a sub-agent. |
There was a problem hiding this comment.
[Suggestion] SubagentConfig and RunConfig TypedDicts are defined here but never referenced — QueryOptions.agents is typed as list[dict[str, Any]] (lines 140 and 167), so these TypedDicts provide zero type-safety benefit. Callers get no IDE autocomplete or static checking.
Either wire them in:
agents: list[SubagentConfig] | None = NoneOr remove them and keep list[dict[str, Any]], consistent with how mcp_servers is typed as dict[str, dict[str, Any]].
— qwen3.7-max via Qwen Code /review
| return parsed | ||
|
|
||
|
|
||
| def _as_optional_list_of_dicts( |
There was a problem hiding this comment.
[Suggestion] No tests added for the new code in this PR. _as_optional_list_of_dicts has 4 branches (None, not-list, non-mapping items, valid) with zero coverage. The validation blocks for max_subagent_depth (bool exclusion, range 1–100) and agents (required-field checks) in validation.py are also untested, as are the --max-subagent-depth CLI arg in transport.py and the agents payload in query.py.
Consider adding tests covering:
_as_optional_list_of_dicts— valid list, non-list input, list with non-mapping itemsvalidate_query_options—max_subagent_depthboundaries (0, 1, 100, 101), bool rejection, agents missing required fieldsbuild_cli_arguments—--max-subagent-depthflag emission_initialize—agentsincluded in control request payload when set
— qwen3.7-max via Qwen Code /review
💡 Suggestion: Consolidate SDK PRsHi @juhuan, thanks for the comprehensive SDK work! We noticed you have 15 open PRs that all modify the same core files ( The problem
Suggestion: regroup into 2 PRsWe recommend closing the current 15 PRs and reopening them as 2 consolidated PRs: PR 1 — Covers pure SDK-side option additions (~9 current PRs):
PR 2 — Covers features that also involve CLI-side
This keeps a reasonable separation of concerns while eliminating the merge-conflict chain and making review much more manageable. /cc @juhuan |
|
Closing in favor of consolidated PRs (see suggestion comment above). Please reopen as 2 grouped PRs. |
Summary
Python SDK — add full sub-agent support:
SubagentConfigandRunConfigTypedDictsagentsoption inQueryOptions(sent to CLI viainitializecontrol request payload)max_subagent_depthoption (maps to--max-subagent-depthCLI flag, validated 1–100)name,description, andsystemPromptTypeScript SDK — add
maxSubagentDepth:maxSubagentDepthinTransportOptions,QueryOptions, and Zod schema (int, 1–100)createQuery→ProcessTransport→buildCliArgumentsas--max-subagent-depthagentssupport viaSubagentConfigand theinitializepayloadTest plan
pytest— 58 passed)tsc --noEmit)vitest run— 1163 passed)agentsconfig is received by CLI--max-subagent-depthlimits nesting