Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions acp_adapter/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2128,6 +2128,7 @@ def _cmd_tools(self, args: str, state: SessionState) -> str:
if isinstance(tool, dict)
},
enabled_toolsets=toolsets,
disabled_toolsets=getattr(state.agent, "disabled_toolsets", None),
_memory_manager=getattr(state.agent, "_memory_manager", None),
)
inject_memory_provider_tools(tool_view)
Expand Down
14 changes: 13 additions & 1 deletion agent/memory_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,19 @@ def memory_provider_tools_enabled(
*,
memory_tool_present: bool = False,
) -> bool:
"""Return whether external memory-provider tools should be exposed."""
"""Return whether external memory-provider tools should be exposed.

Gate logic (Issue #45422, #5544):
disabled_toolsets includes "memory" → skip (global nuclear option — user
explicitly opted out of ALL memory)
memory_tool_present is True → inject (built-in memory tool is
already in the tool surface)
enabled_toolsets is None → no filter, inject (backward compat)
enabled_toolsets includes "memory" → user opted in, inject
selected toolsets include "memory"
(via resolve_toolset) → user opted in, inject
otherwise (incl. []) → skip (constrained platform, no tools)
"""
if disabled_toolsets and "memory" in disabled_toolsets:
return False
if memory_tool_present:
Expand Down
2 changes: 1 addition & 1 deletion agent/system_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def build_system_prompt_parts(agent: Any, system_message: Optional[str] = None)

# Tool-aware behavioral guidance: only inject when the tools are loaded
tool_guidance = []
if "memory" in agent.valid_tool_names:
if "memory" in agent.valid_tool_names and (agent._memory_enabled or getattr(agent, "_user_profile_enabled", False)):
tool_guidance.append(MEMORY_GUIDANCE)
if "session_search" in agent.valid_tool_names:
tool_guidance.append(SESSION_SEARCH_GUIDANCE)
Expand Down
15 changes: 10 additions & 5 deletions tests/agent/test_memory_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,9 @@ def test_injection_frequency_first_turn_with_1indexed(self):


class TestMemoryToolToolsetGate:
"""Issue #5544: memory provider tools must respect platform_toolsets.
"""Issue #5544: memory provider tools must respect platform_toolsets,
and Issue #45422: external memory providers work when the built-in memory
toolset is present or implicitly enabled via resolve_toolset.

Before the fix, MemoryManager.get_all_tool_schemas() output was appended
to AIAgent.tools unconditionally in agent_init.py — bypassing the
Expand All @@ -1379,10 +1381,13 @@ class TestMemoryToolToolsetGate:
These tests exercise the shared gate used by agent init and ACP refreshes.
The gate condition is:

disabled_toolsets includes memory → skip injection
enabled_toolsets is None → no filter, inject (backward compat)
selected toolsets include memory → user opted in, inject
otherwise (incl. []) → skip injection
disabled_toolsets includes "memory" → skip injection
memory tool is present in tool surface → inject
enabled_toolsets is None → no filter, inject (backward compat)
enabled_toolsets includes "memory" → user opted in, inject
selected toolsets include "memory"
(via resolve_toolset) → user opted in, inject
otherwise (incl. []) → skip injection
"""

@staticmethod
Expand Down
1 change: 1 addition & 0 deletions tests/run_agent/test_run_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ def agent_with_memory_tool():
skip_memory=True,
)
a.client = MagicMock()
a._memory_enabled = True # required for MEMORY_GUIDANCE injection (#45422)
return a


Expand Down