API Reference

Storage Reference

API reference for the storage function, StorageHandlers, StorageStep, and localStorage.

Passed to agent(name, { storage: ... }) to configure the storage backend.

The Storage Function

Storage is a function that receives a StorageStep and dispatches it to your handlers via store.on():

agent("my-agent", {
  async storage(store) {
    return await store.on({
      "session.get": async ({ id }) => { /* ... */ },
      // ...
    });
  },
})

To add workflow support, add "use step" at the top:

agent("my-agent", {
  async storage(store) {
    "use step";
    return await store.on({ /* same handlers */ });
  },
})

The function signature is:

type StorageStepFunction = (store: StorageStep) => Promise<any>;

StorageHandlers

The object passed to store.on(). A flat map of async handler functions, one per storage operation.

type StorageHandlers = {
  "session.get"(p: { id: string }): Promise<Session | null>;
  "session.set"(p: { id: string; value: Session }): Promise<void>;
  "session.update"(p: { id: string; updates: Partial<Session> }): Promise<Session>;

  "message.get"(p: { id: string }): Promise<Message | null>;
  "message.set"(p: { id: string; value: Message }): Promise<void>;
  "message.update"(p: { id: string; updates: Partial<Message> }): Promise<Message>;
  "message.listBySession"(p: { sessionId: string }): Promise<Message[]>;

  "part.get"(p: { id: string }): Promise<Part | null>;
  "part.set"(p: { id: string; value: Part }): Promise<void>;
  "part.listBySession"(p: { sessionId: string }): Promise<Part[]>;

  "sandbox.get"(p: { id: string }): Promise<Sandbox | null>;
  "sandbox.set"(p: { id: string; value: Sandbox }): Promise<void>;
  "sandbox.update"(p: { id: string; updates: Partial<Sandbox> }): Promise<Sandbox>;

  "setup.get"(p: { id: string }): Promise<Setup | null>;
  "setup.set"(p: { id: string; value: Setup }): Promise<void>;
};

StorageStep

A serializable envelope that carries a storage operation. Dispatches to your handlers via store.on().

class StorageStep {
  event: StorageCall;
  on(handlers: StorageHandlers): Promise<any>;
}

StorageCall is a discriminated union derived from StorageHandlers — each variant has a method field and the corresponding parameters:

type StorageCall = {
  [K in keyof StorageHandlers]: { method: K } & Parameters<StorageHandlers[K]>[0];
}[keyof StorageHandlers];

StorageStep implements @workflow/serde serialization, so it survives workflow replay without any extra configuration.

localStorage

Built-in filesystem-backed storage for development. Returns a function compatible with the storage option.

import { localStorage } from "experimental-agent/storage";
ParameterTypeDefaultDescription
dirstring".agent"Directory path for JSON storage files.
// @fragment expression
localStorage()
localStorage({ dir: ".my-data" })

Data is stored as {dir}/session/{id}.json, {dir}/message/{id}.json, etc.

Stored Types

Session

FieldTypeDescription
idstringSession identifier.
createdAtnumberCreation timestamp.
updatedAtnumberLast update timestamp.
modelstringModel ID.
systemstring | undefinedSystem prompt.
generationobject | undefinedGeneration options.
lastMessageIdstring | undefinedID of the most recent message.
activeToolsstring[] | undefinedActive tool names.

Message

FieldTypeDescription
idstringMessage identifier.
sessionIdstringParent session.
role"user" | "assistant"Message role.
createdAtnumberCreation timestamp.
usageobject | undefinedToken usage for this message.
workflowRunIdstring | undefinedWorkflow run that generated this message.

Part

FieldTypeDescription
idstringPart identifier.
sessionIdstringParent session.
messageIdstringParent message.
typestringPart type (text, tool-call, tool-result, etc.).
indexnumberPosition within the message.

Sandbox

FieldTypeDescription
idstringSandbox identifier.
createdAtnumberCreation timestamp.
updatedAtnumberLast update timestamp.
bindingstringSandbox binding type.
metadataobject | undefinedProvider-specific metadata.

See also

  • Storage — Concepts and design philosophy
  • Custom Storage — Full implementation guide with @vercel/kv2 example
  • agent() — Setting storage on the agent