api.memory

save()

api.memory.save(note) → Promise<Memory>

Creates a note, or replaces the one with the same name. The name is the identity — there is no separate update.

POST /api/ai/memoriesfreeupsert by name
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

Parameters

namestringrequired

Lowercase, digits and hyphens, up to 64. Anything else is converted; what cannot be is refused.

contentstringrequired

The note itself, up to 4 000 characters. Empty is refused.

descriptionstring

One line, up to 200. This is what the agent sees when choosing — see below.

typestring

preference · project · fact · correction · other. Unknown values become other.

sourcestring

user or agent. Anything that is not user becomes agent.

sessionIdstring

The 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 passStored as
Tone Of Voicetone-of-voice
user_preferencesuser-preferences
Déploiement !!d-ploiement
!!!refused — invalid_name
Names are converted, not validated

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 descriptionBetter
« 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

CodeStatusWhen
invalid_name400Nothing usable was left after conversion.
content_required400The content was empty or only whitespace.
too_many_memories400200 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.