记忆
- 作者仓库星标 27
- 许可证 Apache-2.0
- 作者仓库 memories
- 领域
- 工程开发
- 作者声明的智能体
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 94 / 100 · 启发式扫描,不代表运行安全
- 运行环境证据
- 未执行;当前没有隔离运行测试证据
- 作者 / 版本 / 许可证
- @webrenew · Apache-2.0
- 上下文用量评级
- 低消耗
- 接入复杂程度
- 需简单配置
- 是否需要外部接口密钥
- 需要 · Vendor-specific
- 兼容的系统
- 未声明(默认跨平台)
- 运行环境要求
- 未检出明确要求
- 检测到的文件与系统行为
-
- 只读
- 允许写入 / 修改
- 网络行为
- 允许外网请求
- 安装命令数
- 无(仅作为资料)
需要注意: 未声明工具权限范围;实际权限由运行环境决定。
# 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: [REDACTED:credential],
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
章节与文件索引
按说明文件中的顺序排列。
工作流程
决策指南
参考文件
文件/命令 -> @memories.sh/core · @memories.sh/ai-sdk · generateText · streamText · memories-cli · memories-mcp · MEMORIES_API_KEY · tenantId
内容校验值 -> 3c30f54e7b11
当前原文的自动摘译,尚未人工审校。
工作流程
选择集成界面:将
@memories.sh/core用于后端路由、worker、cron 作业和非 AI-SDK 代理。将@memories.sh/ai-sdk用于generateText、streamText、中间件或基于ai构建的工具循环。如果任务与 CLI 或 MCP 配置有关,请切换到memories-cli或memories-mcp。在编写代码之前设置范围:决策指南
需要从您自己的后端代码直接类型化访问:使用
MemoriesClient需要自动上下文注入到提示或消息中:使用memoriesMiddleware需要模型通过工具显式读取或写入内存:使用memoriesTools需要管理存储的技能文件或过程片段:使用client.skills.*或 AI SDK 技能文件工具 需要租户、密钥或嵌入使用管理:使用client.management.*参考文件
references/core.md:直接客户端方法、传输选择、错误、管理 API 和技能文件 APIreferences/ai-sdk.md:中间件、工具、预加载、完成后持久性和查询提取模式references/scoping.md:租户/用户/项目范围规则、服务器端安全性和调试检查表