Skip to main content
Create an agent that remembers past conversations using a SQLite-backed memory store.
1

Create the agent

agent_memory.py
from definable.agent import Agent
from definable.memory import Memory, SQLiteStore

agent = Agent(
    model="gpt-4o",
    instructions="You are a helpful assistant with persistent memory.",
    memory=Memory(store=SQLiteStore("./memory.db")),
)

# First conversation — the agent stores this
output = agent.run("My name is Alice and I work at Acme Corp.", user_id="alice")
print(output.content)

# Second conversation — the agent recalls
output = agent.run("Where do I work?", user_id="alice")
print(output.content)  # "You work at Acme Corp."
2

Install dependencies

pip install definable
3

Export your API key

export OPENAI_API_KEY=sk-***
4

Run

python agent_memory.py
The agent stores facts from the first conversation and recalls them in the second.
For quick testing without persistent storage, use memory=True:
agent = Agent(model="gpt-4o", memory=True)  # InMemoryStore