Skip to main content
The SQLiteDb class provides SQLite storage for agents, sessions, memories, and more. It’s perfect for development, testing, and lightweight deployments.

Constructor

from agno.db.sqlite import SQLiteDb

db = SQLiteDb(db_file="agent.db")

Parameters

db_file
str
default:"tmp/agno.db"
Path to the SQLite database file.
create_tables
bool
default:"True"
If True, automatically creates required tables.
session_table
str
default:"agno_sessions"
Name of the sessions table.
memory_table
str
default:"agno_memories"
Name of the memories table.
knowledge_table
str
default:"agno_knowledge"
Name of the knowledge table.
metrics_table
str
default:"agno_metrics"
Name of the metrics table.
And other table names for eval, traces, components, etc.

Methods

Inherits all methods from BaseDb.

close()

Close database connections.
db.close()

Example Usage

from agno import Agent
from agno.db.sqlite import SQLiteDb

db = SQLiteDb(db_file="my_agent.db")

agent = Agent(
    name="Assistant",
    model="gpt-4o",
    db=db,
    add_history_to_context=True
)

# Conversations are automatically saved
response = agent.run("Hello!", user_id="user_1")
response = agent.run("What did I just say?", user_id="user_1")

# Get session history
session = agent.get_session()
print(f"Session has {len(session.runs)} runs")

Configuration

Custom Database Location

db = SQLiteDb(db_file="/path/to/database.db")

Custom Table Names

db = SQLiteDb(
    db_file="agent.db",
    session_table="my_sessions",
    memory_table="my_memories"
)

In-Memory Database

# For testing
db = SQLiteDb(db_file=":memory:")

Best Practices

  1. Close connections: Call db.close() when shutting down
  2. Use for development: SQLite is great for development and small deployments
  3. PostgreSQL for production: Use PostgreSQL for production workloads
  4. Backup regularly: SQLite is just a file - back it up regularly
  5. One writer at a time: SQLite doesn’t handle concurrent writes well

Limitations

  • Limited concurrency (single writer)
  • Not suitable for high-traffic production deployments
  • No built-in replication
  • Use PostgreSQL for production environments

Build docs developers (and LLMs) love