Skip to content

The agent that grows with you

fix: a pinned tool whose parameters changed takes the current definition

teknium1da70c4612495
diff --git a/tests/tools/test_refresh_agent_mcp_tools.py b/tests/tools/test_refresh_agent_mcp_tools.py
index 676c0abebf8..40d05702941 100644
--- a/tests/tools/test_refresh_agent_mcp_tools.py
+++ b/tests/tools/test_refresh_agent_mcp_tools.py
@@ -370,9 +370,18 @@ def test_resume_on_another_surface_restores_the_pinned_tool_bytes(monkeypatch, t
resumed.tools = [_tool("read_file"), _described("tool_search", "Search 5 additional tools.")]
_mcp_agent.restore_agent_tool_prefix(resumed, json.loads(db.get_session("s1")["tool_names"]))
+ # `hermes update` changed read_file's parameters: the handler validates the NEW
+ # signature, so that one tool takes the fresh def while the rest stay pinned.
+ upgraded_read = _tool("read_file")
+ upgraded_read["function"]["parameters"] = {"type": "object", "properties": {"path_v2": {"type": "string"}}}
+ updated = _agent([])
+ updated.tools = [upgraded_read, _described("tool_search", "Search 5 additional tools.")]
+ _mcp_agent.restore_agent_tool_prefix(updated, json.loads(db.get_session("s2")["tool_names"]))
+
assert json.dumps(resumed.tools) == json.dumps(sent.tools)
assert resumed.valid_tool_names == {"read_file", "skill_manage", "tool_search"}
assert stored == 1
+ assert updated.tools == [upgraded_read, *sent.tools[1:]]
def test_reprobe_tool_availability_drops_cached_check_fn_verdicts(monkeypatch):
diff --git a/tools/mcp_tool_agent.py b/tools/mcp_tool_agent.py
index e73e4d21ac9..62307e2772e 100644
--- a/tools/mcp_tool_agent.py
+++ b/tools/mcp_tool_agent.py
@@ -176,14 +176,21 @@ def restore_agent_tool_prefix(agent, saved: list) -> bool:
fresh = {_def_name(t): t for t in fresh_defs}
registered_names = {entry.name for entry in registry.get_all_entries()}
- def _pinned_def(item):
- if isinstance(item, dict):
- return item
- if item in fresh:
- return fresh[item]
- entry = registry.get_entry(item)
+ def _current_def(name):
+ if name in fresh:
+ return fresh[name]
+ entry = registry.get_entry(name)
return None if entry is None else {"type": "function", "function": {**entry.schema, "name": entry.name}}
+ def _pinned_def(item):
+ if not isinstance(item, dict):
+ return _current_def(item)
+ # Surfaces differ only in descriptions; changed PARAMETERS mean the handler's contract
+ # moved (``hermes update``), and the model must not keep calling the old signature.
+ current = _current_def(_def_name(item))
+ params = lambda d: (d.get("function") or {}).get("parameters") # noqa: E731
+ return current if current is not None and params(current) != params(item) else item
+
merged = [d for d in map(_pinned_def, saved) if d and (_def_name(d) in fresh or _def_name(d) in registered_names)]
pinned_names = {_def_name(d) for d in merged}
merged.extend(t for t in fresh_defs if _def_name(t) not in pinned_names)