Give an agent persistent memory across conversations.
Create an agent that remembers past conversations using a SQLite-backed memory store.
1
Create the agent
agent_memory.py
from definable.agent import Agentfrom definable.memory import Memory, SQLiteStoreagent = Agent( model="gpt-4o", instructions="You are a helpful assistant with persistent memory.", memory=Memory(store=SQLiteStore("./memory.db")),)# First conversation — the agent stores thisoutput = agent.run("My name is Alice and I work at Acme Corp.", user_id="alice")print(output.content)# Second conversation — the agent recallsoutput = 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: