Assistants come with built-in memory but it only lasts while the session is active. To continue conversations across sessions, we store Assistant runs in a database like PostgreSQL.

Storage is a necessary component when building user facing AI products as any production application will require users to be able to “continue” their conversation with the AI.

The general syntax for adding storage to an Assistant looks like:
from import PgAssistantStorage

# Create a storage backend using the Postgres database
storage = PgAssistantStorage(
    # store runs in the ai.assistant_runs table
    # db_url: Postgres database URL

# Add storage to the Assistant
assistant = Assistant(storage=storage)

The following databases are supported as a storage backend: