> ## Documentation Index
> Fetch the complete documentation index at: https://ikun.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# SingleStore 存储

Agno 支持使用 SingleStore 作为 Agent 的存储后端，通过 `SingleStoreStorage` 类实现。

## 用法

从 [这里](https://portal.singlestore.com/) 获取 SingleStore 的凭证。

```python singlestore_storage_for_agent.py theme={null}
from os import getenv

from sqlalchemy.engine import create_engine

from agno.agent import Agent
from agno.storage.singlestore import SingleStoreStorage

# SingleStore 配置
USERNAME = getenv("SINGLESTORE_USERNAME")
PASSWORD = getenv("SINGLESTORE_PASSWORD")
HOST = getenv("SINGLESTORE_HOST")
PORT = getenv("SINGLESTORE_PORT")
DATABASE = getenv("SINGLESTORE_DATABASE")
SSL_CERT = getenv("SINGLESTORE_SSL_CERT", None)

# SingleStore 数据库 URL
db_url = f"mysql+pymysql://{USERNAME}:{PASSWORD}@{HOST}:{PORT}/{DATABASE}?charset=utf8mb4"
if SSL_CERT:
    db_url += f"&ssl_ca={SSL_CERT}&ssl_verify_cert=true"

# 创建数据库引擎
db_engine = create_engine(db_url)

# 使用 Singlestore 数据库创建存储后端
storage = SingleStoreStorage(
    # 将会话存储在 ai.sessions 表中
    table_name="agent_sessions",
    # db_engine: Singlestore 数据库引擎
    db_engine=db_engine,
    # schema: Singlestore schema
    schema=DATABASE,
)

# 将存储添加到 Agent
agent = Agent(storage=storage)
```

## 参数

<Snippet file="storage-s2-params.mdx" />

## 开发者资源

* 查看 [Cookbook](https://github.com/agno-agi/agno/blob/main/cookbook/storage/singlestore_storage/singlestore_storage_for_agent.py)
