Skip to content

The agent that grows with you

feat(delegation): results report the route a backend-routed child ran on

Teknium827c68e26a93
diff --git a/tests/tools/test_delegation_route_fields.py b/tests/tools/test_delegation_route_fields.py
index 377b2671552..b3f7fe74169 100644
--- a/tests/tools/test_delegation_route_fields.py
+++ b/tests/tools/test_delegation_route_fields.py
@@ -8,6 +8,7 @@ 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
@@ -129,3 +130,25 @@ def test_the_delegation_sections_own_effort_keeps_its_warn_and_inherit_rule():
"""A backend that falls back to ``dict(config)`` carries the config's value; config behaviour is unchanged."""
result, (child,), _ = _spawn([None], cfg={"reasoning_effort": "hgih"})
assert result == {"status": "built"} and child["reasoning_config"] == {"enabled": True, "effort": "medium"}
+
+
+def test_backend_routed_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"}])
+ 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"}
+
+
+def test_default_routed_result_keeps_its_shape():
+ from tools.delegate_tool_child_run import _SchemaOutcome, _build_result_entry
+
+ child = SimpleNamespace(model="m", provider="p", reasoning_config=None, service_tier=None)
+ 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 1545d60345e..8099d485741 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.label:
- child._delegate_route_label = route.label
+ if route.reported:
+ child._delegate_route = {"label": route.label} if route.label else {}
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 ad1b3dca9a8..53a0140f99f 100644
--- a/tools/delegate_tool_child_run.py
+++ b/tools/delegate_tool_child_run.py
@@ -33,12 +33,31 @@ def _num(value: Any, default: int = 0) -> int:
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."""
+ route = getattr(child, "_delegate_route", None)
+ if not isinstance(route, dict):
+ return None
+ from agent.fast_mode import service_tier_word
+ reasoning = getattr(child, "reasoning_config", None)
+ effort = None
+ if isinstance(reasoning, dict):
+ effort = reasoning.get("effort") if reasoning.get("enabled", True) else "none"
+ return {**route, "provider": _str_or_none(getattr(child, "provider", None)),
+ "model": _str_or_none(getattr(child, "model", None)), "reasoning_effort": _str_or_none(effort),
+ "service_tier": service_tier_word(getattr(child, "service_tier", None))}
+
def _fabricated_entry(idx: int, status: str, error: str, child: Any, duration: float = 0) -> dict[str, Any]:
"""Result entry for a child that raised, never finished, or was abandoned."""
- return {
+ entry = {
"task_index": idx, "status": status, "summary": None, "error": error, "api_calls": 0,
"duration_seconds": duration, "_child_role": getattr(child, "_delegate_role", None),
}
+ route = _route_report(child)
+ if route is not None:
+ entry["route"] = route
+ return entry
def _append_missed_steer(entry: dict[str, Any], late_steer: Optional[str]) -> None:
"""Record steer text that won the race with the child's failure/timeout."""
@@ -619,9 +638,9 @@ def _build_result_entry(
# Model-visible per-delegation spend (unlike _child_cost_usd above).
entry["cost_usd"] = round(entry["_child_cost_usd"], 6)
entry["cost_status"] = _cost_status if isinstance(_cost_status, str) and _cost_status else "unknown"
- _route_label = getattr(child, "_delegate_route_label", None)
- if isinstance(_route_label, str) and _route_label:
- entry["route"] = _route_label # the delegation provider's label (profile name, model-map option)
+ _route = _route_report(child)
+ if _route is not None:
+ entry["route"] = _route
if status == "failed":
entry["error"] = result.get("error", "Subagent did not produce a response.")
# Classified reason from the child loop (e.g. "rate_limit", "billing")
diff --git a/tools/delegate_tool_routes.py b/tools/delegate_tool_routes.py
index 2d06e00ccbc..ed0f69cbcaf 100644
--- a/tools/delegate_tool_routes.py
+++ b/tools/delegate_tool_routes.py
@@ -36,6 +36,7 @@ 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:
@@ -272,7 +273,8 @@ def resolve_task_routes(task_list: list[dict[str, Any]], config: Mapping[str, An
_check_backend_effort(i, route, config)
else:
route.pop("service_tier", None) # not a delegation-section key: the default route stays today's
- routes.append(_route_to_task_route(route, parent_agent, cache))
+ resolved = _route_to_task_route(route, parent_agent, cache)
+ routes.append(replace(resolved, reported=True) if from_backend else resolved)
except ValueError as exc: # DelegationRouteError, the credential resolver's and the tier check's refusals
return [], str(exc)
return routes, None