Cloud-Native Serverless Databases

Scale-to-zero database persistence with Neon, Supabase, Turso, CockroachDB, and Xata

PraisonAI supports cloud-native serverless databases that automatically scale to zero when idle, reducing costs for bursty AI agent workloads.

python
from praisonaiagents import Agent, MemoryConfig

agent = Agent(
    name="data-agent",
    instructions="Persist session state to a serverless database.",
)
agent.start("Save this conversation to Neon.")

The user connects a serverless database URL; PraisonAI detects the provider and uses scale-to-zero persistence for bursty agent workloads.

Diagram

Cloud-Native Database Flow

neon.tech

supabase.co

turso.io

cockroachlabs.cloud

xata.sh

🤖 Agent

🔍 Detect Provider

💚 Neon

🟢 Supabase

🟦 Turso

🟤 CockroachDB

🟣 Xata

⚡ Serverless Features

🎯 Auto Scale

Supported URL Schemes

PraisonAIDB._detect_backend recognises these schemes:

SchemeBackend
sqlite://SQLite
postgres://, postgresql://PostgreSQL
mysql://MySQL
redis://Redis
libsql://LibSQL / Turso
http://, https://Cloud DB hosts (Neon, Supabase, etc.)

Hostname heuristics also detect Qdrant and Weaviate URLs.

Quick Start

  1. Choose Provider

    Pick your preferred cloud database provider and get credentials:

    python
    from praisonaiagents import Agent, MemoryConfig
    
    # Using Neon (PostgreSQL)
    agent = Agent(
        name="Cloud Agent",
        instructions="You are a helpful assistant with persistent memory.",
        memory=MemoryConfig(
            db={"database_url": "postgresql://user:pass@ep-xxx.neon.tech/db?sslmode=require"},
        ))
    
    # Using Turso (libSQL)
    agent = Agent(
        name="Edge Agent", 
        instructions="You are a helpful assistant with edge persistence.",
        memory=MemoryConfig(
            db={
                "database_url": "libsql://mydb-user.turso.io",
                "auth_token": "eyJ..."
            },
        ))
  2. Start Conversation

    Your agent automatically gets persistent memory across sessions:

    python
    # First conversation
    result = agent.start("Remember: My favorite color is blue")
    print(result)  # Agent confirms and stores this fact
    
    # Later (different session)
    result = agent.start("What's my favorite color?")
    print(result)  # "Your favorite color is blue"

Supported Providers

ProviderBackendProtocolAuto-ScaleEdge ReplicasFree Tier
NeonPostgreSQLpostgresql://✅❌0.5GB
SupabasePostgreSQL + RESTpostgresql:// or https://✅❌500MB
TursolibSQL/SQLitelibsql://✅✅9GB
CockroachDBPostgreSQLpostgresql://✅❌5GB
XataPostgreSQLpostgresql://✅❌15GB

How It Works

Diagram
Conversation StoreCloud ProviderPraisonDBAgentConversation StoreCloud ProviderPraisonDBAgentAuto-suspend after 5 mins idleStart sessionCold start connectionDatabase wakes upLoad conversation historyPrevious messagesSave new messageStore with retry logicPersist to serverless DBConfirmed

Serverless-Resilient Features

All cloud providers get these features automatically:

FeatureDescriptionBenefit
SSL Enforcementsslmode=require added automaticallySecurity compliance
Cold-Start Retry3 retries with exponential backoffHandles database wake-up
Extended Timeout30s connect timeout (vs 5s default)Accommodates scale-up delay
Connection RecoveryBroken connections discarded and replacedResilient to network issues

Installation

All Providers

bash
# Install PraisonAI with all database support
pip install "praisonai[databases]"

Individual Providers

bash
# PostgreSQL-based (Neon, CockroachDB, Xata, Supabase Direct)
pip install "praisonai[neon]"

# Turso/libSQL
pip install "praisonai[turso]"

# Supabase REST API
pip install supabase

Common Patterns

Environment-Based Configuration

python
import os
from praisonaiagents import Agent, MemoryConfig

# Set environment variables for your provider
os.environ["NEON_DATABASE_URL"] = "postgresql://user:pass@ep-xxx.neon.tech/db"

agent = Agent(
    name="Assistant",
    instructions="You are a helpful assistant.",
    memory=MemoryConfig(
        db=True,  # Auto-detects from environment variables
    ))

Multi-Provider Setup

python
from praisonaiagents import Agent, MemoryConfig, db

store = db(
    database_url="postgresql://user:pass@ep-xxx.neon.tech/conversations",  # Chat history
    state_url="redis://upstash-redis.com:6379",  # Session state
    knowledge_url="https://vector-db.qdrant.io",  # RAG knowledge
)

agent = Agent(
    name="Multi-Store Agent",
    memory=MemoryConfig(db=store),
)

Session Resume Pattern

python
from praisonai import ManagedAgent, LocalManagedConfig

# Create agent with cloud persistence
managed = ManagedAgent(
    provider="local",
    db={"database_url": "libsql://mydb-user.turso.io"},
    config=LocalManagedConfig(name="Persistent Agent")
)

# Save session for later resume
session_ids = managed.save_ids()

# Resume from any device/deployment
managed2 = ManagedAgent(provider="local", db=db)
managed2.resume_session(session_ids["session_id"])

Best Practices

Choose the Right Provider
  • Neon: Best for traditional PostgreSQL workloads with auto-scaling
  • Supabase: Great for rapid prototyping with built-in auth and REST API
  • Turso: Perfect for edge deployment and global distribution
  • CockroachDB: Ideal for distributed, multi-region applications
  • Xata: Excellent for full-text search and analytics use cases
Handle Cold Starts

Set appropriate retry and timeout settings for serverless databases:

python
from praisonai.db.adapter import NeonDB

db = NeonDB(
    database_url="postgresql://...",
    max_retries=5,  # More retries for cold starts
    retry_delay=1.0,  # Base delay between retries
)
Optimize for Scale-to-Zero

Design your agent interactions to be stateless between sessions:

python
agent = Agent(
    name="Stateless Agent",
    instructions="Always greet returning users and recap our last conversation.",
    memory=MemoryConfig(
        db=True,  # Persistence handles state across scale-to-zero cycles
    ))
Monitor Database Usage

Most providers offer usage dashboards. Set up alerts for:

  • Connection timeout increases (indicates cold starts)
  • Query latency spikes
  • Storage or bandwidth limits approaching

Related