Skip to content

Sub-agents: types started at run time - #337

Merged
shoom1 merged 10 commits into
developfrom
feature/subagent-spawn
Nov 22, 2026
Merged

shoom1 merged 10 commits into
developfrom
feature/subagent-spawn

Conversation

@shoom1

@shoom1 shoom1 commented Nov 22, 2026

Copy link
Copy Markdown
Owner

An agent type can now be started while the app runs, by an agent's task call, when the app allows it twice: on the type, with AgentConfig.spawnable_by, and in the policy, with SubAgentPolicy.spawn_sources. With the default policy nothing changes: task's schema and description are pinned byte for byte on both backends. Both backends.

Types started at run time

  • AgentConfig.spawnable_by (YAML spawnable_by) names who may start the type: agent, skill or user (SPAWN_SOURCES). It is checked, not coerced, and refused when empty or unknown.
  • A free type sets spawnable_by and is in no sub_agents list. It is never the root, wherever it is listed, in configs or in agent YAML, and it is built as any sub-agent is (AgentGraph.free_types).
  • An agent graph with no root left (every agent nobody delegates to sets spawnable_by) is refused, naming the agents.
  • A free type that no enabled source can start is logged as a warning at each validation (subagent_type_unreachable).
  • validate_agent_graph(configs, backend, *, policy=None) takes the policy; both managers pass it.

The policy

  • SubAgentPolicy.spawn_sources (empty by default) is the app's switch: a source not in it starts nothing.
  • SubAgentPolicy.max_spawn_depth (default 1): a run at depth d (the root 0) may start run-time types only while d < max_spawn_depth, so by default only the main agent can.
  • A type that inherits the conversation is offered only to the main agent, as today's inheriting sub-agents are.

What one run may start

  • Delegations.offered(caller_agent, depth): the caller's own sub-agents in order, then the run-time types it may start.
  • task is offered per run: ADK builds its declaration per request, Deep Agents rewrites a sub-agent's task per request; the main agent's is fixed at build. Its agent_type enum and type lines are that run's, with the depth sentence (Sub-agents cannot start sub-agents.) when the run cannot start any.
  • A type the run may not start is "Unknown agent_type" when asked for anyway; a run offered nothing that calls task gets the unknown-tool answer on both backends.
  • With follow_ups, the follow-up tools and the roster go to every agent that can have children.

One entry for a first run

  • Delegations.start(StartRequest) starts a first run (counted toward max_runs_per_turn unless the request says otherwise, numbered past the stored instances, AGENT_RUN with its started_by). delegate is now reading the brief, then start; skills and the user's start will use it too.

Tests: written first and seen failing. The shared contract suite runs on both backends and covers:

  • a free type listed before the root (configs and YAML);
  • task offered per run by depth, including a run offered less than the tool it was built with;
  • the refusals and the unknown-tool answer;
  • the "no description" warning given at build, not per model call;
  • the default policy unchanged.

There are unit tests for the policy, spawnable_by and free types, spawn.py, Delegations.offered/task_offer/start and the YAML key. Reviewed in two parts; one round of review fixes.

The full offline suite passes in the worktree (10634 passed), except TestChildImportOrigin::test_child_resolves_the_checkout, which fails the same way on develop under the worktree wrapper. On CI's library versions the contract suites and every touched file pass (1051).

SubAgentPolicy gains who may start an agent type at run time (spawn_sources, of SPAWN_SOURCES: agent, skill, user; none by default) and from how deep (max_spawn_depth, 1: the root alone). A set, list or tuple of sources is kept as a frozenset; anything else, and a depth that is no positive int, is refused as the policy is made.
AgentConfig.spawnable_by names who may start a type at run time (agent, skill, user; the agent YAML's spawnable_by: [agent]). A type that sets it and is in no sub_agents list is a free type (AgentGraph.free_types): never the root. validate_agent_graph takes the policy, counts roots among the agents that are not free types, refuses spawnable_by on the root, an empty one and a source other than the three, and warns of a free type no source the policy enables can start.
…e run

workflow/agents/spawn.py says which types a source may start (spawnable: the policy's spawn_sources and the type's spawnable_by), from which depth (may_spawn) and which agents are built with task (can_have_children). task_description can add 'Sub-agents cannot start sub-agents.' after the limits and be made without its warning; task_offer makes a run's schema and description together (TaskOffer).
Delegations.offered is what a run of an agent at a depth may start with task: its own sub-agents, then, while the run is above max_spawn_depth and does not inherit, the types agents may start at run time (an inheriting one for the root alone). task_offer is task's schema and description for that run, None when it may start nothing. delegate reads the brief against it, so a type the run is not offered is an unknown agent_type and starts no run.
Delegations.start runs a first run of a type from a StartRequest (the type, the brief, who starts it, the calling run and call, the conversation, the shared state, an inheriting type's history, whether it counts toward the turn's runs): counted, numbered past the stored instances, reported with its started_by, run through the hook to its end. delegate is now read_brief and start; who may start the type stays the asker's to check.
Both managers validate their agents with their policy. Deep Agents' build_agent_tree takes the validated graph's root (root=), where it took the first agent nobody delegates to: a free type listed before the root, in configs or agent YAML, became the root. Free types are built as any sub-agent is on both.
Every agent that can have sub-agents (its own, or types it may start at run time) is built with task, and, with follow_ups, the parent's tools and the roster. What one run is offered is its own: ADK's TaskTool declares, for each request, the types the run that asks may start, none when it may start nothing; Deep Agents fixes the root's and RunControlMiddleware rewrites a sub-agent's for each model call. A run offered nothing that calls task gets the answer for a tool it does not have, on both. With the default policy task is what it was, byte for byte.
The CHANGELOG adds spawnable_by and free types, spawn_sources and max_spawn_depth, and rewrites the bullets that said task lists only the caller's sub-agents, or that only an agent with sub-agents gets task, the parent's tools and the roster. The README's AgentConfig table, graph checks and sub-agent section, and CLAUDE.md's structure lines and sub-agent paragraph, say the same.
Pins the offer a run is made, not the one its agent was built with (a run below the depth its task was built for, on both backends), that a per-request offer logs no description warning, that an unknown task call on Deep Agents is logged at info, and that each validation warns of an unreachable free type. Docstrings say the run's depth is below max_spawn_depth, name the TypeError of policy=, and say how start names a run; long README and CHANGELOG lines are rewrapped, imports ordered, a misplaced test class and comment moved.
@shoom1
shoom1 merged commit fa4d56b into develop Nov 22, 2026
6 checks passed
@shoom1
shoom1 deleted the feature/subagent-spawn branch November 22, 2026 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant