Skip to content

The agent that grows with you

fix(delegation): /new starts the chat on the saved delegation backend

Teknium06e36326f655
diff --git a/gateway/run_agent_cache.py b/gateway/run_agent_cache.py
index d1d86da165e..dd51a6f273b 100644
--- a/gateway/run_agent_cache.py
+++ b/gateway/run_agent_cache.py
@@ -411,6 +411,9 @@ class GatewayAgentCacheMixin:
state = self._peek_session_state(session_key)
if state is not None:
state.conversation.clear()
+ # A /delegation backend pick is conversation-scoped like /model's, but lives with the backends.
+ from agent.delegation_backends import set_session_backend
+ set_session_backend(session_key, None)
# Legacy plain-dict stores still in _CONVERSATION_SCOPED_STATE (not yet folded into
# SessionState), e.g. _pending_model_notes. SessionState-backed names resolve to MutableMapping
# views (not dict), so the isinstance(dict) guard skips them — already handled above.
diff --git a/tests/gateway/test_session_model_reset.py b/tests/gateway/test_session_model_reset.py
index 40c2903bd84..7b8209f85a4 100644
--- a/tests/gateway/test_session_model_reset.py
+++ b/tests/gateway/test_session_model_reset.py
@@ -100,3 +100,22 @@ async def test_new_command_only_clears_own_session():
assert other_key in runner._session_reasoning_overrides
assert session_key not in runner._pending_model_notes
assert other_key in runner._pending_model_notes
+
+
+async def test_new_command_drops_the_sessions_delegation_backend_override():
+ """A ``/delegation <mode>`` pick is session-scoped like ``/model``: /new starts the chat on config.yaml's backend
+ (the route key survives /new), and other chats keep theirs."""
+ from agent.delegation_backends import get_session_backend, set_session_backend
+
+ runner = _make_runner()
+ session_key = build_session_key(_make_source())
+ set_session_backend(session_key, "default")
+ set_session_backend("other_session_key", "default")
+ try:
+ await runner._handle_reset_command(_make_event("/new"))
+ assert get_session_backend(session_key) is None
+ assert get_session_backend("other_session_key") == "default"
+ finally:
+ set_session_backend(session_key, None)
+ set_session_backend("other_session_key", None)
diff --git a/website/docs/user-guide/features/delegation.md b/website/docs/user-guide/features/delegation.md
index cce6700f0fd..5dc4f7aabfe 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 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; the per-task parameters the model sees (option or profile names) follow `config.yaml` and change at the next session. 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. 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.