Memory Operations
Create, update, list, and delete user memories
Create a Python file
import asyncio
import os
from agno.client import AgentOSClient
HEADERS = {"Authorization": f"Bearer {os.environ['OS_SECURITY_KEY']}"}
async def main():
client = AgentOSClient(base_url="http://localhost:7778")
user_id = "example-user"
print("=" * 60)
print("Memory Operations")
print("=" * 60)
# Create a memory
print("\n1. Creating a memory...")
memory = await client.create_memory(
memory="User prefers dark mode for all applications",
user_id=user_id,
topics=["preferences", "ui"],
headers=HEADERS,
)
print(f" Created memory: {memory.memory_id}")
print(f" Content: {memory.memory}")
print(f" Topics: {memory.topics}")
# List memories for the user
print("\n2. Listing memories...")
memories = await client.list_memories(user_id=user_id, headers=HEADERS)
print(f" Found {len(memories.data)} memories for user {user_id}")
for mem in memories.data:
print(f" - {mem.memory_id}: {mem.memory[:50]}...")
# Get a specific memory
print(f"\n3. Getting memory {memory.memory_id}...")
retrieved = await client.get_memory(memory.memory_id, user_id=user_id, headers=HEADERS)
print(f" Memory: {retrieved.memory}")
# Update the memory
print("\n4. Updating memory...")
updated = await client.update_memory(
memory_id=memory.memory_id,
memory="User strongly prefers dark mode for all applications and websites",
user_id=user_id,
topics=["preferences", "ui", "accessibility"],
headers=HEADERS,
)
print(f" Updated memory: {updated.memory}")
print(f" Updated topics: {updated.topics}")
# Delete the memory
print(f"\n5. Deleting memory {memory.memory_id}...")
await client.delete_memory(memory.memory_id, user_id=user_id, headers=HEADERS)
print(" Memory deleted")
if __name__ == "__main__":
asyncio.run(main())Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U "agno[os]" openaiSet the server model key
Set this key in the terminal that starts the example server. The client sends requests to AgentOS and does not call OpenAI directly.
export OPENAI_API_KEY="your_openai_api_key_here"Start an AgentOS Server
Set OS_SECURITY_KEY in the client terminal to the same value used by the server. The code sends it as a bearer credential on each request.
export OS_SECURITY_KEY="your_os_security_key_here"Start the client example server on port 7778. It registers a SQLite database for the memory API. This client creates and edits memories explicitly; the server example does not enable automatic memory updates on agent runs.
Run the Client
python memory_operations.py