From b0f0e1b0eb241b4dcc8cb224c23bfa1a6cfecef6 Mon Sep 17 00:00:00 2001 From: vbfs Date: Mon, 12 Oct 2026 22:05:17 -0300 Subject: [PATCH] docs(skill): agent identity rule and setup guidance The skill now tells agents to pass their role as `agent` on every write (also added to the server instructions, so it applies without the skill), and adds a setup section for when an agent is asked to configure memory: Node >= 22.16, .mcp.json template, model choice by available RAM, one model for all agents in a project, .gitignore. Co-Authored-By: Claude Opus 5.5 --- README.md | 1 + skills/SKILL.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++-- src/server.js | 1 + 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b58e85c..1cc8787 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ server instructions). For multi-agent pipelines, add - Before a task: `search_context` for prior decisions, conventions and outputs (any language). - After a decision, output or discovery others need: `write_context` with a specific topic, the content with its rationale, and 1–4 lowercase tags. +- Always pass your role as `agent` (e.g. `backend-agent`) on writes, same id every session. - To change a memory, pass its `id` to `write_context`. Merge reported duplicates. - Shared mutable values (phase, owner, run id): `get_state` / `set_state` with `expected_version`. - Never store secrets — store where they live. diff --git a/skills/SKILL.md b/skills/SKILL.md index edd92ae..91bc576 100644 --- a/skills/SKILL.md +++ b/skills/SKILL.md @@ -1,6 +1,6 @@ --- name: agent-memory -description: "How to use the shared agent memory (agent-memory-store MCP tools: search_context, write_context, read_context, list_context, delete_context, get_state, set_state). Use whenever these tools are available and you start a task, receive a handoff, are unsure about a project fact, make a decision, finish a piece of work others depend on, or discover something that changes prior assumptions." +description: "How to use the shared agent memory (agent-memory-store MCP tools: search_context, write_context, read_context, list_context, delete_context, get_state, set_state). Use whenever these tools are available and you start a task, receive a handoff, are unsure about a project fact, make a decision, finish a piece of work others depend on, discover something that changes prior assumptions, or are asked to install or configure agent memory for a project." --- # Shared agent memory @@ -37,7 +37,8 @@ write_context({ topic: "Payments — PIX refund webhook timeout set to 20s", content: "Raised from 10s to 20s: the bank's sandbox p99 is 14s (load test PAG-4821). Retries: 3, exponential backoff. Config: services/payments/config/pix.yaml.", tags: ["payments", "pix", "decision"], - importance: "high" + importance: "high", + agent: "backend-agent" }) ``` @@ -48,6 +49,10 @@ write_context({ - **Importance**: `critical` = others will break things without it; `high` = changes how the next step runs; `medium` default; `low` = ephemeral. - **Temporary facts** (rate limits, incident workarounds): set `ttl_days`. +- **Agent**: always pass `agent` with your role as a stable lowercase id + (`backend-agent`, `qa-agent`) — on `write_context` and `set_state` too. It + records who wrote what, and lets others filter with + `search_context({ ..., agent: "qa-agent" })`. Use the same id in every session. ## 3. Update, don't duplicate @@ -90,3 +95,45 @@ Finish in this order: `write_context` (your output) → `set_state` (next phase) The server rejects API keys, tokens, private keys and passwords in connection strings. Write where the secret lives instead ("DATABASE_URL in Vault at prod/payments"). + +## 7. Setting up the memory server (only when asked) + +If you are asked to add or configure agent memory for a project: + +1. **Node.js ≥ 22.16** is required (`node --version`); older builds lack FTS5. +2. **Register the server** in the project's `.mcp.json` (shared via git): + + ```json + { + "mcpServers": { + "agent-memory": { + "command": "npx", + "args": ["-y", "agent-memory-store"], + "env": { "AGENT_MEMORY_MODEL": "arctic-embed-m-v2" } + } + } + } + ``` + + Agents that share this config (e.g. Claude Code subagents) identify + themselves by passing `agent` on each call (§2). Only when each agent runs + with its own config (separate clients or processes) also set + `"AGENT_MEMORY_AGENT": ""` in that agent's `env`, as the default + for its writes. + +3. **Pick the model from available RAM.** Each agent process loads its own copy: + + | `AGENT_MEMORY_MODEL` | RAM per process | Use when | + | --- | --- | --- | + | `arctic-embed-m-v2` (default) | ~0.6 GB macOS ARM, ~1.3 GB Linux x64 | agents × RAM fits comfortably in free memory | + | `granite-97m-multilingual` | ~0.45 GB | many agents or a small machine; still PT/EN | + | `none` | ~64 MB | very constrained machines; keyword search only | + + Check memory first (`sysctl -n hw.memsize` on macOS, `free -g` on Linux) + and keep the total under about half of it. +4. **Same model for every agent on a project.** Write the chosen + `AGENT_MEMORY_MODEL` explicitly in every entry; mixed models make the + agents keep re-embedding each other's memories. +5. Add `.agent-memory-store/` to `.gitignore` (the store is local data). +6. The first start downloads the model (~310 MB for the default); until then + search runs in keyword mode and says so in its response. diff --git a/src/server.js b/src/server.js index fb8ab7f..c60ca60 100644 --- a/src/server.js +++ b/src/server.js @@ -33,6 +33,7 @@ const DEFAULT_AGENT = process.env.AGENT_MEMORY_AGENT || "global"; const INSTRUCTIONS = `Persistent memory shared by every agent working in this project. - Before acting on a task, call search_context with what you need to know (decisions, conventions, prior outputs). Queries can be in any language. - After a decision, discovery or output others will need, call write_context with a specific topic, the content with its rationale, and a few lowercase tags. +- Always pass your role as \`agent\` (e.g. "backend-agent") on write_context and set_state, using the same id every session, so others know who wrote what. - To change an existing memory, pass its id to write_context (updates in place). If write_context reports possible duplicates, update one of them instead of keeping both. - Use get_state/set_state for small mutable values (phase, run id, flags). Pass expected_version to set_state when several agents may write the same key. - Never store secrets; store where they live instead.`;