api.memory

save()

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

Crea una nota, o la sostituisce con il memònimo nome. Il nome è l'identitè — non c'è una aggiornament separata.

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.

Parâmetros

namestringobrigatório

Mincescase, cifres e guinxes, fino a 64. Cualquier altra cosa è convertita; ciò che non può ser nega.

contentstringobrigatório

La nota stessa, fino a 4 000 caracteres.

descriptionstring

Una fila, fino a 200. It's ove lo agent vee quando elige — ved inferior.

typestring

preference · project · fact · correction · other. Valori sconosciutis diventa other.

sourcestring

user or agent. Qualsiasi cosa non è user diventa agent.

sessionIdstring

La sessione in cui fu imparat, quando fuse una.

Il nome è l'identitè

Salvare con un nome che già esiste sostituisce que nota. Questo è l'intero meccanismo di update, e è per questo che vale la pena scegliere bene: è la cosa che dovrès aderire poi.

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.
Tu passa- Conservato como
Tonu de voceTono de voce
user_preferencesPreferenze d'usuari
- Deploiment!!d-ploiement
!!!Refusat — invalid_name
I nomi sono convertiti, non validati

Due nomi diversi possono convergere su un, e la seconda salva poi sostituisce la prima nota senza dicir. Pitch simple, nomes stabile, e legga il nome che torna quando lo costruite da input d'usuario.

Scrive la descriptura per l'agente

Il contenuto è aperto solo quando una nota pare pertinente, e la relevance è giudicata sulla description. Quindi la description deve dicire quando vale la pena lere, non quello che contiene.

Descriptio deficiente-Meglior
«Preferenze»«Come questo utentu vore ser scrit a»
« Base de données »«Qual database a usar, e qual mai a tocar»
« Notes sul progetto »«Le regole di implementare per questo progetto, incluso ciò che è proibit»

Retorno

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"]

La nota come memorized — dopo che il nome è convertit e il testo rimàstot a i suoi limiti. Legîlo di nuovo, invece di supponendo che quello che tu enviaste è quello che era conservat.

Erros

CódigoStatusQuando
invalid_name400Nada utilizable era lasciato dopo la conversione.
content_required400Il contenit era vazio o solo spazio bianco.
too_many_memories400200 notes ya, e questo sarebbe un nuovo.

too_many_memories solo aplica a una nota nov: sostituire una existente funciona al cap, perché non aggiunge nada. Isso è deliberat — esser pieno non deve impedir-te de corregir algo errat.

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()

fonte, e por què vale la pena impostare

Qualsiasi cosa non è "user" è registrat come agent. Setuant-lo onestamente è ciò che lascia una interface separate « me has detto » de « me ha reso l'officina » — e la seconda merita di essere più facile da questionare.