memory
The memory namespace provides persistent key-value storage for your agent. All data is scoped to your agent session and persists across executions. Use memory to track state, store configuration, or maintain context between runs. Memory is automatically scoped to your session ID, and for now is simple string storage. You will need to handle serialization of whatever data you want to store here.
memory.set()
memory.set()Store a string value with a unique key.
Signature
agent.memory.set(
key: str,
value: str
) -> MemorySetResponseParameters
key
str
Unique identifier for the value (1 - 255 characters)
value
str
String value to store
Returns
MemorySetResponse
class MemorySetResponse:
success: bool
data: {
key: str # The key that was set
} | None
error: str | None
error_details: dict | NoneExamples
# Set a value
result = agent.memory.set("lastSwapNetwork", "ethereum:42161")
if result.success and result.data:
agent.log(f"Stored key: {result.data.key}")
else:
agent.log(result.error, error=True)Common Errors
"Invalid key"
Key too long (>255 chars) or empty
Use keys between 1-255 characters
"Invalid value"
Value exceeds size limit
Keep values reasonable size, consider splitting large data
memory.get()
memory.get()Retrieve a previously stored value by key.
Signature
agent.memory.get(
key: str
) -> MemoryGetResponseParameters
key
str
The key to retrieve
Returns
MemoryGetResponse
class MemoryGetResponse:
success: bool
data: {
key: str, # The requested key
value: str # The stored value
} | None
error: str | None
error_details: dict | NoneExamples
# Get a value
result = agent.memory.get("lastSwapNetwork")
if result.success and result.data:
agent.log(f"Network: {result.data.value}")
else:
agent.log(f"Key not found: {result.error}", error=True)Common Errors
"Key not found"
Key doesn't exist in memory
Check if key exists first, or handle missing keys gracefully
memory.delete()
memory.delete()Remove a key-value pair from storage. Succeeds even if the key doesn't exist.
Signature
agent.memory.delete(
key: str
) -> MemoryDeleteResponseParameters
key
str
The key to delete
Returns
MemoryDeleteResponse
class MemoryDeleteResponse:
success: bool
data: {
key: str # The deleted key
} | None
error: str | None
error_details: dict | NoneExamples
# Get a key
result = agent.memory.delete("tempSwapQuote")
if result.success and result.data:
agent.log(f"Deleted key: {result.data.key}")memory.list()
memory.list()Get an array of all keys stored for this agent session. Useful for debugging or iterating through stored data.
Signature
agent.memory.list() -> MemoryListResponseReturns
MemoryListResponse
class MemoryListResponse:
success: bool
data: {
keys: list[str], # Array of all stored keys
count: int # Total number of keys
} | None
error: str | None
error_details: dict | NoneExamples
# List all keys
result = agent.memory.list()
if result.success and result.data:
agent.log(f"Found {result.data.count} keys: {', '.join(result.data.keys)}")
# Iterate through all stored values
for key in result.data.keys:
value = agent.memory.get(key)
if value.success and value.data:
agent.log(f"{key}: {value.data.value}")Last updated