Skip to content

feat: add named delegation routing profiles#7201

Open
nepenth wants to merge 2 commits into
NousResearch:mainfrom
nepenth:feat/delegation-routing-profiles
Open

feat: add named delegation routing profiles#7201
nepenth wants to merge 2 commits into
NousResearch:mainfrom
nepenth:feat/delegation-routing-profiles

Conversation

@nepenth

@nepenth nepenth commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Description

Refreshes PR #7201 onto the current main line and keeps the scope limited to named delegation routing profiles only.

This PR now contains ONLY these files:

  • tools/delegate_tool.py
  • hermes_cli/config.py
  • tests/tools/test_delegate.py
  • tests/hermes_cli/test_config.py

The earlier accidental Matrix history has been removed from the branch.

What this adds

  • named delegation routes under delegation.routes
  • default route selection via delegation.route
  • explicit per-call route selection via delegate_task(..., routing_profile=...)
  • per-task route overrides in batch delegation
  • runtime normalization of legacy flat delegation config into delegation.routes.default
  • validation for delegation route structure and iteration limits
  • fail-fast guard for invalid inherited provider/model combinations

Config shape

delegation:
  route: default
  routes:
    default:
      provider: openai-codex
      model: gpt-5.3-codex
    coding:
      provider: openai-codex
      model: gpt-5.3-codex
    research:
      provider: openai-codex
      model: gpt-5.4
    fast:
      provider: openai-codex
      model: gpt-5.3-codex-spark
  max_iterations: 50
  reasoning_effort: high

Behavior

Route precedence is:

  • per-task routing_profile
  • top-level routing_profile
  • delegation.route
  • fallback to default

Legacy configs like:

delegation:
  model: gpt-5.4
  provider: openai-codex
  base_url: ''
  api_key: ''

are normalized/migrated to:

delegation:
  route: default
  routes:
    default:
      model: gpt-5.4
      provider: openai-codex
      base_url: ''
      api_key: ''

Validation

This PR adds validation for:

  • delegation being a dict
  • delegation.routes being a dict
  • route entry values being mappings
  • route field types (model, provider, base_url, api_key)
  • non-string route keys
  • delegation.route type and missing-route warnings
  • deprecated delegation.route: auto
  • delegation.max_iterations being a positive integer

How to test

Targeted:

~/.hermes/hermes-agent/venv/bin/python -m pytest -q -o 'addopts=' \
  tests/tools/test_delegate.py \
  tests/hermes_cli/test_config.py

Additional relevant slice:

~/.hermes/hermes-agent/venv/bin/python -m pytest -q -o 'addopts=' \
  tests/tools/test_delegate_toolset_scope.py

Local results

  • tests/tools/test_delegate.py tests/hermes_cli/test_config.py128 passed
  • tests/tools/test_delegate_toolset_scope.py5 passed

Note on current upstream baseline

tests/hermes_cli/test_runtime_provider_resolution.py::test_named_custom_provider_uses_providers_dict_when_list_missing
currently fails on clean origin/main as well, so it is not introduced by this PR refresh.

@easyvibecoding

Copy link
Copy Markdown

Related: #9555 (handoff payload to delegated children) and #9557 (adaptive delegation policy) are complementary — this PR gives named targets, those give the data a policy needs to pick between them intelligently.

@nepenth nepenth force-pushed the feat/delegation-routing-profiles branch from 36df89e to a3bd7c8 Compare April 14, 2026 19:33
@nepenth nepenth force-pushed the feat/delegation-routing-profiles branch from a3bd7c8 to 9c02f8f Compare April 14, 2026 20:57
@nidhishgajjar

Copy link
Copy Markdown

Orb Code Review (powered by GLM 5.1 on Orb Cloud)

PR #7201 — feat: add named delegation routing profiles

What it does

Replaces the flat delegation.model/provider/base_url/api_key config with named routing profiles (delegation.routes.<name>), adds per-task routing_profile selection, includes config migration, and comprehensive validation.

Observations

✅ Excellent design

  • Named routes allow different subagent tasks to use different provider:model pairs
  • Per-task routing_profile override in batch mode is well-designed
  • _normalize_delegation_config() bridges legacy flat config and new route-based config seamlessly
  • Config migration in migrate_config() properly moves legacy keys into routes.default

✅ Strong validation and error messages

  • validate_config_structure() checks route types, field types, missing default route, unknown route references
  • Error messages reference the specific route name (e.g., "route 'research'") which aids debugging
  • _validate_inherited_route_model() catches provider/model mismatches early

✅ Comprehensive test coverage

  • Tests cover normalization, route resolution, legacy migration, validation, batch per-task routing, and error cases
  • 8+ new test methods covering edge cases

⚠️ Minor: narrow provider validation
_validate_inherited_route_model() only checks for openai-codex provider with / in the model name:

if parent_provider == "openai-codex" and "/" in configured_model:

This handles one specific case. Other providers may have similar constraints. Consider making this more general or documenting why only openai-codex needs this check.

⚠️ Minor: dual normalization paths
Config normalization exists in two places:

  1. delegate_tool.py::_normalize_delegation_config() — runtime
  2. hermes_cli/config.py::migrate_config() — persistent migration

Both must stay in sync. A comment cross-referencing them would help future maintainers.

Summary: Well-designed feature with thorough migration, validation, and test coverage. Named routing profiles are a significant improvement over flat delegation config. Minor notes about the narrow provider validation and dual normalization paths.

Assessment: approve

@nepenth nepenth force-pushed the feat/delegation-routing-profiles branch from 9c02f8f to 8de4a7f Compare April 15, 2026 00:42
@nepenth

nepenth commented Apr 16, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up after reviewing the current PR comments and re-validating the refreshed branch:

  • The complementary-note comment about [Feature]: Structured handoff payload for delegate_task so children don't re-explore #9555 / [Feature]: Adaptive delegation policy — learn which tasks pay off delegating #9557 doesn't require a code change here; it reads as architectural context, not a gap in this PR.
  • I DID take the Orb review's two minor notes: added explicit cross-reference comments between the runtime delegation normalization path (tools.delegate_tool._normalize_delegation_config) and the persistent migration path (hermes_cli.config.migrate_config), and documented why the inherited-provider model guard is intentionally narrow to the known openai-codex mismatch case.
  • While re-running the targeted validation slice, I also found and fixed a real correctness issue in batch mode: an unknown per-task routing_profile could be masked by credential resolution on an earlier task. The branch now validates all requested routing profiles before any child-agent build/credential work starts, so the batch fails on the intended route error first.

Validation after the follow-up commit:

  • tests/tools/test_delegate.py tests/hermes_cli/test_config.py129 passed
  • tests/tools/test_delegate_toolset_scope.py5 passed

The incremental follow-up commit is PR-scoped only and touches:

  • tools/delegate_tool.py
  • hermes_cli/config.py

@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have tool/delegate Subagent delegation area/config Config system, migrations, profiles labels Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles 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.

4 participants