Skip to content

feat(delegate): add per-call model/provider/base_url overrides - #17756

Closed
mddragon18 wants to merge 1 commit into
NousResearch:mainfrom
mddragon18:jarvis-dev
Closed

feat(delegate): add per-call model/provider/base_url overrides#17756
mddragon18 wants to merge 1 commit into
NousResearch:mainfrom
mddragon18:jarvis-dev

Conversation

@mddragon18

@mddragon18 mddragon18 commented Apr 30, 2026

Copy link
Copy Markdown

Summary

Add model, provider, and base_url parameters to delegate_task, allowing per-call overrides for subagents — both at the top level and per-task in batch mode. api_key is kept in the code path (works via delegation.api_key config) but excluded from the schema for security.

Changes

tools/delegate_tool.py:

  • Extended delegate_task() function signature with model, provider, base_url params
  • Added fields to DELEGATE_TASK_SCHEMA at top-level and per-task — api_key excluded from schema to prevent LLM secret leakage
  • Credential resolution happens per-child: per-task > top-level per-call > delegation config > parent inherit
  • All pre-existing code preserved (cost rollup, ACP transport safety, ACP override clearing)

tests/tools/test_delegate.py:

  • Updated test_schema_valid to assert new fields
  • Added test_per_call_model_override

Security

api_key is NOT exposed to the model via the schema. The code path still supports it internally — set via delegation.api_key in config.yaml — but the LLM cannot inject or read it through tool calls.

Example

# Single task with model override
delegate_task(goal="Do X", model="gemini-flash-latest", provider="google")

# Batch with per-task overrides
delegate_task(tasks=[
    {"goal": "Research", "model": "fast-model"},
    {"goal": "Analyze", "model": "reasoning-model", "provider": "openrouter"},
])

Verification

  • All 121 delegate tests pass

Copilot AI review requested due to automatic review settings April 30, 2026 04:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds per-invocation runtime overrides to delegate_task so callers can choose a different model/provider (and related connection settings) for spawned subagents, including per-task overrides in batch mode.

Changes:

  • Extended delegate_task() to accept model, provider, base_url, and api_key, with per-task override precedence in batch delegation.
  • Updated DELEGATE_TASK_SCHEMA to expose the new override fields at both top-level and per-task item level.
  • Added/updated tests covering schema fields, per-call overrides, and subagent cost rollup behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tools/delegate_tool.py Adds per-call/per-task runtime override parameters + schema exposure; includes subagent cost rollup and ACP transport handling updates.
tests/tools/test_delegate.py Updates schema validation assertions and adds coverage for per-call overrides and cost rollup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tools/delegate_tool.py
Comment on lines +1960 to +1969
# Per-child credential resolution: merge per-task overrides on top of effective_cfg
task_cfg = dict(effective_cfg)
if "model" in t:
task_cfg["model"] = t.get("model")
if "provider" in t:
task_cfg["provider"] = t.get("provider")
if "base_url" in t:
task_cfg["base_url"] = t.get("base_url")
if "api_key" in t:
task_cfg["api_key"] = t.get("api_key")
Comment thread tools/delegate_tool.py Outdated
Comment on lines +2478 to +2481
"api_key": {
"type": "string",
"description": "Override API key for the child agent(s).",
},

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check the updated PR again for this

@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have tool/delegate Subagent delegation labels Apr 30, 2026
@mddragon18 mddragon18 changed the title feat(delegate): add per-call model/provider/base_url/api_key overrides feat(delegate): add per-call model/provider/base_url overrides Apr 30, 2026
Add model, provider, and base_url parameters to delegate_task for both
single-task and batch modes. api_key is kept in the code path (works
via delegation.api_key config) but excluded from the schema for security.

Fixes: model=None no longer clears the configured delegation model;
per-child loop uses .get() is not None checks instead of 'in' checks.
@mddragon18

Copy link
Copy Markdown
Author

Rebased onto latest main to resolve merge conflicts. Clean diff now: +117 lines across 2 files.

Changes since initial review:

  • model: None no longer clears the configured delegation model (task dict only includes keys when value is not None)
  • api_key removed from schema for security — still works via delegation.api_key config, but the LLM can not inject or read it through tool calls
  • .get("model") is not None guards in per-child loop as belt-and-suspenders

@gigi206

gigi206 commented May 11, 2026

Copy link
Copy Markdown
Contributor

The patch in delegate_tool.py is correct, but it also needs forwarding in run_agent.py _dispatch_delegate_task() on line 9645. This function intercepts the tool call (delegate_task is in _AGENT_LOOP_TOOLS) and didn't forward model, provider, base_url, api_key to the actual delegate_task() function.

Without this, the parameters arrive in function_args but are never passed through. The comment at line 9648 even says: "New DELEGATE_TASK_SCHEMA fields only need to be added here to reach all invocation paths."

The fix is adding:

model=function_args.get("model"),
provider=function_args.get("provider"),
base_url=function_args.get("base_url"),
api_key=function_args.get("api_key"),

before parent_agent=self in that function.

@teknium1

teknium1 commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

We do not want this

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.

5 participants