Skip to main content

What is a memory store?

A memory store is a project-level collection of persistent files. When you mount a memory store at session creation, the agent can read or update its files during the session. Memory stores, memory files, and file versions represent distinct objects: Memory stores do not provide automatic vector search. When a session starts, the platform provides the agent with up to 16 KiB each from root-level README.md and index.md files. Other files are read on demand by the agent using file tools.
Do not store API keys, access tokens, passwords, or other sensitive credentials in a memory store. Use Vaults to store credentials.

Create and mount a memory store

The minimal end-to-end workflow takes three steps: create a memory store, create a memory file, and mount the memory store when creating a session. You can also create and manage memory stores on the Memory page in the console; see Using the Console. Beyond the console and REST API, you can also create and manage memory stores with the kha CLI. The examples below provide both cURL and kha CLI commands for working with memory stores and memory files.

Create a memory store

The request below creates a memory store named project-conventions:
Save id from the response as MEMORY_STORE_ID for subsequent requests. name must be unique within the project, be 1 to 64 characters long, and start with a Unicode letter or digit; subsequent characters may also include _ and -.

Create a memory file

Create a file using the memory store ID and file path. content is the Base64-encoded file body, and the decoded body can be at most 20 MiB. In the example below, content is the Base64 encoding of "Project conventions\n":
Save the file id from the response as MEMORY_ID for reading, updating, and listing versions. You can omit content or pass an empty string to create an empty file, but you cannot create another file at an existing path. path must be a normalized relative path of at most 900 bytes (UTF-8 encoded) using / as the directory separator. Absolute paths, empty path segments, ., .., backslashes, control characters, and percent-encoding are not allowed.

Mount a memory store in a session

Memory stores can only be attached when creating a session. The request below uses MEMORY_STORE_ID from the previous step and mounts the memory store in read-write mode:
Replace agent_id and environment_id with existing resource IDs, and replace MEMORY_STORE_ID with id from the memory store creation response. access can be read_only or read_write:
  • read_only: allows reading from the memory store only.
  • read_write: allows both reading from and writing to the memory store.
A single session can mount at most 8 memory stores. Each memory store is mounted at /mnt/agents/memories/<store-name>/ inside the session. The binding, access mode, and instructions cannot be modified after the session is created, though you can unbind the memory store via the session resources endpoints.

Manage memory files

Read a file

Read a file using the memory store ID and file ID. content in the API response is Base64-encoded; save content_sha256 from the response so you can pass it back unchanged for concurrency checking when updating the file:

Update a file

Encode the new body in Base64 and update the file. Set content_sha256 in the request to the value obtained when reading the current file; the platform uses it to check whether the file was modified after you read it:
If the file has been modified by another source, updating with a stale content_sha256 returns HTTP 409 without overwriting the newer content. Writes made through the session mount path and file tools do not go through the API’s content_sha256 concurrency check, so concurrent session writes can overwrite each other. Every successful file change creates a new version.

Delete a file

Deleting a file removes only the current file while preserving its historical versions:
After deletion, you can still query the version list and historical version contents under the original memory_id, but you can no longer send PATCH requests to that memory_id.

Inspect versions and restore files

Inspect file versions

Creating, modifying, renaming, and deleting a file each generate a version whose operation field is created, modified, renamed, or deleted, respectively. Query the file’s version list first, then choose a version to read:
Select a version that includes file content and read its content. Versions with operation set to deleted do not return content and cannot be used to restore a file:
Each version also records how it was written: source is api for writes through the API and session for writes from a session. When source is session, source_id contains the ID of the session that wrote the version. To find changes produced by a given session, filter for versions where source is session and source_id equals that session ID. content in historical versions is also Base64-encoded. To restore a file, write the historical version’s content back as the new file body along with the current file’s content_sha256:
Restoring generates a new version for the file. When restoring multiple files, read the current content_sha256 and write back the historical content for each file individually, then verify each restored file.

Restore a deleted file

A version with operation set to deleted does not include file content. To restore a deleted file, read a pre-deletion version that includes content, then recreate the file at the original path using that version’s content:
Recreating the file generates a new memory_id and starts a new version history from a fresh created version; the pre-deletion version history is still retained and queryable under the original memory_id. Before restoring, make sure content in the historical version has not been redacted.

Redact historical version content

If the body of a historical version no longer needs to be retained, call the redact endpoint to permanently erase its body while keeping the version metadata:
  • Redaction affects only the selected version; the current file and other versions are unaffected.
  • You cannot redact the version corresponding to the current file, and repeating the call on an already redacted version is a no-op.
  • Redacted content cannot be recovered, and any version with redacted_at in its response can no longer be used for restoration.

Memory store lifecycle

Update a memory store

Call PATCH /v1/memory-stores/{id} to modify a memory store’s name and description; fields omitted from the request body keep their current values. Archived memory stores cannot be updated.

Duplicate a memory store

Duplicating a memory store is currently supported only in the console and is not exposed via the API. Click Duplicate memory store on the memory store details page in the console to create a new memory store and copy all memory files from the current store into it. Only current file contents are copied, without version history; files in the copy start from a new created version with new memory_id values.

Archive a memory store

Call POST /v1/memory-stores/{id}/archive or click Archive on the console details page to archive an unused memory store. Archiving is irreversible. After archiving:
  • The memory store cannot be mounted in new sessions, and its metadata and memory files cannot be modified via the API.
  • Files and version history remain readable, and historical version content can still be redacted.

Delete a memory store

Call DELETE /v1/memory-stores/{id} to permanently delete a memory store along with all of its files and version history. The memory store’s Dreams policy is deleted together with it; its managed trigger is archived so it stops firing, while past run records are retained. A memory store must be archived first and must not be attached to any session.
Permanently deleting a memory store may result in unrecoverable data loss. Proceed with caution.

Dreams

Consolidate memory stores by policy, and inspect or restore changes through version history.

Create a Session

Learn how to create sessions and attach resources.

Sandbox Reference

Check memory store mount paths and sandbox boundaries.

Vaults

Manage credentials used by sessions.