Repository navigation
Sub-agents: model choices and a delegation's tools - #338
Merged
Merged
Conversation
AgentConfig.model_choices (the agent YAML's model_choices: [fast]) names the models a delegation may run a sub-agent type on instead of its own: references, bare ids or roles. validate_agent_graph refuses them on the root, one that is no tuple or list of texts and a choice named twice; validate_settings parses each and checks its provider's key; the catalog lists their providers at startup and computes a role choice no setting maps.
Each agent's model_choices resolve as its model would (its name, its model_settings), all or nothing with the rest of the models, and get their own context numbers before any service is built: a window too small to work in fails startup as an agent's own does. The manager gives them as choice_models[(agent, choice)] and context_budget(agent, model=choice).
Every task call may give tools, some of the type's own tools, and, when a type it offers has model choices, model, one of them; the type's line in task's description names its choices. read_choices reads both after the brief: anything else is a BriefError naming what it may be. With the default policy task is what it was but for the tools argument.
A first run's AGENT_RUN start may carry the tools and the model choice its delegation gave it (WorkflowEvent.agent_run(tools=, model=)); its instance keeps them (InstanceRecord.tools, .model), exported with the records and read back, records written before them reading as all its tools and its type's own model.
Delegations.delegate reads task's tools against the type's own (its backend's names, tool_names=, asked only for a call that names some) and its model against the type's choices, after the brief: anything else is the call's error result, no run started and none counted. The run, its control (RunControl.tools, keeps: its tools and the state and delegation tools) and its instance get them; every follow-up runs with them, and one whose type no longer has them is refused.
A run whose task call gave tools is offered only those of its type's tools and the ones every run keeps (its plan's, the delegation tools): ADK's RunControlPlugin leaves the others out of the request and its tools_dict, Deep Agents' RunControlMiddleware out of the model request, and a call of one is answered as one of a tool the agent does not have. _agent_tool_names says what tools may name: the agent's own tools, its skill and MCP tools (ADK lists an MCP toolset when first asked).
Each sub-agent type is built once more at initialization for each of its model choices, through the backend's builder: on ADK an agent and a runner of its own, its plugin chain reading the choice's model, kind and context numbers under the type's name; on Deep Agents a graph of its own (build_agent, Variant), summarized by the choice's numbers. A run on a choice runs there, its usage and context the choice's; a model switch builds them again and the release closes them. ADK's raw log names the choice's model too.
/agents <id> shows the model choice and the tools an instance's delegation gave it. Its view's status bar (ctx) and /status read its model and context numbers from its model choice when it runs on one, after a restart too.
The CHANGELOG adds AgentConfig.model_choices and task's tools and model, and says task keeps its schema with the default policy but for the tools argument. The README's AgentConfig and YAML tables, graph checks and sub-agent section, and CLAUDE.md's structure lines and sub-agent paragraph, say the same.
A backend that cannot list a type's tools (ADK, an MCP toolset whose listing failed) raises ToolsUnlistedError, which Delegations answers as the call's error result, no run started or counted, instead of reporting the tools as gone; a message asks for a narrowed instance's tool names once; the configured tool names have one rule. Tests: the release closes a model choice's runner and server, the model is checked before the tools, two messages to a narrowed instance. Style: blank lines, wrapped docstrings, one expression for the overflow plugin's models.
Line breaks only, in the lines this change added that ran past 88 columns: docstrings, comments, calls and imports. Long string literals a test compares are left as they are.
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.
A delegation can now narrow its run to some of its type's tools, and run it on one of the type's cheaper models. It can never widen. Both backends.
Model choices
AgentConfig.model_choices(YAMLmodel_choices: [fast]) names the models a delegation may pick: references or role names. The root sets none.task'stoolsandmodeltoolsis on everytaskcall: names of the agent's own tools, to narrow the run ([]keeps none of them; left out, all).modelappears when a type it offers has choices, and its type line saysmodel choices: <a>, <b>.modelfor a type without choices is the call's error result, with no run started and none counted. A static child narrows too.RunControlPlugin, Deep Agents'RunControlMiddleware).The records
InstanceRecord.tools,.model, from the start event). Its follow-ups, the user's and after a restart, run on the same model with the same tools./agents <id>shows an instance's model and tools; the instance view's context and/statusfollow its model.Tests: written first and seen failing. The shared contract suite runs on both backends and covers:
There are unit tests for the config and the static check, the resolution and budgets,
task's schema, the records,Delegations' checks (including two messages at once to a narrowed instance), the filters and/agents. Reviewed in two parts; two rounds of review fixes.The full offline suite passes in the worktree (10775 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 (1452).