INTEGRITY Cloudflare Docs

Workers API

Use the Workers API to access Agent Memory from your Worker. The binding connects your Worker to a namespace containing profiles, which are isolated memory stores for your agent.

Configure the binding

Add an agent_memory entry to your Wrangler configuration. The binding field is the variable name you use in Worker code, and the namespace field is the Agent Memory namespace to bind to.

{
  "$schema": "./node_modules/wrangler/config-schema.json",
  "agent_memory": [
    {
      "binding": "MEMORY",
      "namespace": "<NAMESPACE_NAME>"
    }
  ]
}
[[agent_memory]]
binding = "MEMORY"
namespace = "<NAMESPACE_NAME>"

To bind multiple namespaces, add multiple entries to the agent_memory array.

Generated types

Run npx wrangler types to generate the binding type in worker-configuration.d.ts:

worker-configuration.d.ts
interface Env {
	MEMORY: AgentMemoryNamespace;
}

Namespace methods

Use namespace methods on the binding to access and manage memory profiles.

getProfile(profileName)

Gets a memory profile by name. If the profile does not exist, Agent Memory creates it.

The first getProfile() call for a new profile may take longer while Agent Memory creates the profile.

deleteProfile(profileName)

Marks a profile and all its memories and messages for deletion.

Profile methods

Call profile methods after you get a profile from the binding.

type AgentMemoryMemory = {
	id: string;
	type: "fact" | "event" | "instruction" | "task";
	summary: string;
	content: string;
	sessionId: string | null;
	createdAt: Date;
	updatedAt: Date;
};

ingest(messages, options?)

Processes a conversation and extracts structured memories from it. Agent Memory identifies facts, events, instructions, and tasks automatically, so you do not need to specify what to remember.

type AgentMemoryMessage = {
	role: "system" | "user" | "assistant";
	content: string; // Max 32 KB
	timestamp?: Date;
};

ingest() is idempotent. Re-ingesting the same conversation does not create duplicate memories.

remember(memory)

Stores a single memory explicitly. Use remember() when your application or agent already knows what should be stored, instead of passing a conversation to ingest() for extraction.

recall(query, options?)

Searches stored memories in the profile and returns a synthesized answer grounded in the stored content.

type AgentMemoryRecallResult = {
	count: number;
	answer: string;
	candidates: AgentMemoryScoredCandidate[];
};

type AgentMemoryScoredCandidate = {
	id: string;
	summary: string;
	sessionId: string | null;
	score: number;
};

If no memories match the query, recall() returns an empty answer.

list(options?)

Lists memories stored in the profile. Returns a paginated, filterable view of stored memories. Use the returned cursor (when present) to fetch the next page.

type AgentMemoryMemoryListEntry = Omit<AgentMemoryMemory, "content">;

type AgentMemoryListMemoriesResult = {
	memories: AgentMemoryMemoryListEntry[];
	cursor?: string;
};

List entries omit content. Use get(memoryId) to retrieve the full memory.

get(memoryId)

Retrieves a memory by ID.

Throws an error if the memory does not exist.

delete(memoryId)

Deletes a memory by ID. Removes the memory and any source messages linked to it. Returns the deleted memory.

Throws an error if the memory does not exist.

deleteSession(sessionId)

Marks all memories and messages in the profile that are tagged with the given session ID for deletion. Rows from other sessions in the same profile are untouched. Idempotent: deleting a session ID that has no rows is a no-op.

getSummary(options?)

Generates a structured Markdown summary of everything stored in a memory profile. Use it to inspect what Agent Memory remembers about a profile.

type AgentMemoryGetSummaryResponse = {
	summary: string;
};

Limits

Parameter Limit
Messages per ingest() call 500
Message content size 32 KB (32,768 bytes UTF-8)
Session ID length 64 characters
recall() query size 1 KB (1,024 bytes UTF-8)

Refer to Limits for the complete list of constraints.

Next steps

HTTP API

Use Agent Memory from services that call the Cloudflare API directly.

Get started

Add durable memory recall and ingestion to an agent.