Skip to content

Trainspotting31/memory-buddy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

10 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

MemoryBuddy ๐Ÿง 

ไธญๆ–‡็‰ˆ

Give your AI agents a shared memory that lasts. Deploy once, connect any MCP-compatible AI tool โ€” Hermes, Trae, Cursor, Claude Desktop โ€” they all share the same memory.

License: MIT Cloudflare Workers TypeScript MCP Free Tier

๐ŸŒŸ What is this?

Most AI tools suffer from "goldfish memory" โ€” refresh the page, start a new session, switch to another app, and everything's gone. You keep reintroducing yourself, re-explaining your preferences, re-stating context.

MemoryBuddy fixes this with a shared memory layer that any AI tool can read from and write to:

  • ๐Ÿง  Long-term memory โ€” facts, preferences, decisions persist across sessions
  • ๐Ÿ” Semantic search โ€” find relevant memories by meaning, not just keywords
  • ๐Ÿค– Auto fact extraction โ€” LLM automatically distills what's worth remembering
  • ๐Ÿ“ Smart summarization โ€” long conversations get compressed, key points retained
  • ๐Ÿ—‘๏ธ One-click forget โ€” DELETE wipes everything, GDPR compliant
  • ๐Ÿ”Œ MCP protocol โ€” any MCP-compatible client can connect, zero integration code
  • ๐Ÿ’ธ $0/month โ€” runs entirely on Cloudflare's free tier

๐Ÿ’ก What problem does it solve?

๐Ÿ˜ฃ Without MemoryBuddy โœ… With MemoryBuddy
Every AI tool starts fresh โ€” you re-explain yourself constantly All your AI tools share one memory โ€” tell one, they all know
Switching from Hermes to Trae means losing all context Switch freely โ€” memory lives in the cloud, not in the tool
AI forgets your preferences between sessions Preferences persist forever, across all sessions and all tools
Long conversations hit context limits Auto-summarization keeps things compact
Privacy concerns โ€” can't delete what it remembers One API call wipes everything, fully GDPR compliant

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Hermes  โ”‚   โ”‚  Trae   โ”‚   โ”‚ Cursor  โ”‚   โ”‚ Claude  โ”‚
โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜
     โ”‚ MCP         โ”‚ MCP         โ”‚ MCP         โ”‚ MCP
     โ–ผ             โ–ผ             โ–ผ             โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚           MemoryBuddy Worker (Cloudflare)         โ”‚
โ”‚                                                  โ”‚
โ”‚   /mcp  โ†’ MCP Server (5 tools, Streamable HTTP)  โ”‚
โ”‚   /chat โ†’ HTTP API (SSE streaming + auto-extract)โ”‚
โ”‚   /memory/:userId โ†’ REST API                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
           โ”‚                  โ”‚
     โ”Œโ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”
     โ”‚ D1 (facts)โ”‚    โ”‚ Vectorize   โ”‚
     โ”‚ SQLite DB โ”‚    โ”‚ (embeddings)โ”‚
     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Three-tier memory:

  1. Short-term (Durable Object) โ€” current conversation context
  2. Long-term (D1 database) โ€” structured facts: name, preferences, key entities
  3. Semantic (Vectorize) โ€” vector embeddings for meaning-based recall

๐Ÿš€ Quick Start (3 steps, ~5 minutes)

Prerequisites

1. Clone & Install

git clone https://github.com/Trainspotting31/memory-buddy.git
cd memory-buddy
npm install

2. Create Cloudflare Resources

npx wrangler login

# Create D1 database
npx wrangler d1 create memory-buddy-db

# Create Vectorize index
npx wrangler vectorize create memory-buddy-index --dimensions 768 --metric cosine

# Initialize database schema
npx wrangler d1 execute memory-buddy-db --remote --file=schema.sql

Copy the generated database_id into wrangler.toml (rename from wrangler.toml.example).

3. Deploy

npx wrangler deploy

Done! Your memory server is live at https://memory-buddy.<your-subdomain>.workers.dev ๐ŸŽ‰

๐Ÿ”Œ Connect Your AI Tools

MemoryBuddy speaks MCP (Model Context Protocol). Any MCP-compatible tool can connect โ€” they all share the same memory.

Hermes Agent

hermes mcp add memory-buddy --url https://memory-buddy.<your-subdomain>.workers.dev/mcp

Trae IDE

  1. Settings โ†’ MCP โ†’ Add Manually
  2. Type: Streamable HTTP
  3. URL: https://memory-buddy.<your-subdomain>.workers.dev/mcp

Or create .trae/mcp.json in your project:

{
  "mcpServers": {
    "memory-buddy": {
      "type": "streamable-http",
      "url": "https://memory-buddy.<your-subdomain>.workers.dev/mcp"
    }
  }
}

Cursor

Add to ~/.cursor/mcp.json:

{
  "mcpServers": {
    "memory-buddy": {
      "url": "https://memory-buddy.<your-subdomain>.workers.dev/mcp"
    }
  }
}

Claude Desktop

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "memory-buddy": {
      "type": "streamable-http",
      "url": "https://memory-buddy.<your-subdomain>.workers.dev/mcp"
    }
  }
}

Any MCP Client (raw config)

Endpoint: https://memory-buddy.<your-subdomain>.workers.dev/mcp
Transport: Streamable HTTP
Auth: None (or add your own)

๐Ÿ› ๏ธ MCP Tools

Once connected, the AI gets 5 tools:

Tool What it does When AI calls it
recall_memory Load all memory for a user Start of conversation
search_memory Semantic search by meaning "What did I say about X?"
store_memory Save a new fact User shares preferences, decisions
forget_memory Delete all memory User says "forget everything"
list_memory_users List all memory spaces Checking what exists

Shared memory: All tools default to userId: "hermes-shared". Use different userIds to isolate memory per project/persona.

๐Ÿ“ก HTTP API (no MCP needed)

POST /chat โ€” Chat with memory

curl -N -X POST https://your-worker.workers.dev/chat \
  -H "Content-Type: application/json" \
  -d '{"userId":"user123","message":"Hi! I'm John and I love espresso."}'

GET /memory/:userId โ€” Get all memory

curl https://your-worker.workers.dev/memory/user123

DELETE /memory/:userId โ€” Wipe memory

curl -X DELETE https://your-worker.workers.dev/memory/user123

GET /health โ€” Health check

curl https://your-worker.workers.dev/health

โš™๏ธ Configuration

Edit wrangler.toml:

[vars]
LLM_MODEL = "@cf/meta/llama-3.2-3b-instruct"  # Default: Workers AI (free)

# Optional: use external LLM instead of Workers AI
LLM_API_KEY = "sk-your-key"
LLM_API_BASE = "https://api.openai.com/v1"
LLM_MODEL = "gpt-4o-mini"

๐Ÿ’ธ Why Cloudflare Free Tier?

Component Free Tier Self-Hosted Equivalent
Compute (Workers) 100K req/day $5โ€“$50/mo (VPS)
Database (D1) 1GB storage $10โ€“$100/mo (Postgres)
Vector DB (Vectorize) 256K vectors $70+/mo (Pinecone)
LLM (Workers AI) 10K neurons/day $10+/mo (API)
Total $0 ~$100+/mo

๐Ÿ“ Project Structure

memory-buddy/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ index.ts          # Hono router: /mcp + /chat + /memory + /health
โ”‚   โ”œโ”€โ”€ mcp.ts            # MCP Server factory (5 tools, stateless)
โ”‚   โ”œโ”€โ”€ agent-do.ts       # Durable Object: chat session + memory orchestration
โ”‚   โ”œโ”€โ”€ llm.ts            # LLM abstraction (Workers AI / OpenAI-compatible)
โ”‚   โ””โ”€โ”€ memory/
โ”‚       โ”œโ”€โ”€ extract.ts    # LLM-powered fact extraction
โ”‚       โ”œโ”€โ”€ retrieve.ts   # Hybrid retrieval (D1 + Vectorize)
โ”‚       โ””โ”€โ”€ summarize.ts  # Conversation summarization
โ”œโ”€โ”€ public/index.html     # Built-in demo chat UI
โ”œโ”€โ”€ schema.sql            # D1 database schema
โ”œโ”€โ”€ wrangler.toml.example # Cloudflare config template
โ””โ”€โ”€ package.json

๐ŸŽฎ Try the Demo

Open your Worker URL in a browser โ€” you'll see a built-in chat interface.

  1. Tell the agent your name and a preference ("I'm Sarah, I'm allergic to peanuts")
  2. Refresh the page
  3. Ask: "What do you know about me?"

It remembers everything. That's MemoryBuddy.

๐Ÿ—บ๏ธ Roadmap

  • MCP Server (Streamable HTTP)
  • Multi-agent shared memory
  • Semantic search
  • Auto fact extraction
  • Memory categories & filtering
  • User authentication
  • Batch memory import/export
  • Multi-language support
  • Hermes plugin (auto-inject memory at conversation start)

๐Ÿค Contributing

  1. Fork โ†’ 2. Branch โ†’ 3. Commit โ†’ 4. Push โ†’ 5. PR

๐Ÿ“„ License

MIT โ€” see LICENSE

About

Shared memory layer for AI agents. Deploy once, connect Hermes/Trae/Cursor/Claude Desktop via MCP - they all share one memory. $0/month on Cloudflare free tier.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages