feat(delegate): per-task and top-level model override for cost-aware routing#25813
Open
ChronaSystems wants to merge 1 commit into
Open
feat(delegate): per-task and top-level model override for cost-aware routing#25813ChronaSystems wants to merge 1 commit into
ChronaSystems wants to merge 1 commit into
Conversation
…routing
delegate_task now accepts an optional 'model' field both per-task (inside
the 'tasks' array) and at the top level. This enables cost-aware fan-out
where each child can be routed to a model that matches its task complexity
without changing the main session's model.
Typical use:
delegate_task(tasks=[
{'goal': 'list files in /tmp', 'model': 'anthropic/claude-haiku-4'},
{'goal': 'refactor auth module', 'model': 'anthropic/claude-opus-4.7'},
])
Precedence (highest to lowest):
1. per-task tasks[i].model
2. top-level model arg
3. delegation.model from config (creds["model"])
4. parent_agent.model (existing fallback inside _build_child_agent)
When delegation.provider is configured, user model overrides are silently
ignored so the delegation-config credential bundle stays coherent (model
+ provider + base_url + api_key all come from the same source). This
matches the existing pattern where delegation.provider trumps inherited
credentials.
Empty / whitespace-only / non-string model values fall back to the next
level in the precedence chain rather than crashing.
Tests: 16 new tests in tests/tools/test_delegate_model_override.py
covering schema exposure, the four precedence rules, the
delegation.provider trump, edge cases (empty, whitespace, wrong type,
trimming), and the registry handler plumbing. Existing 137 delegate
tests still pass; the unrelated test_registry.py::test_matches_previous_manual_builtin_tool_set
failure pre-exists on upstream main.
Collaborator
This was referenced May 21, 2026
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.
Summary
delegate_taskalready supports rich subagent fan-out, but every child currently inherits the parent's model (ordelegation.modelwhen configured). This PR adds an optionalmodelfield at both the per-task level and the top level so callers can route individual children to cheaper or more powerful models without touching the main session.Typical use — cost-aware routing inside a single fan-out:
Why
Right now the only way to use a different model for a subagent is to change
delegation.modelfor the whole session — which means trivial subtasks pay opus prices alongside the deep ones. Per-task model override lets a singledelegate_taskcall send the cheap legwork to haiku and the hard reasoning to opus, which is exactly the pattern users keep building manually arounddelegate_tasktoday.Precedence
When
delegation.provideris configured, user-supplied model overrides are silently ignored so the delegation-config credential bundle (provider+base_url+api_key+model) stays coherent. This matches the existing pattern wheredelegation.providertrumps inherited credentials.Empty string, whitespace-only, and non-string
modelvalues fall back to the next level in the precedence chain rather than crashing.What changed
tools/delegate_tool.py— addedmodel: Optional[str] = Nonetodelegate_task()signature, threaded it into the synthesized single-task dict and the batch loop, plumbed it throughregistry.register(...handler=...), and addedmodelproperties to both the per-task and top-level schema slots with descriptions that teach the LLM what they're for (e.g. "trivial subtasks → haiku, deep reasoning → opus").tests/tools/test_delegate_model_override.py— new file, 16 tests:delegation.providertrumps both per-task and top-level overridesargs["model"]Test results
That's 137 existing delegate tests + 16 new ones, all green. Zero regressions in:
tests/tools/test_delegate.pytests/tools/test_delegate_composite_toolsets.pytests/tools/test_delegate_toolset_scope.py(There's one pre-existing failure in
tests/tools/test_registry.py::TestBuiltinDiscovery::test_matches_previous_manual_builtin_tool_setabouttools.video_generation_toolbeing in the discovered set — it fails on unmodifiedmaintoo, so it's not from this PR.)Notes for reviewers
modelparameter is fully optional and defaults toNone. Calls that don't pass it behave bit-for-bit identically to before — every existing test still passes.delegate_task'sparameters.requiredlist is unchanged._provider_override_activegate is intentional. Without it, a user withdelegation.provider: minimax-cnwho also passedmodel="anthropic/claude-haiku-4"would silently get an Anthropic model name on a MiniMax provider — broken credentials. Better to silently ignore the override and stick with the provider-pinned bundle (creds["model"])._build_dynamic_schema_overrides) is untouched logic-wise; it deep-copies the staticpropertiesdict so the newmodelfield rides along automatically.I'm happy to split this into separate commits, rename anything, or rework the precedence rule if you'd prefer a different default. Thanks for considering it!