uv pip install ddgs sqlalchemy openai to install dependencies.
Copy
Ask AI
"""Use SQLite as the database for an Agent.
Run `uv pip install ddgs sqlalchemy openai` to install dependencies.
"""
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.tools.websearch import WebSearchTools
# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
db = SqliteDb(db_file="tmp/data.db")
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
db=db,
tools=[WebSearchTools()],
add_history_to_context=True,
add_datetime_to_context=True,
)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
# The Agent sessions and runs will now be stored in SQLite
agent.print_response("How many people live in Canada?")
agent.print_response("What is their national anthem?")
agent.print_response("List my messages one by one")
Run the Example
Copy
Ask AI
# Clone and setup repo
git clone https://github.com/agno-agi/agno.git
cd agno/cookbook/06_storage/sqlite
# Create and activate virtual environment
./scripts/demo_setup.sh
source .venvs/demo/bin/activate
python sqlite_for_agent.py