Skip to content

ingest()

ingest() processes a conversation and extracts structured memories from it. The system identifies facts, events, instructions, and tasks automatically — you do not need to specify what to remember.

Signature

TypeScript
profile.ingest(messages: Iterable<Message>, options?: IngestOptions): Promise<void>

Parameters

messages

An iterable (typically an array) of Message objects representing the conversation to process.

TypeScript
type Message = {
role: "system" | "user" | "assistant";
content: string;
timestamp?: Date | string;
};
FieldTypeRequiredDescription
role"system" | "user" | "assistant"YesThe role of the message sender.
contentstringYesThe message content. Maximum 32 KB (32,768 bytes UTF-8).
timestampDate | stringNoWhen the message was sent. Accepts a Date object or an ISO 8601 string (for example, "2026-04-21T12:00:00Z" or "2026-04-21").

Timestamp resolution

Agent Memory determines a message timestamp using the following priority:

  1. Explicit timestamp field — If provided, this value is used.
  2. Current time — If timestamp not present, the current time is used.

Timestamps do not affect message identity. Two messages with the same role and content but different timestamps are treated as the same message.

options

TypeScript
type IngestOptions = {
sessionId?: string | null;
};
FieldTypeDefaultDescription
sessionIdstring | nullAuto-derivedAn identifier for the conversation session. Maximum 64 characters. If omitted, a deterministic session ID is derived from the message content.

Return value

ingest() returns Promise<void>. It does not return the extracted memories.

Idempotency

ingest() is safe to call multiple times with the same messages. Message identity is content-addressed (based on the session ID, role, and content), so re-ingesting the same conversation does not create duplicates.

No-op behavior

If the AI does not identify any memorable content in the conversation, ingest() completes successfully without creating any memories. The raw messages are still stored for future keyword search.

Examples

Basic ingestion

JavaScript
const profile = await env.MEMORY.getProfile("alice");
await profile.ingest([
{ role: "user", content: "I prefer dark mode and use VS Code." },
{
role: "assistant",
content: "Noted your preferences for dark mode and VS Code.",
},
]);

With a session ID

JavaScript
await profile.ingest(
[
{ role: "user", content: "Deploy the API to production." },
{
role: "assistant",
content: "Deployed v2.3.0 to production successfully.",
},
],
{ sessionId: "deployment-session-42" },
);

With explicit timestamps

JavaScript
await profile.ingest([
{
role: "user",
content: "We decided to use PostgreSQL for the new service.",
timestamp: "2026-04-15T14:30:00Z",
},
{
role: "assistant",
content:
"Understood. I will recommend PostgreSQL for the new service going forward.",
timestamp: "2026-04-15T14:30:05Z",
},
]);

Limits

ParameterLimit
Messages per call500
Message content size32 KB (32,768 bytes UTF-8)
Session ID length64 characters

Refer to Limits for the complete list of constraints.