Skip to content

The agent that grows with you

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.py
index 8219df513e5..76dd071a9bd 100644
--- a/agent/delegation_registry.py
+++ b/agent/delegation_registry.py
@@ -31,7 +31,8 @@ class DefaultDelegationProvider(DelegationProvider):
return DEFAULT_BACKEND
def 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.py
index 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 the
child actually ran on. Real ``delegate_task``, real credential resolution and tier gates; only the child's
construction 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 json
import threading
-from types import SimpleNamespace
from unittest.mock import MagicMock, patch
import 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 entry
diff --git a/tools/delegate_tool.py b/tools/delegate_tool.py
index 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.py
index 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 None
def _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 None
diff --git a/tools/delegate_tool_routes.py b/tools/delegate_tool_routes.py
index ed0f69cbcaf..d68b019c9f8 100644
--- a/tools/delegate_tool_routes.py
+++ b/tools/delegate_tool_routes.py
@@ -36,7 +36,6 @@ class TaskRoute:
reasoning_effort: Any = None
profile_home: Optional[Path] = None
label: Optional[str] = None
- reported: bool = False # a plugin backend chose it: the result reports what the child ran on
def _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[s
def _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)``. Identical
routes resolve credentials once per call (the default provider resolves exactly once, as
before the seam)."""
- from agent.delegation_registry import DEFAULT_BACKEND
provider = _active_provider(config)
declared = _declared_parameters(provider, config)
- from_backend = provider.name != DEFAULT_BACKEND
cache: 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 refusals
return [], str(exc)
return routes, None
diff --git a/website/docs/developer-guide/delegation-provider-plugin.md b/website/docs/developer-guide/delegation-provider-plugin.md
index 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 child
actually 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