Skip to content

The agent that grows with you

fix(delegation): the undeclared-parameter refusal names the saved backend

Teknium1c6cd5b8ec84
diff --git a/agent/delegation_backends.py b/agent/delegation_backends.py
index 34fbf6cb6b5..ac0df5f2d94 100644
--- a/agent/delegation_backends.py
+++ b/agent/delegation_backends.py
@@ -6,7 +6,8 @@ session's next ``delegate_task`` call. The ``delegate_task`` schema (a backend's
is part of the cached prompt and keeps following config.yaml, so a backend's own task parameters
appear in sessions started after a global switch. After a session switch the model may still send the
previous backend's parameters: each such task is refused (naming the session's backend, the parameter,
-and ``/new`` or ``/delegation <backend>`` as the fix), never run on the new backend's default route.
+and the fix: ``/delegation <backend> --global`` then ``/new``, since ``/new`` starts on the saved backend, or
+``/delegation <saved backend>`` back), never run on the new backend's default route.
Session keys are the ``session_key`` a plugin command handler receives: the gateway/TUI route key, or
the session id on the classic in-process CLI. ``delegate_task`` resolves the same key from the turn's
diff --git a/tests/tools/test_delegation_backends.py b/tests/tools/test_delegation_backends.py
index d219833244f..b11d71041ae 100644
--- a/tests/tools/test_delegation_backends.py
+++ b/tests/tools/test_delegation_backends.py
@@ -224,7 +224,8 @@ def test_a_session_backend_switch_routes_that_session_only_and_global_persists(t
{"goal": "route me on a tier", "tier": "a"}],
parent_agent=_parent("chat-a")))["error"]
owned, unknown = error.split(" Task 1: ")
- assert "backend is 'default'" in owned and "`/delegation probe-options`" in owned and "/new" in owned
+ assert "backend is 'default'" in owned and "`/delegation default --global` then `/new`" in owned
+ assert "`/delegation probe-options` to switch this session back to the saved backend" in owned
assert "'tier'" in unknown and "no installed delegation backend" in unknown and len(recorded) == 3
with pytest.raises(ValueError, match="'nope' is not installed"):
set_session_backend("chat-a", "nope")
@@ -271,10 +272,12 @@ def test_a_session_switch_refuses_a_task_using_the_previous_backends_parameter(t
], parent_agent=_parent("chat-a")))
refused, plain, work = out["results"]
assert refused["status"] == "error" and refused["route"] == {"backend": "probe-profiles", "refused": True}
+ # /new starts on the saved backend, so the advice persists the session's pick first or names the saved one.
assert refused["error"] == (
"Task 0: this session's delegation backend is 'probe-profiles', which does not take 'option' (declared by "
- "'probe-options'), so this task was not started. Start a new session with /new for a delegate_task tool "
- "that matches 'probe-profiles', or switch this session back with `/delegation probe-options`.")
+ "'probe-options'), so this task was not started. Run `/delegation probe-profiles --global` then `/new` for "
+ "a session whose delegate_task choices match 'probe-profiles', or `/delegation probe-options` to switch "
+ "this session back to the saved backend.")
assert plain["status"] == work["status"] == "completed"
assert [b["model"] for b in recorded] == ["profile-default-model", "work-model"]
finally:
diff --git a/tools/delegate_tool_routes.py b/tools/delegate_tool_routes.py
index 0f314c20af7..555d86a7355 100644
--- a/tools/delegate_tool_routes.py
+++ b/tools/delegate_tool_routes.py
@@ -268,32 +268,36 @@ def _check_backend_effort(index: int, route: Mapping[str, Any], config: Mapping[
f"Use none or one of: {', '.join(VALID_REASONING_EFFORTS)}.")
-def _undeclared_error(provider: DelegationProvider, index: int, names: list[str], config: Mapping[str, Any]) -> str:
+def _undeclared_error(provider: DelegationProvider, index: int, names: list[str], config: Mapping[str, Any],
+ saved: str) -> str:
"""Why a task carrying parameters the session's backend does not declare is refused. The schema follows
config.yaml for the whole session (cached prompt), so after a ``/delegation`` switch the model can still send
- the previous backend's parameters; dropping them would run the task on this backend's default route."""
+ the previous backend's parameters; dropping them would run the task on this backend's default route.
+ ``/new`` starts on the saved backend (``saved``), so the fix persists the session's pick first or names it."""
from agent.delegation_registry import _registry
+ active = provider.name
listed = ", ".join(f"'{name}'" for name in names)
- owners = sorted({other.name for other in _registry.list_providers() if other.name != provider.name
+ owners = sorted({other.name for other in _registry.list_providers() if other.name != active
and set(names) & set(_declared_parameters(other, config))})
- head = f"Task {index}: this session's delegation backend is '{provider.name}', which does not take {listed}"
+ head = f"Task {index}: this session's delegation backend is '{active}', which does not take {listed}"
+ if saved == active:
+ fix = f"start a new session with /new for delegate_task choices that match '{active}'"
+ else:
+ fix = (f"run `/delegation {active} --global` then `/new` for a session whose delegate_task choices match "
+ f"'{active}', or `/delegation {saved}` to switch this session back to the saved backend")
if owners:
- back = " or ".join(f"`/delegation {owner}`" for owner in owners)
quoted = ", ".join(f"'{owner}'" for owner in owners)
- return (f"{head} (declared by {quoted}), so this task was not started. Start a "
- f"new session with /new for a delegate_task tool that matches '{provider.name}', or switch this "
- f"session back with {back}.")
+ return f"{head} (declared by {quoted}), so this task was not started. {fix[0].upper()}{fix[1:]}."
return (f"{head}, and no installed delegation backend does, so this task was not started. Resend it without "
- f"{listed}; if this session's delegate_task tool offers {listed}, start a new session with /new for a "
- f"tool that matches '{provider.name}'.")
+ f"{listed}; if this session's delegate_task tool offers {listed}, {fix}.")
def _route_one(provider: DelegationProvider, declared: dict[str, dict[str, Any]], index: int,
- task: Mapping[str, Any], config: Mapping[str, Any]) -> dict[str, Any]:
+ task: Mapping[str, Any], config: Mapping[str, Any], saved: str) -> dict[str, Any]:
undeclared = sorted(name for name, value in task.items()
if value is not None and name not in declared and name not in RESERVED_TASK_PARAMETERS)
if undeclared:
- raise DelegationRouteError(_undeclared_error(provider, index, undeclared, config))
+ raise DelegationRouteError(_undeclared_error(provider, index, undeclared, config, saved))
params = {name: task[name] for name in declared if task.get(name) is not None}
for name, value in params.items():
error = _param_error(index, name, value, declared[name])
@@ -316,6 +320,8 @@ def resolve_task_routes(task_list: list[dict[str, Any]], config: Mapping[str, An
backend). A task the backend cannot route gets a route with ``error`` set; its siblings are unaffected.
Identical routes resolve credentials once per call (the default backend resolves exactly once)."""
from agent.delegation_backends import session_delegation_config
+ from agent.delegation_registry import configured_backend
+ saved = configured_backend(config)
config = session_delegation_config(config, parent_agent)
try:
provider = _active_provider(config)
@@ -326,7 +332,7 @@ def resolve_task_routes(task_list: list[dict[str, Any]], config: Mapping[str, An
routes: list[TaskRoute] = []
for i, task in enumerate(task_list):
try:
- route = _route_one(provider, declared, i, task, config)
+ route = _route_one(provider, declared, i, task, config, saved)
_check_backend_effort(i, route, config)
routes.append(_route_to_task_route(route, parent_agent, cache, config, provider.name))
except ValueError as exc: # DelegationRouteError, the credential resolver's and the tier check's refusals
diff --git a/website/docs/developer-guide/delegation-provider-plugin.md b/website/docs/developer-guide/delegation-provider-plugin.md
index 7a9718e7c7c..1d4b62e37d9 100644
--- a/website/docs/developer-guide/delegation-provider-plugin.md
+++ b/website/docs/developer-guide/delegation-provider-plugin.md
@@ -176,11 +176,14 @@ of dropping it and running the task on the new backend's default route:
```text
Task 0: this session's delegation backend is 'profile_routes', which does not take 'option' (declared by
-'model_map'), so this task was not started. Start a new session with /new for a delegate_task tool that
-matches 'profile_routes', or switch this session back with `/delegation model_map`.
+'model_map'), so this task was not started. Run `/delegation profile_routes --global` then `/new` for a
+session whose delegate_task choices match 'profile_routes', or `/delegation model_map` to switch this
+session back to the saved backend.
```
-A parameter no installed backend declares is refused the same way, with "Resend it without ..." as the fix.
+`/new` starts on the saved backend (`delegation.backend`), so the fix persists the session's pick first or
+names the saved one. When the session follows `config.yaml` (it changed mid-session), the fix is just `/new`.
+A parameter no installed backend declares is refused the same way, with "Resend it without ..." first.
## Prompt caching
diff --git a/website/docs/user-guide/features/delegation.md b/website/docs/user-guide/features/delegation.md
index b2989c0cf8a..659927389bf 100644
--- a/website/docs/user-guide/features/delegation.md
+++ b/website/docs/user-guide/features/delegation.md
@@ -331,7 +331,7 @@ The model only ever sees the names and descriptions you configured, never raw pr
**Failures are explicit, never a silent switch.** If the selected backend is missing (plugin not installed or disabled) or reports it cannot run, `delegate_task` returns a tool error naming the backend and the fix, and no subagent starts; it never quietly runs the children on the default route. Within a batch, a task its backend cannot route (an unknown option, a parameter the selected backend does not take, a profile that does not exist, a `service_tier` the route does not offer, an unknown `reasoning_effort`, missing credentials) is refused alone: its result entry has `status: "error"`, the reason, and `route.refused: true`, while the other tasks run. A model route without its own `fallback_providers` uses `delegation.fallback_providers`; `fallback_providers: []` on the route disables fallback for it. A profile route uses that profile's own fallback chain.
-**Switching back.** `/delegation default` (from the `advanced-delegation` plugin) switches the current session to the default backend, and `/delegation <backend> --global` writes `delegation.backend` to `config.yaml`, following the `/model` convention. A session switch changes routing from the next `delegate_task` call and lasts until the conversation ends (`/new`, `/resume`, an automatic reset); the per-task parameters the model sees (option or profile names) follow `config.yaml` and change at the next session, because the tool list is part of the cached prompt. Until then, a task that sends the previous backend's parameter (an `option` after switching to `profile_routes`) is refused with a message naming the session's backend, the parameter and the fix (`/new`, or `/delegation <backend>` back); it never runs on the new backend's default route. Without the plugin, `hermes config set delegation.backend default` restores the default.
+**Switching back.** `/delegation default` (from the `advanced-delegation` plugin) switches the current session to the default backend, and `/delegation <backend> --global` writes `delegation.backend` to `config.yaml`, following the `/model` convention. A session switch changes routing from the next `delegate_task` call and lasts until the conversation ends (`/new`, `/resume`, an automatic reset); the per-task parameters the model sees (option or profile names) follow `config.yaml` and change at the next session, because the tool list is part of the cached prompt. Until then, a task that sends the previous backend's parameter (an `option` after switching to `profile_routes`) is refused with a message naming the session's backend, the parameter and the fix (`/delegation <backend> --global` then `/new`, because `/new` starts on the saved backend, or `/delegation <saved backend>` back); it never runs on the new backend's default route. Without the plugin, `hermes config set delegation.backend default` restores the default.
:::note Profile routes share credentials
Listing a profile in `delegation.backends.profile_routes` lets this profile's subagents use that profile's credentials, credential pool, `SOUL.md` and terminal policy. Only list profiles whose keys and terminal access you are happy for this profile's agent to use.