Use memory to persist state betweenDocumentation Index
Fetch the complete documentation index at: https://docs.circuit.org/llms.txt
Use this file to discover all available pages before exploring further.
run cycles — 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.
Shared vs Session Memory
Memory supports two scopes:| Session (default) | Shared | |
|---|---|---|
| Isolation | Each session has its own keyspace | Accessible across all sessions of the same agent |
| Lifetime | Cleared when the session ends | Persists independently of any session |
| Use when | Tracking per-session state (cycle counters, last-run timestamps) | Storing learned configuration, cross-session counters, shared lookup data |
| Concurrency | Single session — no conflicts | Last-write-wins across concurrent sessions |
{ shared: true } (TypeScript) or shared=True (Python) to any memory method to use shared scope. Omitting the option defaults to session scope.
Set Value
Store a key-value pair.key(string): Unique identifier (1-255 characters)value(string): String value to storeshared/options.shared(boolean, optional): If true, store in shared memory
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 retrieveshared/options.shared(boolean, optional): If true, read from shared memory
success(boolean): Whether the operation succeededdata.key(string): The requested key (on success)data.value(string): The stored value (on success)data.updatedAt(number): Unix timestamp in seconds of when the value was last written — accessed asdata.updated_atin Python (on success)error(string | null): Error message if key not found
Delete Value
Remove a key-value pair.key(string): The key to deleteshared/options.shared(boolean, optional): If true, delete from shared memory
success(boolean): Whether the operation succeededdata.key(string): The deleted key (on success)error(string | null): Error message (on failure)
List Keys
Enumerate keys in the current scope, optionally filtered by a prefix. Results are returned in lexicographic ascending order.prefix(string, optional): Only return keys that start with this prefixshared/options.shared(boolean, optional): If true, list shared-scope keys
prefix or shared must be present — agent.memory.list({}) is a type error. Call agent.memory.list() with no argument for the default session-scoped enumeration.
Response:
success(boolean): Whether the operation succeededdata.items({ key, updatedAt }[]/list[MemoryListItem]): Matching keys with last-updated timestamps (on success)error(string | null): Error message (on failure)
list() returns at most 1000 items per call. If you expect to manage more than 1000 keys in a single scope, use a more granular prefix to scope the result, or restructure how you store state.
Example:
Notes
- Values must be strings. Serialize complex data (JSON, numbers) before storing.
- Keys must be 1-255 characters.
- Session and shared memory are completely separate namespaces — the same key name can exist in both without collision.
- Session memory persists across execution cycles within the same session and is cleared when the session ends.
- Shared memory persists independently of any session and is accessible from all sessions of the same agent.
- Shared memory uses last-write-wins concurrency — if two sessions write the same key simultaneously, the last write is kept.
delete()is idempotent — it succeeds even if the key does not exist.- API transport: The SDKs send a
?scope=sharedor?scope=sessionquery parameter to the underlying REST endpoints. Valid values are"session"(default) and"shared". Invalid values return a 400 error. - 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