npx agentspec-cli install 37a5a2c9-7a60-4105-a4d1-d239ae203061 --framework ClaudeCode→ .claude/skills/memories-sdk/SKILL.md
# memories-sdk
Use the SDK packages when an application needs memories.sh programmatically. Prefer `@memories.sh/core` for direct typed API access and `@memories.sh/ai-sdk` only when the caller already uses the Vercel AI SDK.
## Workflow
1. Pick the integration surface:
- Use `@memories.sh/core` for backend routes, workers, cron jobs, and non-AI-SDK agents.
- Use `@memories.sh/ai-sdk` for `generateText`, `streamText`, middleware, or tool loops built on `ai`.
- If the task is about the CLI or MCP configuration, switch to `memories-cli` or `memories-mcp`.
2. Set scope before writing code:
- Keep `MEMORIES_API_KEY` server-side.
- `tenantId` selects the tenant or workspace database.
- `userId` narrows memory to a user inside that tenant.
- `projectId` narrows reads and writes to a product area, repo, or feature slice.
3. Use the narrowest pattern that solves the task:
- Direct CRUD or context lookup: `MemoriesClient`
- Automatic prompt injection: `memoriesMiddleware`
- Agent loops with explicit memory tools: `memoriesTools` and `memoriesSystemPrompt`
- Fetch once and reuse: `preloadContext`
- Persist after completion: `createMemoriesOnFinish`
4. Verify the integration:
- Confirm the same scope is used on both reads and writes.
- Catch `MemoriesClientError`.
- Do not expose the API key to browser-only code.
## Quick Start
### `@memories.sh/core`
```ts
import { MemoriesClient } from "@memories.sh/core"
const client = new MemoriesClient({
apiKey: process.env.MEMORIES_API_KEY,
tenantId: "acme-prod",
userId: "user_123",
})
const context = await client.context.get({
query: "billing architecture",
projectId: "dashboard",
mode: "all",
strategy: "hybrid",
limit: 8,
})
await client.memories.add({
content: "Enterprise billing uses Stripe invoices.",
type: "fact",
projectId: "dashboard",
tags: ["billing"],
})
```
### `@memories.sh/ai-sdk`
```ts
import { generateText, stepCountIs, wrapLanguageModel } from "ai"
import { openai } from "@ai-sdk/openai"
import {
memoriesMiddleware,
memoriesSystemPrompt,
memoriesTools,
} from "@memories.sh/ai-sdk"
const model = wrapLanguageModel({
model: openai("gpt-4o"),
middleware: memoriesMiddleware({
tenantId: "acme-prod",
userId: "user_123",
projectId: "dashboard",
}),
})
const result = await generateText({
model,
system: memoriesSystemPrompt(),
tools: memoriesTools({
tenantId: "acme-prod",
userId: "user_123",
projectId: "dashboard",
}),
stopWhen: stepCountIs(5),
prompt: "Summarize prior decisions about billing.",
})
console.log(result.text)
```
## Decision Guide
- Need direct typed access from your own backend code: use `MemoriesClient`
- Need automatic context injection into prompts or messages: use `memoriesMiddleware`
- Need the model to read or write memory explicitly through tools: use `memoriesTools`
- Need to manage stored skill files or procedure fragments: use `client.skills.*` or the AI SDK skill-file tools
- Need tenant, key, or embedding usage administration: use `client.management.*`
- Need internals of the memories monorepo or server endpoints: use `memories-dev`
## Reference Files
- `references/core.md`: direct client methods, transport choices, errors, management APIs, and skill-file APIs
- `references/ai-sdk.md`: middleware, tools, preload, post-finish persistence, and query extraction patterns
- `references/scoping.md`: tenant/user/project scoping rules, server-side safety, and debugging checklist
Built on the Agent Skills standard
Cursor Rules — ai-memory
Use `memory.*` MCP tools as a persistent memory loop when available. **Namespace for all operations in this repo:** { "repo_url": "https://github.com/matt-antone/ai-memory" } Do not pass `agent` or `repo_name` — set automatically. Global items (no `repo_url`) are always included in repo-scoped searches.
by AgentHub Crawler
OpenCode Supermemory
OpenCode plugin for persistent memory using Supermemory. Your agent remembers what you tell it - across sessions, across projects.
by AgentHub Crawler
AI Memory Rule
This rule defines how the AI should manage and utilize its "memory" regarding this specific project, including user preferences, learned facts, and project-specific conventions.
by AgentHub Crawler
Sign in to leave a comment.
Codevira — persistent project memory
This project uses **Codevira** to give every AI coding tool you use shared memory of the project. Decisions, fix history, the structural code graph, and learned style preferences persist across sessions and across IDEs.
by AgentHub Crawler