Skip to content

The agent that grows with you

fix(delegation): one profile resolves once whatever its label

Teknium5d10b1c8d8ab
diff --git a/tests/tools/test_delegation_profile_route.py b/tests/tools/test_delegation_profile_route.py
index 122cacfeab0..f578b88da7d 100644
--- a/tests/tools/test_delegation_profile_route.py
+++ b/tests/tools/test_delegation_profile_route.py
@@ -306,3 +306,16 @@ def test_profile_pinned_to_a_missing_acp_command_is_refused_at_routing(two_profi
routes, error = _resolve_coder_task()
assert routes == []
assert "hermes-test-missing-acp-binary" in (error or "") and "coder" in error
+
+
+def test_one_profile_under_two_labels_resolves_once_and_keeps_each_label(two_profiles):
+ from hermes_cli import runtime_provider
+ from tools.delegate_tool_routes import _route_to_task_route
+
+ cache, parent = {}, _parent()
+ with patch.object(runtime_provider, "resolve_runtime_provider", wraps=runtime_provider.resolve_runtime_provider) as rp:
+ first = _route_to_task_route({"profile": "coder", "label": "reviewer"}, parent, cache)
+ second = _route_to_task_route({"profile": "coder", "label": "fixer"}, parent, cache)
+ assert rp.call_count == 1
+ assert (first.label, second.label) == ("reviewer", "fixer")
+ assert first.creds == second.creds and first.creds["model"] == "coder-model"
diff --git a/tools/delegate_tool_routes.py b/tools/delegate_tool_routes.py
index 42df7e76da8..aef09e9b26a 100644
--- a/tools/delegate_tool_routes.py
+++ b/tools/delegate_tool_routes.py
@@ -13,7 +13,7 @@ import contextlib
import json
import logging
import re
-from dataclasses import dataclass
+from dataclasses import dataclass, replace
from pathlib import Path
from typing import Any, Iterator, Mapping, Optional
@@ -173,7 +173,7 @@ def _refuse_under_worker_snapshot(home: Path) -> None:
f"cannot run as the profile at {home}. Delegate without a profile.")
-def _profile_route(home: Path, label: Optional[str]) -> TaskRoute:
+def _profile_route(home: Path) -> TaskRoute:
"""The profile's own primary route, resolved inside its scope (its config.yaml + secrets). The
child never borrows the launching profile's key, pool, fallback chain or reasoning level."""
from hermes_cli.config import load_config_readonly
@@ -204,22 +204,21 @@ def _profile_route(home: Path, label: Optional[str]) -> TaskRoute:
command=rt.get("command"), args=list(rt.get("args") or []),
)
return TaskRoute(creds, {"fallback_providers": fallback if isinstance(fallback, list) else []},
- ResolvedReasoning(resolve_reasoning_config(cfg, model or "")), home, label)
+ ResolvedReasoning(resolve_reasoning_config(cfg, model or "")), home)
def _route_to_task_route(route: dict[str, Any], parent_agent: Any, cache: dict[str, TaskRoute]) -> TaskRoute:
- key = json.dumps(route, sort_keys=True, default=str)
- if key in cache:
- return cache[key]
label = route.get("label") if isinstance(route.get("label"), str) else None
- if route.get("profile"):
- resolved = _profile_route(_profile_home(route["profile"]), label)
- else:
- from tools.delegate_tool import _resolve_delegation_credentials # the facade is the patch seam
- resolved = TaskRoute(_resolve_delegation_credentials(route, parent_agent), route,
- route.get("reasoning_effort"), None, label)
- cache[key] = resolved
- return resolved
+ # The label is display-only: two labels on one route (or one profile) resolve once.
+ key = json.dumps({k: v for k, v in route.items() if k != "label"}, sort_keys=True, default=str)
+ if key not in cache:
+ if route.get("profile"):
+ cache[key] = _profile_route(_profile_home(route["profile"]))
+ else:
+ from tools.delegate_tool import _resolve_delegation_credentials # the facade is the patch seam
+ cache[key] = TaskRoute(_resolve_delegation_credentials(route, parent_agent), route,
+ route.get("reasoning_effort"), None, None)
+ return replace(cache[key], label=label)
def _route_one(provider: DelegationProvider, declared: dict[str, dict[str, Any]], index: int,