# SingleStore for Workflow (/database/providers/singlestore/usage/singlestore-for-workflow)



`SingleStoreDb` stores a Workflow's sessions and run history in SingleStore.

## Usage [#usage]

Start in a [virtual environment](/sdk/setup).

Install dependencies:

```shell
uv pip install agno openai ddgs sqlalchemy pymysql
```

Get your SingleStore credentials from the [SingleStore portal](https://portal.singlestore.com/).

Set the endpoint values from your SingleStore workspace:

<CodeBlockTabs defaultValue="macOS / Linux">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="macOS / Linux">
      macOS / Linux
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="Windows">
      Windows
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="macOS / Linux">
    ```bash
    export SINGLESTORE_USERNAME="your_username"
    export SINGLESTORE_PASSWORD="your_password"
    export SINGLESTORE_HOST="your_host"
    export SINGLESTORE_PORT="3306"
    export SINGLESTORE_DATABASE="your_database"
    ```
  </CodeBlockTab>

  <CodeBlockTab value="Windows">
    ```powershell
    $Env:SINGLESTORE_USERNAME="your_username"
    $Env:SINGLESTORE_PASSWORD="your_password"
    $Env:SINGLESTORE_HOST="your_host"
    $Env:SINGLESTORE_PORT="3306"
    $Env:SINGLESTORE_DATABASE="your_database"
    ```
  </CodeBlockTab>
</CodeBlockTabs>

Set your OpenAI API key:

## Set OpenAI Key [#set-openai-key]

Set your `OPENAI_API_KEY` as an environment variable. You can get one [from OpenAI](https://platform.openai.com/account/api-keys).

<CodeBlockTabs defaultValue="Mac">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="Mac">
      Mac
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="Windows PowerShell">
      Windows PowerShell
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="Mac">
    ```bash
    export OPENAI_API_KEY=sk-***
    ```
  </CodeBlockTab>

  <CodeBlockTab value="Windows PowerShell">
    ```powershell
    $env:OPENAI_API_KEY = "your-openai-api-key"
    ```
  </CodeBlockTab>
</CodeBlockTabs>

```python title="singlestore_for_workflow.py"
from os import getenv
from sqlalchemy import URL

from agno.agent import Agent
from agno.db.singlestore import SingleStoreDb
from agno.models.openai import OpenAIResponses
from agno.team import Team
from agno.tools.hackernews import HackerNewsTools
from agno.tools.websearch import WebSearchTools
from agno.workflow.step import Step
from agno.workflow.workflow import Workflow

# Configure SingleStore DB connection
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)

hackernews_agent = Agent(
    name="HackerNews Agent",
    model=OpenAIResponses(id="gpt-5.2"),
    tools=[HackerNewsTools()],
    role="Extract key insights and content from HackerNews posts",
)
web_agent = Agent(
    name="Web Agent",
    model=OpenAIResponses(id="gpt-5.2"),
    tools=[WebSearchTools()],
    role="Search the web for the latest news and trends",
)

research_team = Team(
    name="Research Team",
    members=[hackernews_agent, web_agent],
    instructions="Research tech topics from HackerNews and the web",
)

content_planner = Agent(
    name="Content Planner",
    model=OpenAIResponses(id="gpt-5.2"),
    instructions=[
        "Plan a content schedule over 4 weeks for the provided topic and research content",
        "Ensure that I have posts for 3 posts per week",
    ],
)

research_step = Step(
    name="Research Step",
    team=research_team,
)

content_planning_step = Step(
    name="Content Planning Step",
    agent=content_planner,
)

if __name__ == "__main__":
    content_creation_workflow = Workflow(
        name="Content Creation Workflow",
        description="Automated content creation from blog posts to social media",
        db=db,
        steps=[research_step, content_planning_step],
    )
    content_creation_workflow.print_response(
        input="AI trends in 2024",
        markdown=True,
    )
```

## Run the example [#run-the-example]

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

```shell
python singlestore_for_workflow.py
```

## Parameters [#parameters]

| Parameter         | Type               | Default | Description                                                                                                      |
| ----------------- | ------------------ | ------- | ---------------------------------------------------------------------------------------------------------------- |
| `id`              | `Optional[str]`    | -       | Database ID. Derived deterministically from the URL (or engine URL) and schema when omitted.                     |
| `db_engine`       | `Optional[Engine]` | -       | The SQLAlchemy database engine to use.                                                                           |
| `db_schema`       | `Optional[str]`    | -       | The database schema to use.                                                                                      |
| `db_url`          | `Optional[str]`    | -       | The database URL to connect to.                                                                                  |
| `session_table`   | `Optional[str]`    | -       | Name of the table to store Agent, Team and Workflow sessions.                                                    |
| `memory_table`    | `Optional[str]`    | -       | Name of the table to store memories.                                                                             |
| `metrics_table`   | `Optional[str]`    | -       | Name of the table to store metrics.                                                                              |
| `eval_table`      | `Optional[str]`    | -       | Name of the table to store evaluation runs data.                                                                 |
| `knowledge_table` | `Optional[str]`    | -       | Name of the table to store knowledge content.                                                                    |
| `runs_table`      | `Optional[str]`    | -       | Name of the table to store runs for each session.                                                                |
| `traces_table`    | `Optional[str]`    | -       | Name of the table to store traces.                                                                               |
| `spans_table`     | `Optional[str]`    | -       | Name of the table to store spans.                                                                                |
| `versions_table`  | `Optional[str]`    | -       | Name of the table to store schema versions.                                                                      |
| `create_schema`   | `bool`             | `True`  | Whether to create the database schema if it doesn't exist. Set to `False` when the schema is managed externally. |
