Skip to content

Repository files navigation

Agent Memory — Shared Memory for AI Coding Agents

Fully local, persistent, semantic memory for your AI coding agents. No external API keys required.

Give every agent in your project the same long-term memory: architecture decisions, TDD rules, coding conventions, bug-fix lessons, and anti-patterns — retrieved automatically before coding, updated automatically after coding.

Works with: Claude Code, OpenCode, Qwen Code, KiloCode, Antigravity, and any MCP-compatible agent.

Architecture

Global Qdrant (Docker)          Ollama (Embeddings)
      │                              │
      └────── Mem0 MCP Server ───────┘
                    │
    ┌───────┬───────┼───────┬───────────┐
  Qwen   Claude   OpenCode KiloCode  Antigravity
  • Qdrant — Vector store, one global instance shared across all projects
  • Ollama — Local LLM (gemma3:4b) + embedding model (nomic-embed-text)
  • Mem0 — Memory orchestration layer
  • MCP Server — Exposes memory tools to your agents over stdio

Prerequisites

  • Python 3.11+
  • Docker (for Qdrant)
  • Ollama running locally with nomic-embed-text and gemma3:4b models

Quick Start

1. Start Qdrant (one-time, global)

docker run -d --name qdrant-mem0 --restart unless-stopped \
  -p 6333:6333 -v qdrant_mem0_global:/qdrant/storage \
  qdrant/qdrant:latest

2. Pull the embedding model

ollama pull nomic-embed-text
ollama pull gemma3:4b

3. Clone and set up

git clone https://github.com/sanprat/agent-memory.git
cd agent-memory
python3 -m venv .venv
.venv/bin/pip install -r requirements.txt

4. Initialize a project

./init_project.sh /path/to/your/project

This copies the memory server, rules files, and agent MCP configs into your project, and creates its virtualenv.

5. Seed memories for your project

Edit seed_memories.py in your project to add project-specific memories (TDD rules, architecture decisions, coding conventions, anti-patterns), then:

cd /path/to/your/project
.venv/bin/python3 seed_memories.py

6. Done — agents auto-load the rules

Every agent reads .agent-memory-rules.md on startup and automatically:

  • Searches memory before coding (finds TDD rules, conventions, past decisions)
  • Follows retrieved rules during coding
  • Updates memory after coding (stores bug fixes, architecture decisions, learnings)

How Agents Connect

The Universal Pattern

Every project gets these files:

File Purpose Loaded by
.agent-memory-rules.md Universal brain — rules for before/during/after coding All agents
CLAUDE.md Tells Claude Code to load the rules file Claude Code
AGENTS.md Tells OpenCode to load the rules file OpenCode
.mcp.json MCP config Claude Code
.kilocode/mcp.json MCP config + native instruction injection KiloCode
mcp_config.json MCP config Antigravity
.qwen/mcp.json MCP config Qwen Code

MCP Tools

The mem0_mcp_server.py exposes 4 tools to agents:

Tool Description
mem0_add Store a new memory with optional category
mem0_search Semantic search across memories
mem0_list List all memories for an agent
mem0_delete Delete a memory by ID

All memories are stored under a single shared agent ID (shared_rules by default), so every agent in the project sees the same memory.

Testing

A smoke test verifies the MCP server starts and exposes its tools:

.venv/bin/python3 test_smoke.py

Env Variables

Variable Description Default
MEM0_AGENT_ID Shared agent identifier shared_rules
MEM0_COLLECTION Qdrant collection name agent_memory
LLM_MODEL Ollama LLM model gemma3:4b
EMBED_MODEL Ollama embedding model nomic-embed-text
OLLAMA_BASE_URL Ollama URL http://localhost:11434
QDRANT_URL Qdrant URL http://localhost:6333

Limitations

  • Ollama LLM quality — memory extraction/summarisation uses a small local model (gemma3:4b); complex memories may be summarised imperfectly. Swap in a larger model via LLM_MODEL if needed.
  • Single shared agent ID — all agents in a project share one memory scope by default; per-agent scoping is possible via agent_id tool arguments but not yet a first-class workflow.
  • No sync across machines — Qdrant is a single instance; teams need a shared Qdrant deployment to share memory.
  • Memory growth is unmanaged — memories accumulate; periodic curation (via mem0_list / mem0_delete) is manual.

Learn More

Read the full write-up on PyBankers — Build Real Products with AI: practical guides on AI agents, coding tools, and finance automation for Indian developers.

License

MIT — see LICENSE.

About

Universal MCP memory layer for AI coding agents (OpenCode, Claude Code, Cursor, Kilo Code). Self-hosted with Mem0 + Qdrant. Seed rules once, all agents remember.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages