> ## Documentation Index
> Fetch the complete documentation index at: https://docs.definable.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Memory Examples

> Examples for session memory, store backends, and agent integration.

## 01 — Basic Memory

An agent with `SQLiteStore` that remembers conversation history across turns. Demonstrates the simplest memory setup.

```python theme={null}
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)
```

<Card title="Full source" icon="github" href="https://github.com/definable-ai/definable/blob/main/definable/examples/memory/01_basic_memory.py">
  `definable/examples/memory/01_basic_memory.py`
</Card>

## 02 — Store Protocol

Exercises the `MemoryStore` protocol methods using `InMemoryStore`. Useful for understanding the data model without any external dependencies.

```python theme={null}
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)
```

<Card title="Full source" icon="github" href="https://github.com/definable-ai/definable/blob/main/definable/examples/memory/02_store_protocol.py">
  `definable/examples/memory/02_store_protocol.py`
</Card>

## 03 — Store Backends

Smoke-tests all available memory store backends. Detects which optional dependencies are installed and tests each one.

```python theme={null}
# Tests whichever backends are available:
# - InMemoryStore (always)
# - SQLiteStore (always, aiosqlite is a core dep)
# - FileStore (JSONL-based, always available)
```

<Card title="Full source" icon="github" href="https://github.com/definable-ai/definable/blob/main/definable/examples/memory/03_store_backends.py">
  `definable/examples/memory/03_store_backends.py`
</Card>
