Repository navigation
Sub-agents: types started at run time - #337
Merged
Merged
Conversation
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.
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.
An agent type can now be started while the app runs, by an agent's
taskcall, when the app allows it twice: on the type, withAgentConfig.spawnable_by, and in the policy, withSubAgentPolicy.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(YAMLspawnable_by) names who may start the type:agent,skilloruser(SPAWN_SOURCES). It is checked, not coerced, and refused when empty or unknown.spawnable_byand is in nosub_agentslist. It is never the root, wherever it is listed, inconfigsor in agent YAML, and it is built as any sub-agent is (AgentGraph.free_types).spawnable_by) is refused, naming the agents.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 depthd(the root 0) may start run-time types only whiled < max_spawn_depth, so by default only the main agent can.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.taskis offered per run: ADK builds its declaration per request, Deep Agents rewrites a sub-agent'staskper request; the main agent's is fixed at build. Itsagent_typeenum and type lines are that run's, with the depth sentence (Sub-agents cannot start sub-agents.) when the run cannot start any.taskgets the unknown-tool answer on both backends.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 towardmax_runs_per_turnunless the request says otherwise, numbered past the stored instances,AGENT_RUNwith itsstarted_by).delegateis now reading the brief, thenstart; 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:
taskoffered per run by depth, including a run offered less than the tool it was built with;There are unit tests for the policy,
spawnable_byand free types,spawn.py,Delegations.offered/task_offer/startand 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).