Skip to main content

01 — Basic Memory

An agent with SQLiteStore that remembers conversation history across turns. Demonstrates the simplest memory setup.
from definable.agent import Agent
from definable.memory import Memory, SQLiteStore
from definable.model import OpenAIChat

memory = Memory(store=SQLiteStore("./example_memory.db"))

agent = Agent(
  model=OpenAIChat(id="gpt-4o-mini"),
  instructions="You are a helpful assistant with persistent memory.",
  memory=memory,
)

# Store information
output = agent.run(
  "My name is Alice and I'm a software engineer at Acme Corp.",
  user_id="alice",
)
print(output.content)

# Recall information
output = agent.run("What do you know about me?", user_id="alice")
print(output.content)

Full source

definable/examples/memory/01_basic_memory.py

02 — Store Protocol

Exercises the MemoryStore protocol methods using InMemoryStore. Useful for understanding the data model without any external dependencies.
from definable.memory import InMemoryStore
from definable.memory.types import MemoryEntry

store = InMemoryStore()
await store.initialize()

# Store a conversation entry
entry = MemoryEntry(
  session_id="s1",
  user_id="alice",
  role="user",
  content="Hello, I'm Alice from San Francisco.",
)
await store.add(entry)

# Query entries
entries = await store.get_entries("s1", user_id="alice")
for e in entries:
  print(f"[{e.memory_id}] {e.role}: {e.content}")

# Delete
await store.delete(entry.memory_id)

Full source

definable/examples/memory/02_store_protocol.py

03 — Store Backends

Smoke-tests all available memory store backends. Detects which optional dependencies are installed and tests each one.
# Tests whichever backends are available:
# - InMemoryStore (always)
# - SQLiteStore (always, aiosqlite is a core dep)
# - FileStore (JSONL-based, always available)

Full source

definable/examples/memory/03_store_backends.py