Skip to content

Sub-agents: model choices and a delegation's tools - #338

Merged
shoom1 merged 11 commits into
developfrom
feature/subagent-choices
Nov 22, 2026
Merged

shoom1 merged 11 commits into
developfrom
feature/subagent-choices

Conversation

@shoom1

@shoom1 shoom1 commented Nov 22, 2026

Copy link
Copy Markdown
Owner

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 (YAML model_choices: [fast]) names the models a delegation may pick: references or role names. The root sets none.
  • Each choice is resolved the way the type's own model is (its settings and the thinking effort) and budgeted with the agents' models, before any service is built. A choice the type's settings cannot take fails startup, naming the agent. The settings' static check, the catalog's references and the computed roles include the choices.
  • Each choice is its type built once more on that model, at initialization: on ADK an agent and a runner of its own (its own MCP connections), on Deep Agents a graph of its own. A run on a choice sends its requests to the choice's model, and uses that model's context numbers for the fit guard, the overflow handler and summarization. ADK's raw LLM log names the choice. The release closes each build, and a model switch rebuilds them.

task's tools and model

  • tools is on every task call: names of the agent's own tools, to narrow the run ([] keeps none of them; left out, all). model appears when a type it offers has choices, and its type line says model choices: <a>, <b>.
  • A name the type does not have, a model that is not one of its choices, or model for a type without choices is the call's error result, with no run started and none counted. A static child narrows too.
  • A narrowed run is offered only those tools, plus its plan tools and the delegation tools. A call of any other tool gets the unknown-tool answer, on both backends (ADK's RunControlPlugin, Deep Agents' RunControlMiddleware).
  • An MCP server whose tools cannot be listed is said as such: "The tools of '' could not be listed just now (...); try again."

The records

  • An instance keeps its tools and model (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.
  • A follow-up whose type no longer has that choice or those tools is refused, naming what is gone. Records from before load unchanged.
  • /agents <id> shows an instance's model and tools; the instance view's context and /status follow its model.

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

  • a narrowed run (offered only its tools, a call of another refused), and a static child narrowed;
  • a run on a choice (its requests, budget and usage on the choice's model);
  • the refusals, and a follow-up after a restart on the same model and tools;
  • each build closed by cleanup and rebuilt by a model switch, MCP servers included.

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).

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.
@shoom1
shoom1 merged commit 1838dfe into develop Nov 22, 2026
6 checks passed
@shoom1
shoom1 deleted the feature/subagent-choices branch November 22, 2026 20:54
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