Skip to main content

01 — Basic Memory

An agent with SQLiteMemoryStore that remembers across turns. Demonstrates the simplest memory setup.
from definable.agents import Agent
from definable.memory import CognitiveMemory, SQLiteMemoryStore
from definable.models import OpenAIChat

store = SQLiteMemoryStore(db_path="./example_memory.db")
memory = CognitiveMemory(store=store, token_budget=300)

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 all 19 MemoryStore protocol methods using InMemoryStore. Useful for understanding the data model without any external dependencies.
from definable.memory import InMemoryStore, Episode, KnowledgeAtom, Procedure

store = InMemoryStore()
await store.initialize()

# Store an episode
episode_id = await store.store_episode(Episode(
  id="ep-1",
  user_id="alice",
  session_id="sess-1",
  role="user",
  content="I work at Acme Corp.",
  topics=["work", "acme"],
))

# Store a knowledge atom
atom_id = await store.store_atom(KnowledgeAtom(
  id="atom-1",
  user_id="alice",
  subject="Alice",
  predicate="works-at",
  object="Acme Corp",
  content="Alice works at Acme Corp.",
))

# Query
episodes = await store.get_episodes(user_id="alice")
atoms = await store.get_atoms(user_id="alice")

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)
# - SQLiteMemoryStore (always, aiosqlite is a core dep)
# - PostgresMemoryStore (if asyncpg installed)
# - ChromaMemoryStore (if chromadb installed)
# - QdrantMemoryStore (if qdrant-client installed)
# - PineconeMemoryStore (if pinecone installed)

Full source

definable/examples/memory/03_store_backends.py