Skip to content

feat: integrate MemPalace persistent memory for agents #276

@vybe

Description

@vybe

Summary

Integrate MemPalace (8.2k stars, MIT) as an optional persistent memory layer for Trinity agents. MemPalace is an MCP-compatible memory server that gives agents structured long-term recall across chat sessions using local SQLite + ChromaDB — no cloud services or API keys required.

Problem

Trinity agents have persistent chat history (stored in the platform DB), but the agents themselves have no cross-session memory. When a new chat session starts, the agent loses all working context about prior conversations, decisions, and accumulated knowledge. This limits the effectiveness of long-running autonomous agents.

Solution

Add MemPalace as a per-agent opt-in capability via a simple toggle, similar to the existing read-only mode or autonomy toggle.

Architecture

  • Transport: stdio MCP server (python -m mempalace.mcp_server) — no ports, no sidecar containers
  • Storage: /home/developer/.mempalace/ — already on the persistent workspace volume, survives restarts
  • Tools: 19 MCP tools for memory filing, semantic search, knowledge graph, and agent diary
  • Dependencies: Python package with ChromaDB (adds ~50MB to base image)
  • Init: None required — palace structure created lazily on first tool use

Runtime flow

User enables memory toggle → backend injects mempalace into .mcp.json
→ Claude Code picks up MCP server → 19 memory tools available
→ Agent stores/retrieves memories automatically
→ Data persists across container restarts via workspace volume

Implementation

Changes required

Change File Notes
Add pip install mempalace docker/base-image/Dockerfile 1 line, requires base image rebuild
Add memory toggle DB mixin src/backend/db/agent_settings/memory.py New mixin, ~40 lines
Add memory toggle endpoints src/backend/routers/agent_config.py GET/PUT /api/agents/{name}/memory
Inject MCP config on toggle src/backend/routers/agent_config.py Add/remove mempalace entry in .mcp.json
Frontend toggle UI src/frontend/src/views/AgentDetail.vue Toggle in agent settings panel
MCP tool (optional) src/mcp-server/src/tools/agents.ts Enable/disable via MCP

MCP config injected when enabled

{
  "mcpServers": {
    "mempalace": {
      "command": "python",
      "args": ["-m", "mempalace.mcp_server"]
    }
  }
}

Design decisions

  • Platform capability, not template-specific — any agent can enable it regardless of template
  • Off by default — adds 19 tools to the agent's context; should be opt-in
  • No initialization step — skip mempalace init (interactive, human-oriented); MCP tools create structure on first use
  • Leverage existing injection flow — use POST /api/agents/{name}/credentials/inject for .mcp.json updates

Acceptance Criteria

  • mempalace Python package pre-installed in base agent image
  • Per-agent memory toggle (GET/PUT endpoints)
  • Enabling toggle injects mempalace MCP server into agent's .mcp.json
  • Disabling toggle removes mempalace entry (preserves other MCP servers)
  • Memory data persists across container restarts
  • Frontend toggle in agent settings panel
  • No initialization required — works on first enable

References

  • MemPalace repo: https://github.com/milla-jovovich/mempalace
  • 19 MCP tools: palace navigation, data modification, knowledge graph, graph navigation, agent diary
  • AAAK compression: 30x compression dialect for efficient memory storage

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity-mediumComplexity: medium (board points 5-8)priority-p2Importantstatus-incubatingIdea under consideration — pre-Todo, not yet greenlit for developmenttheme-devexTheme: DevExtype-featureNew functionality

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions