Skip to content

The agent that grows with you

fix(delegation): refresh pins a backend-only move itself

Tekniumb3555420ba83
diff --git a/agent/delegation_backends.py b/agent/delegation_backends.py
index 918991f839e..f6b8756ca34 100644
--- a/agent/delegation_backends.py
+++ b/agent/delegation_backends.py
@@ -123,11 +123,10 @@ def apply_requested_tool_rebuild(agent: Any) -> bool:
return False
_rebuild_requests.discard(key)
from hermes_cli.observability.shared_metrics_efficiency import record_cache_break
- from tools.mcp_tool_agent import persist_agent_tool_names, refresh_agent_mcp_tools
+ from tools.mcp_tool_agent import refresh_agent_mcp_tools
before = getattr(agent, "tools", None)
refresh_agent_mcp_tools(agent, quiet_mode=True, content_aware=True) # adopts the saved backend, re-pins a change
if agent.tools is before:
- persist_agent_tool_names(agent) # only the backend moved (two backends, one schema): pin it
return False
record_cache_break(agent, "toolset_change")
return True
diff --git a/tools/mcp_tool_agent.py b/tools/mcp_tool_agent.py
index 9b999a67bdf..7a31cb2af75 100644
--- a/tools/mcp_tool_agent.py
+++ b/tools/mcp_tool_agent.py
@@ -145,9 +145,12 @@ def refresh_agent_mcp_tools(
added = _publish_tool_snapshot(
agent, new_defs, new_names, snapshot_generation=snapshot_generation,
staged_engine_names=staged_engine_names, content_aware=content_aware, prefix_registered=prefix_registered)
+ backend_before = getattr(agent, "_delegation_backend", None)
if prefix_registered is None: # a rebuild: the session now routes on the backend its new delegate_task is from
adopt_built_backend(agent, new_defs, built_backend)
if added is None:
+ if getattr(agent, "_delegation_backend", None) != backend_before:
+ persist_agent_tool_names(agent) # only the backend moved (two backends build one schema): pin it
return set()
persist_agent_tool_names(agent) # re-pin so a rebuild after agent-cache eviction restores this order
return added