Skip to main content
MySQL conversation store provides direct persistence for conversation sessions and messages with built-in serverless database optimization and retry logic.

Quick Start

1

Install Dependencies

Install the required MySQL driver:
pip install mysql-connector-python
2

Basic Usage

Use MySQL conversation store with URL connection:
from praisonaiagents import Agent
from praisonai.persistence.conversation.mysql_new import MySQLConversationStore

agent = Agent(
    name="MySQL Agent",
    instructions="Store conversations in MySQL",
    conversation_store=MySQLConversationStore(
        url="mysql://user:password@localhost:3306/praisonai"
    )
)

result = agent.start("Hello, store this conversation!")
3

With Configuration

Configure MySQL with all available options:
from praisonai.persistence.conversation.mysql_new import MySQLConversationStore

store = MySQLConversationStore(
    host="localhost",
    port=3306,
    database="praisonai", 
    user="root",
    password="secret",
    table_prefix="praison_",
    auto_create_tables=True,
    pool_size=5,
    max_retries=3,
    retry_delay=0.5
)

agent = Agent(
    name="Configured Agent",
    conversation_store=store
)

How It Works

FeatureDescription
Auto-retryExponential backoff for .psdb.cloud hosts
Schema ManagementAutomatic table creation with SCHEMA_VERSION = "1.0.0"
Connection PoolingConfigurable pool size for high concurrency
SQL BaseInherits unified schema from _SQLConversationStoreBase

Configuration Options

OptionTypeDefaultDescription
urlstrNoneComplete MySQL URL (overrides individual options)
hoststr"localhost"MySQL server hostname
portint3306MySQL server port
databasestr"praisonai"Database name
userstr"root"Database username
passwordstr""Database password
table_prefixstr"praison_"Prefix for table names
auto_create_tablesboolTrueCreate tables automatically
pool_sizeint5Connection pool size
max_retriesint3Maximum retry attempts for failed operations
retry_delayfloat0.5Base delay between retries (seconds)
Import Path: Due to current implementation, you must import from the submodule:
from praisonai.persistence.conversation.mysql_new import MySQLConversationStore
This will be improved in a future release to be available from the main package.

Common Patterns

PlanetScale Configuration

For PlanetScale serverless MySQL, use optimized retry settings:
store = MySQLConversationStore(
    url="mysql://user:pass@gateway.psdb.cloud:3306/mydb",
    max_retries=5,      # Higher retries for cold starts
    retry_delay=1.0,    # Longer initial delay
    pool_size=3         # Smaller pool for serverless
)

Connection URL Formats

Support for various MySQL URL formats:
# Standard MySQL
url="mysql://user:pass@localhost:3306/dbname"

# PlanetScale (auto-detected for retry behavior)
url="mysql://user:pass@gateway.psdb.cloud:3306/dbname"

# MySQL with SSL
url="mysql://user:pass@host:3306/db?ssl_mode=REQUIRED"

Async Context Manager

Use with async context manager for resource management:
from praisonai.persistence.conversation.mysql_new import MySQLConversationStore

async def main():
    async with MySQLConversationStore(
        url="mysql://user:pass@localhost/db"
    ) as store:
        # Store will be automatically closed
        session = await store.create_session(session_obj)

Best Practices

Serverless MySQL databases benefit from higher retry counts:
# For PlanetScale, Neon, or other serverless
store = MySQLConversationStore(
    max_retries=5,
    retry_delay=1.0,  # Exponential backoff: 1s, 2s, 4s, 8s, 16s
)
Configure appropriate pool size for your workload:
# High concurrency workload
store = MySQLConversationStore(pool_size=10)

# Serverless or low traffic  
store = MySQLConversationStore(pool_size=2)
Use table prefixes to isolate different applications:
# Production app
prod_store = MySQLConversationStore(table_prefix="prod_")

# Staging app  
staging_store = MySQLConversationStore(table_prefix="staging_")
The store uses SCHEMA_VERSION = "1.0.0" for migration tracking:
# Check current schema version
store = MySQLConversationStore()
print(store.SCHEMA_VERSION)  # "1.0.0"

Error Handling

The store automatically handles common MySQL errors:
try:
    store = MySQLConversationStore(url="mysql://invalid")
    session = store.create_session(session_obj)
except Exception as e:
    print(f"Connection failed: {e}")
For PlanetScale hosts (.psdb.cloud), transient errors trigger exponential backoff retry automatically.

Async Conversation Store

Async conversation persistence protocol

Persistence Backend Plugins

Extending SQL backends with _SQLConversationStoreBase