Skip to content

feat(delegate): per-task and top-level model override for cost-aware routing#25813

Open
ChronaSystems wants to merge 1 commit into
NousResearch:mainfrom
ChronaSystems:feat/delegate-task-per-task-model
Open

feat(delegate): per-task and top-level model override for cost-aware routing#25813
ChronaSystems wants to merge 1 commit into
NousResearch:mainfrom
ChronaSystems:feat/delegate-task-per-task-model

Conversation

@ChronaSystems

Copy link
Copy Markdown

Summary

delegate_task already supports rich subagent fan-out, but every child currently inherits the parent's model (or delegation.model when configured). This PR adds an optional model field 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:

delegate_task(tasks=[
    {"goal": "list files in /tmp",       "model": "anthropic/claude-haiku-4"},
    {"goal": "refactor auth module",     "model": "anthropic/claude-opus-4.7"},
    {"goal": "summarise the changelog",  "model": "anthropic/claude-haiku-4"},
])

Why

Right now the only way to use a different model for a subagent is to change delegation.model for the whole session — which means trivial subtasks pay opus prices alongside the deep ones. Per-task model override lets a single delegate_task call send the cheap legwork to haiku and the hard reasoning to opus, which is exactly the pattern users keep building manually around delegate_task today.

Precedence

per-task  tasks[i].model
    ↓
top-level model arg
    ↓
delegation.model config (creds["model"])
    ↓
parent_agent.model (existing fallback inside _build_child_agent)

When delegation.provider is 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 where delegation.provider trumps inherited credentials.

Empty string, whitespace-only, and non-string model values fall back to the next level in the precedence chain rather than crashing.

What changed

  • tools/delegate_tool.py — added model: Optional[str] = None to delegate_task() signature, threaded it into the synthesized single-task dict and the batch loop, plumbed it through registry.register(...handler=...), and added model properties 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:
    • schema exposure (static + dynamic overrides)
    • all four precedence rules (per-task wins, top-level wins, batch propagation, parent fallback)
    • delegation.provider trumps both per-task and top-level overrides
    • validation edge cases (empty / whitespace / non-string / trimming)
    • registry handler forwards args["model"]

Test results

$ pytest tests/tools/test_delegate*.py
153 passed in 17.13s

That's 137 existing delegate tests + 16 new ones, all green. Zero regressions in:

  • tests/tools/test_delegate.py
  • tests/tools/test_delegate_composite_toolsets.py
  • tests/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_set about tools.video_generation_tool being in the discovered set — it fails on unmodified main too, so it's not from this PR.)

Notes for reviewers

  • Backwards compatibility: the new model parameter is fully optional and defaults to None. Calls that don't pass it behave bit-for-bit identically to before — every existing test still passes.
  • No new dependencies.
  • No schema breakage: delegate_task's parameters.required list is unchanged.
  • The _provider_override_active gate is intentional. Without it, a user with delegation.provider: minimax-cn who also passed model="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"]).
  • The dynamic schema rebuild path (_build_dynamic_schema_overrides) is untouched logic-wise; it deep-copies the static properties dict so the new model field 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!

…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.
@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have tool/delegate Subagent delegation labels May 14, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of open PRs #3172, #17756, #25530 — all implement per-task model/provider override on delegate_task. Tracking issue: #14974. At least 4+ competing PRs exist for this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low — cosmetic, nice to have tool/delegate Subagent delegation type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants