fix(acp): preserve memory provider tools
This commit is contained in:
@@ -2,10 +2,11 @@
|
||||
|
||||
import json
|
||||
import pytest
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from agent.memory_provider import MemoryProvider
|
||||
from agent.memory_manager import MemoryManager
|
||||
from agent.memory_manager import MemoryManager, inject_memory_provider_tools
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Concrete test provider
|
||||
@@ -1320,38 +1321,25 @@ class TestMemoryToolToolsetGate:
|
||||
causing 10x latency on local models (Qwen3-30B: 1.7s → 42s) and
|
||||
tool-call loops on small models.
|
||||
|
||||
These tests mirror the gate logic in agent/agent_init.py around the
|
||||
memory provider tool injection block. The gate condition is:
|
||||
These tests exercise the shared gate used by agent init and ACP refreshes.
|
||||
The gate condition is:
|
||||
|
||||
enabled_toolsets is None → no filter, inject (backward compat)
|
||||
"memory" in enabled_toolsets → user opted in, inject
|
||||
selected toolsets include memory → user opted in, inject
|
||||
otherwise (incl. []) → skip injection
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def _run_memory_injection(enabled_toolsets, memory_manager):
|
||||
"""Simulate the gated memory-tool injection block from agent_init.py."""
|
||||
tools = []
|
||||
valid_tool_names = set()
|
||||
|
||||
if memory_manager and tools is not None and (
|
||||
enabled_toolsets is None or "memory" in enabled_toolsets
|
||||
):
|
||||
_existing = {
|
||||
t.get("function", {}).get("name")
|
||||
for t in tools
|
||||
if isinstance(t, dict)
|
||||
}
|
||||
for _schema in memory_manager.get_all_tool_schemas():
|
||||
_tname = _schema.get("name", "")
|
||||
if _tname and _tname in _existing:
|
||||
continue
|
||||
tools.append({"type": "function", "function": _schema})
|
||||
if _tname:
|
||||
valid_tool_names.add(_tname)
|
||||
_existing.add(_tname)
|
||||
|
||||
return tools, valid_tool_names
|
||||
"""Run the shared memory-tool injection helper against a fake agent."""
|
||||
fake_agent = SimpleNamespace(
|
||||
_memory_manager=memory_manager,
|
||||
enabled_toolsets=enabled_toolsets,
|
||||
tools=[],
|
||||
valid_tool_names=set(),
|
||||
)
|
||||
inject_memory_provider_tools(fake_agent)
|
||||
return fake_agent.tools, fake_agent.valid_tool_names
|
||||
|
||||
def _mgr_with_tools(self, *tool_names):
|
||||
"""Build a MemoryManager whose providers expose the named tool schemas."""
|
||||
@@ -1376,6 +1364,13 @@ class TestMemoryToolToolsetGate:
|
||||
tools, names = self._run_memory_injection(["terminal", "memory", "web"], mgr)
|
||||
assert "fact_store" in names
|
||||
|
||||
def test_composite_toolset_with_memory_injects(self):
|
||||
"""Composite toolsets that include memory should inject provider tools."""
|
||||
mgr = self._mgr_with_tools("hindsight_recall")
|
||||
tools, names = self._run_memory_injection(["hermes-acp"], mgr)
|
||||
assert "hindsight_recall" in names
|
||||
assert any(t["function"]["name"] == "hindsight_recall" for t in tools)
|
||||
|
||||
def test_empty_toolsets_blocks_injection(self):
|
||||
"""`platform_toolsets: telegram: []` must suppress memory tools. (#5544)"""
|
||||
mgr = self._mgr_with_tools("fact_store")
|
||||
@@ -1384,7 +1379,7 @@ class TestMemoryToolToolsetGate:
|
||||
assert names == set()
|
||||
|
||||
def test_toolsets_without_memory_blocks_injection(self):
|
||||
"""Toolset list that doesn't name 'memory' must suppress injection."""
|
||||
"""Toolsets that don't include memory must suppress injection."""
|
||||
mgr = self._mgr_with_tools("fact_store")
|
||||
tools, names = self._run_memory_injection(["terminal", "web"], mgr)
|
||||
assert tools == []
|
||||
|
||||
Reference in New Issue
Block a user