Skip to content

fix(delegate): respect model selection for sub-agents (fixes #12440)#12503

Open
PratikRai0101 wants to merge 3 commits into
NousResearch:mainfrom
PratikRai0101:fix/delegate-model-override
Open

fix(delegate): respect model selection for sub-agents (fixes #12440)#12503
PratikRai0101 wants to merge 3 commits into
NousResearch:mainfrom
PratikRai0101:fix/delegate-model-override

Conversation

@PratikRai0101

Copy link
Copy Markdown
Contributor

What does this PR do?
This PR fixes the context-length errors occurring during delegation by ensuring delegate_task honors explicitly configured models for sub-agents.

It enforces a strict model selection precedence: acp_args → HERMES_MODEL env var → config.delegation.model. The selected model is safely forwarded to the child process via both CLI argument injection (--model) and a defensive fallback in the child's os.environ.

Related Issue
Fixes #12440

Type of Change
[x] 🐛 Bug fix (non-breaking change that fixes an issue)

[ ] ✨ New feature (non-breaking change that adds functionality)

[ ] 🔒 Security fix

[ ] 📝 Documentation update

[x] ✅ Tests (adding or improving test coverage)

[ ] ♻️ Refactor (no behavior change)

[ ] 🎯 New skill (bundled or hub)

Changes Made
tools/delegate_tool.py: Extracted the ACP subprocess spawning logic into a dedicated _launch_subagent function. Wired it into the delegate_task execution path for ACP-backed children. Ensured subprocess.run executes securely using lists (strictly no shell=True).

tests/tools/test_delegate_model_forwarding.py: Added a new test suite utilizing pytest and monkeypatch to intercept the subprocess.run call. Tests validate precedence logic, flag parsing (--model, -m, --model=), and environment injection without actual execution.

How to Test
Unit Tests: Run pytest tests/tools/test_delegate_model_forwarding.py -v. Ensure all 8 parametrized mocks pass.

Precedence Validation: Set delegation.model in config.yaml to one model, export HERMES_MODEL as another, and pass a third via acp_args. Trigger a sub-agent spawn and verify via process logs that the acp_args model wins the collision.

Regression Check: Run pytest tests/tools/test_delegate_toolset_scope.py to ensure existing delegation logic remains unbroken.

Checklist
Code
[x] I've read the Contributing Guide

[x] My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)

[x] I searched for existing PRs to make sure this isn't a duplicate

[x] My PR contains only changes related to this fix/feature (no unrelated commits)

[x] I've run pytest tests/ -q and all tests pass (Note: Delegation-specific tests pass locally. The ~72 failures in the full suite are due to upstream baseline drift, e.g., Camofox config schema version bumps, unrelated to this PR).

[x] I've added tests for my changes (required for bug fixes, strongly encouraged for features)

[x] I've tested on my platform: Arch Linux

Documentation & Housekeeping
[x] I've updated relevant documentation (README, docs/, docstrings) — or N/A

[x] I've updated cli-config.yaml.example if I added/changed config keys — or N/A

[x] I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A

[x] I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A

[x] I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

Test Execution Output:

$ ./venv/bin/pytest tests/tools/test_delegate_model_forwarding.py -q -r a
........ [100%] 8 passed in 0.84s

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists tool/delegate Subagent delegation labels Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Medium — degraded but workaround exists tool/delegate Subagent delegation type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Sub-agent model configuration is ignored, causing persistent context window errors

2 participants