SingleStore for Agent

Store agent sessions and run history in SingleStore with SingleStoreDb.

SingleStoreDb stores an Agent's sessions and run history in SingleStore.

Usage

Start in a virtual environment.

Install dependencies:

uv pip install agno openai ddgs sqlalchemy pymysql

Get your SingleStore credentials from the SingleStore portal, then set the connection values and OpenAI API key:

export SINGLESTORE_USERNAME="your_singlestore_username"
export SINGLESTORE_PASSWORD="your_singlestore_password"
export SINGLESTORE_HOST="your_singlestore_host"
export SINGLESTORE_PORT="3306"
export SINGLESTORE_DATABASE="your_singlestore_database"
export OPENAI_API_KEY="your_openai_api_key_here"
singlestore_for_agent.py
from os import getenv
from sqlalchemy import URL

from agno.agent import Agent
from agno.db.singlestore import SingleStoreDb
from agno.tools.websearch import WebSearchTools

db_url = URL.create(
    drivername="mysql+pymysql",
    username=getenv("SINGLESTORE_USERNAME"),
    password=getenv("SINGLESTORE_PASSWORD"),
    host=getenv("SINGLESTORE_HOST"),
    port=int(getenv("SINGLESTORE_PORT", "3306")),
    database=getenv("SINGLESTORE_DATABASE"),
    query={"charset": "utf8mb4"},
).render_as_string(hide_password=False)

db = SingleStoreDb(db_url=db_url)

agent = Agent(
    db=db,
    tools=[WebSearchTools()],
    add_history_to_context=True,
)
agent.print_response("How many people live in Canada?")
agent.print_response("What is their national anthem called?")

Run the example

Save the code as singlestore_for_agent.py, ensure your SingleStore database is running, and run:

python singlestore_for_agent.py

Parameters

ParameterTypeDefaultDescription
idOptional[str]-Database ID. Derived deterministically from the URL (or engine URL) and schema when omitted.
db_engineOptional[Engine]-The SQLAlchemy database engine to use.
db_schemaOptional[str]-The database schema to use.
db_urlOptional[str]-The database URL to connect to.
session_tableOptional[str]-Name of the table to store Agent, Team and Workflow sessions.
memory_tableOptional[str]-Name of the table to store memories.
metrics_tableOptional[str]-Name of the table to store metrics.
eval_tableOptional[str]-Name of the table to store evaluation runs data.
knowledge_tableOptional[str]-Name of the table to store knowledge content.
runs_tableOptional[str]-Name of the table to store runs for each session.
traces_tableOptional[str]-Name of the table to store traces.
spans_tableOptional[str]-Name of the table to store spans.
versions_tableOptional[str]-Name of the table to store schema versions.
create_schemaboolTrueWhether to create the database schema if it doesn't exist. Set to False when the schema is managed externally.