MemoryBuddy
README.md
# MemoryBuddy š§
[äøęē](README.zh-CN.md)
> **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)
[](https://workers.cloudflare.com/)
[](https://www.typescriptlang.org/)
[](https://modelcontextprotocol.io/)
[](#-why-cloudflare-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
- [Cloudflare account](https://dash.cloudflare.com/sign-up) (free is fine)
- Node.js 18+
### 1. Clone & Install
```bash
git clone https://github.com/Trainspotting31/memory-buddy.git
cd memory-buddy
npm install
```
### 2. Create Cloudflare Resources
```bash
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
```bash
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
```bash
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:
```json
{
"mcpServers": {
"memory-buddy": {
"type": "streamable-http",
"url": "https://memory-buddy.<your-subdomain>.workers.dev/mcp"
}
}
}
```
### Cursor
Add to `~/.cursor/mcp.json`:
```json
{
"mcpServers": {
"memory-buddy": {
"url": "https://memory-buddy.<your-subdomain>.workers.dev/mcp"
}
}
}
```
### Claude Desktop
Add to `claude_desktop_config.json`:
```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
```bash
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
```bash
curl https://your-worker.workers.dev/memory/user123
```
### `DELETE /memory/:userId` ā Wipe memory
```bash
curl -X DELETE https://your-worker.workers.dev/memory/user123
```
### `GET /health` ā Health check
```bash
curl https://your-worker.workers.dev/health
```
## āļø Configuration
Edit `wrangler.toml`:
```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
- [x] MCP Server (Streamable HTTP)
- [x] Multi-agent shared memory
- [x] Semantic search
- [x] 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](LICENSE)
This server cannot be deployed
Maintenance
ActivitySlowing
ResponsivenessNo issues