The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(delegation): route-field rules follow the route, not the backend's name
Teknium62f2171c69d5
diff --git a/agent/delegation_registry.py b/agent/delegation_registry.pyindex 8219df513e5..76dd071a9bd 100644--- a/agent/delegation_registry.py+++ b/agent/delegation_registry.py@@ -31,7 +31,8 @@ class DefaultDelegationProvider(DelegationProvider):return DEFAULT_BACKENDdef route_task(self, task: Mapping[str, Any], config: Mapping[str, Any]) -> dict[str, Any]:- return dict(config)+ # The delegation section has no speed tier: an unknown key there never becomes one.+ return {k: v for k, v in config.items() if k != "service_tier"}def _reject_builtin_collision(key: str) -> None:diff --git a/tests/tools/test_delegation_route_fields.py b/tests/tools/test_delegation_route_fields.pyindex b3f7fe74169..0c665256f18 100644--- a/tests/tools/test_delegation_route_fields.py+++ b/tests/tools/test_delegation_route_fields.py@@ -1,5 +1,5 @@"""Route fields a delegation backend returns: ``service_tier`` is checked like ``/fast`` and survives child-construction, an unknown ``reasoning_effort`` is a tool error, and every backend-routed result reports what the+construction, an unknown ``reasoning_effort`` is a tool error, and a labelled route's result reports what thechild actually ran on. Real ``delegate_task``, real credential resolution and tier gates; only the child'sconstruction and run are stubbed where a test reads what they were handed.@@ -8,7 +8,6 @@ Tier behaviour ported from #140614 (per-task speed tiers, unsupportedpastels).import jsonimport threading-from types import SimpleNamespacefrom unittest.mock import MagicMock, patchimport pytest@@ -132,23 +131,26 @@ def test_the_delegation_sections_own_effort_keeps_its_warn_and_inherit_rule():assert result == {"status": "built"} and child["reasoning_config"] == {"enabled": True, "effort": "medium"}-def test_backend_routed_result_reports_what_the_child_ran_on():+def test_labelled_route_result_reports_what_the_child_ran_on():from tools.delegate_tool_child_run import _SchemaOutcome, _build_result_entry, _fabricated_entry- _, _, (deep, plain) = _spawn([{**CODEX, "reasoning_effort": "high", "service_tier": "fast", "label": "deep"},- {**LOCAL, "reasoning_effort": "none"}])+ _, _, (deep, local) = _spawn([{**CODEX, "reasoning_effort": "high", "service_tier": "fast", "label": "deep"},+ {**LOCAL, "reasoning_effort": "none", "label": "local"}])entry = _build_result_entry(deep, {"final_response": "ok", "completed": True}, 0, 1.0,_SchemaOutcome(None, None, [], 0))assert entry["route"] == {"label": "deep", "provider": "openai-codex", "model": "gpt-6-astra","reasoning_effort": "high", "service_tier": "fast"}- assert _fabricated_entry(1, "error", "boom", plain)["route"] == {- "provider": "custom", "model": "qwen3-local", "reasoning_effort": "none", "service_tier": "normal"}+ assert _fabricated_entry(1, "error", "boom", local)["route"] == {+ "label": "local", "provider": "custom", "model": "qwen3-local", "reasoning_effort": "none",+ "service_tier": "normal"}-def test_default_routed_result_keeps_its_shape():+def test_unlabelled_route_result_keeps_its_shape():+ """The report sits next to a route's label; a route without one (the default strategy, a backend's fallback+ to the delegation section) leaves the result entry exactly as before."""from tools.delegate_tool_child_run import _SchemaOutcome, _build_result_entry- child = SimpleNamespace(model="m", provider="p", reasoning_config=None, service_tier=None)+ _, _, (child,) = _spawn([{**LOCAL, "reasoning_effort": "high"}])entry = _build_result_entry(child, {"final_response": "ok", "completed": True}, 0, 1.0,_SchemaOutcome(None, None, [], 0))assert "route" not in entrydiff --git a/tools/delegate_tool.py b/tools/delegate_tool.pyindex 8099d485741..55e2338e33f 100644--- a/tools/delegate_tool.py+++ b/tools/delegate_tool.py@@ -490,8 +490,8 @@ def _build_children(if _writer is not None:child.tool_progress_callback = wrap_progress_callback(getattr(child, "tool_progress_callback", None), _writer)child._live_transcript_path = str(_writer.path)- if route.reported:- child._delegate_route = {"label": route.label} if route.label else {}+ if route.label:+ child._delegate_route = {"label": route.label}if live_deleg_id:child._delegation_id = live_deleg_id_ident_ref = getattr(child, "_progress_identity_ref", None)diff --git a/tools/delegate_tool_child_run.py b/tools/delegate_tool_child_run.pyindex 53a0140f99f..34776916689 100644--- a/tools/delegate_tool_child_run.py+++ b/tools/delegate_tool_child_run.py@@ -34,8 +34,8 @@ def _str_or_none(value: Any) -> Optional[str]:return value if isinstance(value, str) else Nonedef _route_report(child: Any) -> Optional[dict[str, Any]]:- """What a backend-routed child ran on: the backend's label plus the resolved provider, model, reasoning- effort (None = the provider's default) and speed tier, read off the built child. None for default routes."""+ """What a labelled route's child ran on: the backend's label plus the resolved provider, model, reasoning+ effort (None = the provider's default) and speed tier, read off the built child. None for unlabelled routes."""route = getattr(child, "_delegate_route", None)if not isinstance(route, dict):return Nonediff --git a/tools/delegate_tool_routes.py b/tools/delegate_tool_routes.pyindex ed0f69cbcaf..d68b019c9f8 100644--- a/tools/delegate_tool_routes.py+++ b/tools/delegate_tool_routes.py@@ -36,7 +36,6 @@ class TaskRoute:reasoning_effort: Any = Noneprofile_home: Optional[Path] = Nonelabel: Optional[str] = None- reported: bool = False # a plugin backend chose it: the result reports what the child ran ondef _active_provider(config: Mapping[str, Any]) -> DelegationProvider:@@ -227,7 +226,7 @@ def _route_to_task_route(route: dict[str, Any], parent_agent: Any, cache: dict[sdef _check_backend_effort(index: int, route: Mapping[str, Any], config: Mapping[str, Any]) -> None:"""A backend's ``reasoning_effort`` must be a known level: a typo is a tool error, never the parent's level.- The ``delegation`` section's own value (a backend returning ``dict(config)``) keeps its warn-and-inherit rule."""+ The ``delegation`` section's own value (the default route, ``dict(config)``) keeps its warn-and-inherit rule."""effort = route.get("reasoning_effort")if route.get("profile") or effort in (None, "") or effort == config.get("reasoning_effort"):return@@ -260,21 +259,15 @@ def resolve_task_routes(task_list: list[dict[str, Any]], config: Mapping[str, An"""One :class:`TaskRoute` per task from the active provider, or ``([], error)``. Identicalroutes resolve credentials once per call (the default provider resolves exactly once, asbefore the seam)."""- from agent.delegation_registry import DEFAULT_BACKENDprovider = _active_provider(config)declared = _declared_parameters(provider, config)- from_backend = provider.name != DEFAULT_BACKENDcache: dict[str, TaskRoute] = {}routes: list[TaskRoute] = []try:for i, task in enumerate(task_list):route = _route_one(provider, declared, i, task, config)- if from_backend:- _check_backend_effort(i, route, config)- else:- route.pop("service_tier", None) # not a delegation-section key: the default route stays today's- resolved = _route_to_task_route(route, parent_agent, cache)- routes.append(replace(resolved, reported=True) if from_backend else resolved)+ _check_backend_effort(i, route, config)+ routes.append(_route_to_task_route(route, parent_agent, cache))except ValueError as exc: # DelegationRouteError, the credential resolver's and the tier check's refusalsreturn [], str(exc)return routes, Nonediff --git a/website/docs/developer-guide/delegation-provider-plugin.md b/website/docs/developer-guide/delegation-provider-plugin.mdindex 0ac084f6908..525de02802a 100644--- a/website/docs/developer-guide/delegation-provider-plugin.md+++ b/website/docs/developer-guide/delegation-provider-plugin.md@@ -122,7 +122,7 @@ A route is a dict with any of:Unknown keys are dropped. On a profile route, `service_tier` and `reasoning_effort` are ignored too.-Every result entry of a task your backend routed carries `route`: the `label` plus what the child+Every result entry of a task whose route has a `label` carries `route`: the label plus what the childactually ran on, read off the built child:```json@@ -130,8 +130,8 @@ actually ran on, read off the built child:"reasoning_effort": "high", "service_tier": "fast"}```-`reasoning_effort` is `null` when the provider's default applies. Results of the built-in `default`-strategy carry no `route`, so their shape is unchanged.+`reasoning_effort` is `null` when the provider's default applies. A route without a label (the+`default` strategy, your fallback to `dict(config)`) leaves the result entry unchanged.## Prompt caching