-
Notifications
You must be signed in to change notification settings - Fork 3k
feat(sdk): add sub-agent support to Python SDK and maxSubagentDepth to both SDKs #6467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,29 @@ | |
| ] | ||
|
|
||
|
|
||
| class RunConfig(TypedDict, total=False): | ||
| """Run configuration for a sub-agent.""" | ||
|
|
||
| max_time_minutes: int | ||
| max_turns: int | ||
|
|
||
|
|
||
| class SubagentConfig(TypedDict, total=False): | ||
| """Configuration for a sub-agent. | ||
|
|
||
| Required fields: name, description, systemPrompt. | ||
| Field names match the CLI wire format (camelCase). | ||
| """ | ||
|
|
||
| name: str | ||
| description: str | ||
| systemPrompt: str | ||
| tools: list[str] | ||
| model: str | ||
| runConfig: RunConfig | ||
| color: str | ||
|
|
||
|
|
||
| class PermissionSuggestion(TypedDict): | ||
| type: Literal["allow", "deny", "modify"] | ||
| label: str | ||
|
|
@@ -114,6 +137,8 @@ class QueryOptionsDict(TypedDict, total=False): | |
| timeout: TimeoutOptionsDict | ||
| mcp_servers: dict[str, dict[str, Any]] | ||
| stderr: Callable[[str], None] | ||
| agents: list[dict[str, Any]] | ||
| max_subagent_depth: int | ||
|
|
||
|
|
||
| @dataclass | ||
|
|
@@ -139,6 +164,8 @@ class QueryOptions: | |
| timeout: TimeoutOptions = TimeoutOptions() | ||
| mcp_servers: dict[str, dict[str, Any]] | None = None | ||
| stderr: Callable[[str], None] | None = None | ||
| agents: list[dict[str, Any]] | None = None | ||
| max_subagent_depth: int | None = None | ||
|
|
||
| @classmethod | ||
| def from_mapping(cls, value: Mapping[str, Any] | None) -> QueryOptions: | ||
|
|
@@ -183,6 +210,8 @@ def from_mapping(cls, value: Mapping[str, Any] | None) -> QueryOptions: | |
| Callable[[str], None] | None, | ||
| _as_optional_callable(data, "stderr"), | ||
| ), | ||
| agents=_as_optional_list_of_dicts(data, "agents"), | ||
| max_subagent_depth=_as_optional_int(data, "max_subagent_depth"), | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -321,3 +350,19 @@ def _as_optional_nested_dict( | |
| raise TypeError(f"{key} must be a mapping of string to mapping") | ||
| parsed[k] = dict(v) | ||
| return parsed | ||
|
|
||
|
|
||
| def _as_optional_list_of_dicts( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] No tests added for the new code in this PR. Consider adding tests covering:
— qwen3.7-max via Qwen Code /review |
||
| data: Mapping[str, Any], key: str | ||
| ) -> list[dict[str, Any]] | None: | ||
| raw = data.get(key) | ||
| if raw is None: | ||
| return None | ||
| if not isinstance(raw, list): | ||
| raise TypeError(f"{key} must be a list of mappings") | ||
| parsed: list[dict[str, Any]] = [] | ||
| for item in raw: | ||
| if not isinstance(item, Mapping): | ||
| raise TypeError(f"{key} must be a list of mappings") | ||
| parsed.append(dict(item)) | ||
| return parsed | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion]
SubagentConfigandRunConfigTypedDicts are defined here but never referenced —QueryOptions.agentsis typed aslist[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:
Or remove them and keep
list[dict[str, Any]], consistent with howmcp_serversis typed asdict[str, dict[str, Any]].— qwen3.7-max via Qwen Code /review