Memory

Session-scoped key-value storage. Keys are automatically namespaced by agentId and sessionId.

Access memory methods via agent.memory.<method>

Set value

Store a key-value pair.

async set(key: string, value: string): Promise<MemorySetResponse>

Parameters:

  • key (string): Unique identifier (1-255 characters)

  • value (string): String value to store

Response:

  • success (boolean): Whether the operation succeeded

  • data.key (string): The key that was set (on success)

  • error (string | null): Error message (on failure)

Example:

const result = await agent.memory.set("lastSwapNetwork", "ethereum:42161");
if (result.success && result.data) {
  await agent.log(`Stored: ${result.data.key}`);
}

Get value

Retrieve a value by key.

Parameters:

  • key (string): The key to retrieve

Response:

  • success (boolean): Whether the operation succeeded

  • data.key (string): The requested key (on success)

  • data.value (string): The stored value (on success)

  • error (string | null): Error message if key not found

Example:

Delete value

Remove a key-value pair.

Parameters:

  • key (string): The key to delete

Response:

  • success (boolean): Whether the operation succeeded

  • data.key (string): The deleted key (on success)

  • error (string | null): Error message (on failure)

Note: Succeeds even if the key doesn't exist.

Example:

List session memory keys

List all keys in session memory.

Response:

  • success (boolean): Whether the operation succeeded

  • data.keys (string[]): Array of all stored keys (on success)

  • data.count (number): Number of keys (on success)

  • error (string | null): Error message (on failure)

Example:

Notes

  • Values must be strings. Serialize complex data (JSON, numbers) before storing.

  • Keys are automatically scoped to the current agent session.

  • Memory persists across execution cycles within the same session.

  • Storage is cleared when the session ends.

Last updated