Skip to main content
1

Create a Python file

touch memory_operations.py
2

Add the following code to your Python file

memory_operations.py
import asyncio

from agno.client import AgentOSClient


async def main():
    client = AgentOSClient(base_url="http://localhost:7777")
    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"],
    )
    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)
    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)
    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"],
    )
    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)
    print("   Memory deleted")


if __name__ == "__main__":
    asyncio.run(main())
3

Create a virtual environment

Open the Terminal and create a python virtual environment.
python3 -m venv .venv
source .venv/bin/activate
4

Install libraries

pip install -U agno openai
5

Export your OpenAI API key

export OPENAI_API_KEY="your_openai_api_key_here"
6

Start an AgentOS Server

Make sure you have an AgentOS server running with enable_user_memories=True configured on an agent. See Creating Your First OS for setup instructions.
7

Run the Client

python memory_operations.py