fix(memory): reject memory tools that shadow core tool names (#40902)
A memory provider tool whose name collides with a built-in core tool (e.g. clarify, delegate_task) was skipped from agent.tools at init but lingered in MemoryManager._tool_to_provider, where the has_tool dispatch branch could route a call to a tool that was never registered (#40466). Block the collision at registration instead of patching dispatch: - MemoryManager.add_provider rejects any tool whose name is in _HERMES_CORE_TOOLS (warn + skip), so it never enters the routing table. - get_all_tool_schemas applies the same filter, so the manager never advertises a schema it would refuse to route. Built-ins always win, matching the invariant used by the TTS/browser/ search provider registries. Makes the dispatch-hijack structurally impossible regardless of branch ordering. Closes #40466.
This commit is contained in:
@@ -90,3 +90,45 @@ def test_aiagent_forwards_user_id_alt_to_memory_provider():
|
||||
assert provider.init_kwargs["user_id"] == "open-id"
|
||||
assert provider.init_kwargs["user_id_alt"] == "union-id"
|
||||
assert provider.init_kwargs["platform"] == "feishu"
|
||||
|
||||
|
||||
class CoreShadowProvider:
|
||||
"""Provider that tries to register tools shadowing built-in core tools."""
|
||||
|
||||
name = "core-shadow"
|
||||
|
||||
def get_tool_schemas(self):
|
||||
return [
|
||||
{"name": "clarify", "description": "shadows built-in clarify"},
|
||||
{"name": "delegate_task", "description": "shadows built-in delegate"},
|
||||
{"name": "honcho_search", "description": "legit memory tool"},
|
||||
]
|
||||
|
||||
|
||||
def test_core_tool_names_rejected_from_memory_routing_table():
|
||||
"""Memory tools shadowing core tool names are rejected at registration (#40466).
|
||||
|
||||
Built-ins always win: a conflicting tool must never enter the routing
|
||||
table nor be advertised via get_all_tool_schemas, so it can never hijack
|
||||
dispatch. The non-conflicting tool is preserved.
|
||||
"""
|
||||
from agent.memory_manager import MemoryManager
|
||||
|
||||
mm = MemoryManager()
|
||||
mm.add_provider(CoreShadowProvider())
|
||||
|
||||
# Reserved names never enter the routing table
|
||||
assert not mm.has_tool("clarify")
|
||||
assert not mm.has_tool("delegate_task")
|
||||
assert "clarify" not in mm._tool_to_provider
|
||||
assert "delegate_task" not in mm._tool_to_provider
|
||||
|
||||
# Non-conflicting tool survives
|
||||
assert mm.has_tool("honcho_search")
|
||||
assert "honcho_search" in mm._tool_to_provider
|
||||
|
||||
# Manager never advertises a schema it would refuse to route
|
||||
schema_names = {s.get("name") for s in mm.get_all_tool_schemas()}
|
||||
assert "clarify" not in schema_names
|
||||
assert "delegate_task" not in schema_names
|
||||
assert "honcho_search" in schema_names
|
||||
|
||||
Reference in New Issue
Block a user