Core ConceptsUpdated 2026-05-25
Scopes
How project, user, session, agent, and task scopes keep RetainDB memory isolated and useful.
Scopes decide what memory can be written and retrieved.
| Scope | Purpose | Example |
|---|---|---|
project | Product or environment boundary | production, acme-support |
user_id | End-user memory | user_123 |
session_id | Conversation or workflow memory | chat_456 |
agent_id | Agent identity | planner, builder |
task_id | Shared work item | checkout-redesign |
Rules that avoid bugs
- Use stable IDs from your application.
- Do not let the browser invent tenant scope.
- Keep project names consistent between write and search.
- Use session scope when the same user has multiple independent conversations.
- Use agent and task scope for multi-agent workflows.
User chat example
ts
const user = db.user("user_123");
const session = user.session("chat_456");
await session.remember("User is debugging billing webhooks.");
const { context } = await session.getContext("What are we debugging?");Agent task example
ts
const task = db.agent("planner").task("checkout-redesign");
await task.event({
type: "decision",
summary: "Use hosted checkout for the first release."
});Next: Agent Memory Bus.
Was this page helpful?
Your feedback helps us prioritize docs improvements weekly.