|
10 | 10 | from agent_memory_server.mcp import mcp_app |
11 | 11 | from agent_memory_server.models import ( |
12 | 12 | LongTermMemory, |
| 13 | + LongTermMemoryResult, |
| 14 | + MemoryPromptRequest, |
| 15 | + MemoryPromptResponse, |
| 16 | + SystemMessage, |
13 | 17 | ) |
14 | 18 |
|
15 | 19 |
|
@@ -166,7 +170,6 @@ async def test_default_namespace_injection(self, monkeypatch): |
166 | 170 | Ensure that when default_namespace is set on mcp_app, search_long_term_memory injects it automatically. |
167 | 171 | """ |
168 | 172 | from agent_memory_server.models import ( |
169 | | - LongTermMemoryResult, |
170 | 173 | LongTermMemoryResults, |
171 | 174 | ) |
172 | 175 |
|
@@ -214,3 +217,60 @@ async def fake_core_search(payload): |
214 | 217 | finally: |
215 | 218 | # Restore original namespace |
216 | 219 | mcp_app.default_namespace = original_ns |
| 220 | + |
| 221 | + @pytest.mark.asyncio |
| 222 | + async def test_memory_prompt_parameter_passing(self, session, monkeypatch): |
| 223 | + """ |
| 224 | + Test that memory_prompt correctly passes parameters to core_memory_prompt. |
| 225 | + This test verifies the implementation details to catch bugs like the _params issue. |
| 226 | + """ |
| 227 | + # Capture the parameters passed to core_memory_prompt |
| 228 | + captured_params = {} |
| 229 | + |
| 230 | + async def mock_core_memory_prompt(params: MemoryPromptRequest): |
| 231 | + captured_params["query"] = params.query |
| 232 | + captured_params["session"] = params.session |
| 233 | + captured_params["long_term_search"] = params.long_term_search |
| 234 | + |
| 235 | + # Return a minimal valid response |
| 236 | + return MemoryPromptResponse( |
| 237 | + messages=[ |
| 238 | + SystemMessage(content={"type": "text", "text": "Test response"}) |
| 239 | + ] |
| 240 | + ) |
| 241 | + |
| 242 | + # Patch the core function |
| 243 | + monkeypatch.setattr( |
| 244 | + "agent_memory_server.mcp.core_memory_prompt", mock_core_memory_prompt |
| 245 | + ) |
| 246 | + |
| 247 | + async with client_session(mcp_app._mcp_server) as client: |
| 248 | + prompt = await client.call_tool( |
| 249 | + "memory_prompt", |
| 250 | + { |
| 251 | + "query": "Test query", |
| 252 | + "session_id": {"eq": session}, |
| 253 | + "namespace": {"eq": "test-namespace"}, |
| 254 | + "topics": {"any": ["test-topic"]}, |
| 255 | + "entities": {"any": ["test-entity"]}, |
| 256 | + "limit": 5, |
| 257 | + }, |
| 258 | + ) |
| 259 | + |
| 260 | + # Verify the tool was called successfully |
| 261 | + assert isinstance(prompt, CallToolResult) |
| 262 | + |
| 263 | + # Verify that core_memory_prompt was called with the correct parameters |
| 264 | + assert captured_params["query"] == "Test query" |
| 265 | + |
| 266 | + # Verify session parameters were passed correctly |
| 267 | + assert captured_params["session"] is not None |
| 268 | + assert captured_params["session"].session_id == session |
| 269 | + assert captured_params["session"].namespace == "test-namespace" |
| 270 | + |
| 271 | + # Verify long_term_search parameters were passed correctly |
| 272 | + assert captured_params["long_term_search"] is not None |
| 273 | + assert captured_params["long_term_search"].text == "Test query" |
| 274 | + assert captured_params["long_term_search"].limit == 5 |
| 275 | + assert captured_params["long_term_search"].topics is not None |
| 276 | + assert captured_params["long_term_search"].entities is not None |
0 commit comments