Per-conversation memory
Sometimes you want memory that belongs to one conversation and is not used in
the next one. Writes can carry a scope and a scopeRef, and recall can
filter on both.
Write and recall inside one conversation
// On every write
await memory.remember({
statement: extracted,
scope: "conversation",
scopeRef: conversationId,
});
// On every recall
const result = await memory.recall({
query,
scope: "conversation",
scopeRef: conversationId,
});scope and scopeRef are top-level fields of the recall request. With both
set, the recall only returns memories written for that conversation.
Keep it out of other recalls
A recall with no scope searches every scope, conversation memories
included. If the rest of your agent must not see them, filter those recalls
too:
const longTerm = await memory.recall({ query, scope: "global" });Close the conversation
There is no call that closes a whole scope at once. List the conversation’s facts and forget them one by one:
for (;;) {
const page = await memory.listFacts({
scope: "conversation",
scopeRef: conversationId,
limit: 100,
});
if (page.items.length === 0) break;
for (const fact of page.items) {
await memory.forgetFact(fact.id);
}
}The default list only returns current facts, so each pass sees what is left.
Forgetting is a soft delete
forgetFact closes the fact: the server sets the end of its validity to now
and the row stays in the database. A forgotten fact no longer comes back from
recall, but it is still there for review:
const closed = await memory.listFacts({
scope: "conversation",
scopeRef: conversationId,
status: "forgotten",
});
await memory.restoreFact(closed.items[0].id);Erasing a fact for good is a different call, purgeFact, and the key needs
the memory:hard_delete scope.
Scopes
The server accepts three values for scope. Any other value is rejected with
a 400 (validation_error).
| Scope | Meaning |
|---|---|
global | The default. Workspace memory with no narrower scope |
conversation | Memory tied to one conversation, identified by scopeRef |
personal | Memory owned by the user behind the key. Needs a key bound to a user |
scopeRef is a free string. It also works with global scope, for example to
namespace memory by project or by customer.