feat: replace custom memory MCP with Cognee remote server
- Remove memory_mcp.py (stdio markdown-file memory) - Add Cognee MCP as remote Streamable HTTP toolset at 192.168.86.2:8003/mcp - Filter to only remember/recall/forget tools via allowed_tools - Update system prompt: Memory section moved to top priority with explicit 'call recall FIRST' instructions and examples - Add COGNEE_MCP_URL env var to docker-compose - Remove /memory volume mount (no longer needed) - Rewrite memory tests to use Cognee HTTP client fixture - 28/28 tests passing
This commit is contained in:
@@ -19,6 +19,7 @@ WEB_BASE_URL = os.environ.get("VOICE_WEB_URL", "https://localhost:8090")
|
||||
TOKEN_URL = os.environ.get("VOICE_TOKEN_URL", "http://127.0.0.1:8091/token")
|
||||
GEMMA_BASE_URL = os.environ.get("GEMMA_BASE_URL", "http://192.168.86.2:8023/v1").rstrip("/")
|
||||
GEMMA_MODEL = os.environ.get("GEMMA_MODEL", "gemma-4-e4b")
|
||||
COGNEE_MCP_URL = os.environ.get("COGNEE_MCP_URL", "http://192.168.86.2:8003/mcp")
|
||||
|
||||
# Path to the agent's venv python inside the container (has mcp, livekit.agents)
|
||||
CONTAINER_PYTHON = "/opt/voice-agent/.venv/bin/python"
|
||||
@@ -134,3 +135,42 @@ asyncio.run(main())
|
||||
return data["text"], data["isError"]
|
||||
|
||||
return _call
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def cognee_client():
|
||||
"""Factory that calls tools on the remote Cognee MCP server (Streamable HTTP).
|
||||
|
||||
Returns (result_text, is_error). Uses the mcp client library from the
|
||||
agent venv inside the container.
|
||||
"""
|
||||
|
||||
def _call(tool_name: str, args: dict | None = None) -> tuple[str, bool]:
|
||||
code = f"""
|
||||
import asyncio, json
|
||||
from mcp import ClientSession
|
||||
from mcp.client.streamable_http import streamablehttp_client
|
||||
|
||||
async def main():
|
||||
async with streamablehttp_client({COGNEE_MCP_URL!r}) as (read, write, _):
|
||||
async with ClientSession(read, write) as session:
|
||||
await session.initialize()
|
||||
result = await session.call_tool({tool_name!r}, {json.dumps(args or {})})
|
||||
text = ""
|
||||
for block in result.content:
|
||||
if getattr(block, "type", None) == "text":
|
||||
text += block.text
|
||||
print(json.dumps({{"text": text, "isError": bool(result.isError)}}))
|
||||
|
||||
asyncio.run(main())
|
||||
"""
|
||||
proc = docker_exec_python(code, timeout=120, check=False)
|
||||
if proc.returncode != 0:
|
||||
raise AssertionError(
|
||||
f"Cognee MCP call {tool_name} failed (rc={proc.returncode}): "
|
||||
f"stderr={proc.stderr[-800:]}"
|
||||
)
|
||||
data = json.loads(proc.stdout.strip().splitlines()[-1])
|
||||
return data["text"], data["isError"]
|
||||
|
||||
return _call
|
||||
|
||||
Reference in New Issue
Block a user