run cycles within a session — for example, storing the last rebalance timestamp to avoid trading too frequently, tracking cumulative PnL, or caching external API responses.
Access memory methods via agent.memory.
Set Value
Store a key-value pair.key(string): Unique identifier (1-255 characters)value(string): String value to store
success(boolean): Whether the operation succeededdata.key(string): The key that was set (on success)error(string | null): Error message (on failure)
Get Value
Retrieve a value by key.key(string): The key to retrieve
success(boolean): Whether the operation succeededdata.key(string): The requested key (on success)data.value(string): The stored value (on success)error(string | null): Error message if key not found
Delete Value
Remove a key-value pair.key(string): The key to delete
success(boolean): Whether the operation succeededdata.key(string): The deleted key (on success)error(string | null): Error message (on failure)
List Session Memory Keys
List all keys in session memory.success(boolean): Whether the operation succeededdata.keys(string[]): Array of all stored keys (on success)data.count(number): Number of keys (on success)error(string | null): Error message (on failure)
Notes
- Values must be strings. Serialize complex data (JSON, numbers) before storing.
- Keys must be 1-255 characters.
- 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.
delete()is idempotent — it succeeds even if the key does not exist.- Memory is backed by object storage (R2). Reads and writes have low but non-zero latency — avoid calling memory methods in tight loops.
- For tracking position changes within an execution cycle, memory is often more reliable than polling
getCurrentPositions(). See Positions for details.
See Also
- Positions — Use memory to track position deltas instead of polling
- Execution Model — How the run loop and session lifecycle work