TypeScript SDK

Memories

Add, search, edit, and delete an agent's memories with the TypeScript SDK.

client.memories reads and writes the notes an agent keeps across sessions. Agents save memories themselves through the memory tools; use these methods to seed facts, show a user what the agent remembers about them, or remove something. To learn how memory reaches the agent, read Memory.

await client.memories.create({
  agentId,
  userId: "user_42",
  text: "Prefers concise release notes.",
});

const { data } = await client.memories.list({ agentId, userId: "user_42", search: "release" });

Every method takes the owning agentId and accepts an optional abortSignal.

How memories are kept

  • Each memory belongs to one agent and, through userId, to one of your end users or to no one (""). Neither can change later.
  • Text is up to 10 KiB of UTF-8.
  • An agent holds up to 500 memories across all users. When it is full, a new memory replaces the one used least recently.
  • update() counts as a use. Reading with list() or get() does not.

Available operations

MethodDescriptionReturns
create()Add a memoryMemoryResponse
list()List or search memoriesMemoriesListResponse
get()Read one memoryMemoryResponse
update()Replace a memory's textMemoryResponse
delete()Delete a memoryvoid

Methods

create()

Adds a memory to an agent.

Signature: create(input: CreateMemoryBody & { agentId: string } & ResourceRequestOptions): Promise<MemoryResponse>

const { memory } = await client.memories.create({
  agentId,
  userId: "user_42",
  text: "Prefers concise release notes.",
});
ParameterTypeRequiredDefaultDescription
agentIdstringyesnoneAgent ID (ag_…)
textstringyesnoneThe note, up to 10 KiB
userIdstringno""The end user it is about; "" for everyone

Returns MemoryResponse. Errors: validation_failed, not_found.

list()

Lists an agent's memories, or searches their text.

Signature: list(input: { agentId: string } & MemoriesListOptions): Promise<MemoriesListResponse>

const page = await client.memories.list({ agentId, userId: "user_42", search: "release" });
ParameterTypeRequiredDefaultDescription
agentIdstringyesnoneAgent ID (ag_…)
userIdstringnoall usersOnly this end user's memories; "" for the shared ones
searchstringnononeFull-text search terms
limitnumberno501 to 100 per page
cursorstringnononenextCursor from the previous page

Returns MemoriesListResponse. Errors: validation_failed, invalid_cursor, not_found.

get()

Reads one memory.

Signature: get(input: { agentId: string; memoryId: string } & ResourceRequestOptions): Promise<MemoryResponse>

const { memory } = await client.memories.get({ agentId, memoryId });

Returns MemoryResponse. Errors: validation_failed, not_found.

update()

Replaces a memory's text.

Signature: update(input: UpdateMemoryBody & { agentId: string; memoryId: string } & ResourceRequestOptions): Promise<MemoryResponse>

const { memory } = await client.memories.update({
  agentId,
  memoryId,
  text: "Prefers release notes under five lines.",
});

text is required and replaces the old text. The agent and userId stay the same. Returns MemoryResponse. Errors: validation_failed, not_found.

delete()

Deletes a memory for good.

Signature: delete(input: { agentId: string; memoryId: string } & ResourceRequestOptions): Promise<void>

await client.memories.delete({ agentId, memoryId });

Errors: validation_failed, not_found.

Response types

MemoryResponse

MemoryResponse is { memory: Memory }.

Memory fieldTypeDescription
idstringMemory ID (mem_…)
tenantIdstringYour tenant ID
agentIdstringThe agent that owns it
userIdstringThe end user it is about, or ""
textstringThe note
createdAtstringISO 8601 timestamp
updatedAtstringWhen the text last changed
lastAccessedAtstringWhen it was last used

MemoriesListResponse

interface MemoriesListResponse {
  data: Memory[];
  nextCursor: string | null;
}

Next

On this page