MySQL Conversation Store

Direct MySQL conversation persistence with connection pooling

MySQL conversation store persists agent sessions and messages with automatic schema creation and connection pooling.

python
from praisonaiagents import Agent, MemoryConfig
from praisonaiagents import db

agent = Agent(
    name="MySQL Agent",
    instructions="Store conversations in MySQL",
    memory=MemoryConfig(
        db=db(database_url="mysql://user:pass@localhost:3306/praisonai"),
        session_id="mysql-session",
    ))
agent.start("Hello — save this conversation")

The user continues a thread; MySQL stores messages with connection pooling and auto schema.

Diagram

🤖 Agent

🗃️ MySQL Store

🔗 Connection Pool

🐬 MySQL

Quick Start

  1. Simple Usage
    bash
    pip install mysql-connector-python praisonai
    python
    from praisonaiagents import Agent, MemoryConfig
    from praisonaiagents import db
    
    agent = Agent(
        name="MySQL Agent",
        memory=MemoryConfig(
            db=db(database_url="mysql://user:pass@localhost:3306/praisonai"),
            session_id="session-1",
        ))
    agent.start("Hello!")
  2. With Configuration

    Use MySQLConversationStore directly when you need table prefixes or pool tuning:

    python
    from praisonai.persistence.conversation.mysql import MySQLConversationStore
    from praisonai.persistence import create_conversation_store
    
    store = MySQLConversationStore(
        host="localhost",
        port=3306,
        database="praisonai",
        user="root",
        password="secret",
        table_prefix="praison_",
        auto_create_tables=True,
        pool_size=5,
    )
    
    # Or via the registry
    store = create_conversation_store("mysql", url="mysql://user:pass@localhost/praisonai")

How It Works

Diagram
MySQLMySQLConversationStoreAgentMySQLMySQLConversationStoreAgentsave session / messageCREATE TABLE IF NOT EXISTSINSERT (pooled connection)persisted
FeatureDescription
Schema managementAuto-creates sessions and messages tables (SCHEMA_VERSION = "1.0.0")
Connection poolingConfigurable pool_size for concurrent agents
URL parsingmysql://user:pass@host:port/database format supported

Configuration Options

OptionTypeDefaultDescription
urlstrNoneFull 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

For async workloads, use create_conversation_store("async_mysql", ...) with aiomysql.


Best Practices

Use db() for most agents

Agent( memory=MemoryConfig( db=db(database_url="mysql://..."), )) is the simplest path — no manual store wiring needed.

Set table_prefix for multi-tenancy

Isolate apps on one database with different prefixes: table_prefix="prod_" vs table_prefix="staging_".

Tune pool_size for concurrency

Increase pool_size for high-traffic deployments; use smaller pools for serverless MySQL hosts.

Use SSL in production

Append ?ssl_mode=REQUIRED to the connection URL for encrypted connections.


Related