Parameters
namestringrequiredLowercase, digits and hyphens, up to 64. Anything else is converted; what cannot be is refused.
contentstringrequiredThe note itself, up to 4 000 characters. Empty is refused.
descriptionstringOne line, up to 200. This is what the agent sees when choosing — see below.
typestringpreference · project · fact · correction · other. Unknown values become other.
sourcestringuser or agent. Anything that is not user becomes agent.
sessionIdstringThe session this was learned in, when there was one.
The name is the identity
Saving with a name that already exists replaces that note. That is the whole update mechanism, and it is why the name is worth choosing well: it is the thing you will have to match later.
await api.memory.save({ name: "tone-of-voice", content: "Short answers.", source: "user" });
await api.memory.save({ name: "tone-of-voice", content: "Short answers, in French.", source: "user" });
// One note. The second content replaced the first.api.memory.save(name="tone-of-voice", content="Short answers.", source="user")
api.memory.save(name="tone-of-voice", content="Short answers, in French.", source="user")
# One note. The second content replaced the first.| You pass | Stored as |
|---|---|
| Tone Of Voice | tone-of-voice |
| user_preferences | user-preferences |
| Déploiement !! | d-ploiement |
| !!! | refused — invalid_name |
Two different names can converge on one, and the second save then replaces the first note without saying so. Pick plain, stable names, and read back the name that comes back when you built it from user input.
Write the description for the agent
The content is only opened when a note looks relevant, and relevance is judged on the description alone. So the description should say when this is worth reading, not what it contains.
| Weak description | Better |
|---|---|
| « Preferences » | « How this user wants to be written to » |
| « Database » | « Which database to use, and which never to touch » |
| « Notes about the project » | « The deploy rules for this project, including what is forbidden » |
Returns
const note = await api.memory.save({
name: "deploy-rules",
description: "The deploy rules for this project, including what is forbidden",
content: "No deploys on Friday. Staging first, always. Migrations run separately.",
type: "project",
source: "user",
});
note.name; // "deploy-rules"
note.type; // "project"
note.updatedAt;note = api.memory.save(
name="deploy-rules",
description="The deploy rules for this project, including what is forbidden",
content="No deploys on Friday. Staging first, always. Migrations run separately.",
type="project",
source="user",
)
note["name"] # "deploy-rules"
note["type"] # "project"
note["updatedAt"]The note as stored — after the name has been converted and the text trimmed to its limits. Read it back rather than assuming what you sent is what was kept.
Errors
| Code | Status | When |
|---|---|---|
| invalid_name | 400 | Nothing usable was left after conversion. |
| content_required | 400 | The content was empty or only whitespace. |
| too_many_memories | 400 | 200 notes already, and this would be a new one. |
too_many_memories only applies to a new note: replacing an existing one works at the cap, because it adds nothing. That is deliberate — being full should not stop you correcting something wrong.
import { IaGenifyError } from "iagenify";
try {
await api.memory.save({ name, content, description, type, source: "user" });
} catch (err) {
if (err instanceof IaGenifyError && err.code === "too_many_memories") {
// Let the user choose what goes. Do not evict on their behalf.
return { needsPruning: await api.memory.list() };
}
throw err;
}from iagenify import IaGenifyError
try:
api.memory.save(name=name, content=content, description=description, type=kind, source="user")
except IaGenifyError as error:
if error.code != "too_many_memories":
raise
# Let the user choose what goes. Do not evict on their behalf.
needs_pruning = api.memory.list()source, and why it is worth setting
Anything that is not "user" is recorded as agent. Setting it honestly is what lets an interface separate « you told me this » from « I worked this out » — and the second deserves to be easier to question.