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

Quick Start

1

Choose Provider

Pick your preferred cloud database provider and get credentials:
from praisonaiagents import Agent

# Using Neon (PostgreSQL)
agent = Agent(
    name="Cloud Agent",
    instructions="You are a helpful assistant with persistent memory.",
    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.",
    db={
        "database_url": "libsql://mydb-user.turso.io",
        "auth_token": "eyJ..."
    }
)
2

Start Conversation

Your agent automatically gets persistent memory across sessions:
# 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

PostgreSQL Compatible

Neon, Supabase, CockroachDB, Xata use standard PostgreSQL drivers

Edge-First

Turso provides SQLite replicas at the edge for microsecond reads

How It Works

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

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

Common Patterns

Environment-Based Configuration

import os
from praisonaiagents import Agent

# 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.",
    db=True  # Auto-detects from environment variables
)

Multi-Provider Setup

from praisonai.db.adapter import PraisonAIDB

# Different stores for different purposes
db = PraisonAIDB(
    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", db=db)

Session Resume Pattern

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

  • 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
Set appropriate retry and timeout settings for serverless databases:
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
)
Design your agent interactions to be stateless between sessions:
agent = Agent(
    name="Stateless Agent",
    instructions="Always greet returning users and recap our last conversation.",
    db=True  # Persistence handles state across scale-to-zero cycles
)
Most providers offer usage dashboards. Set up alerts for:
  • Connection timeout increases (indicates cold starts)
  • Query latency spikes
  • Storage or bandwidth limits approaching

Local Databases

SQLite, PostgreSQL, MySQL for local development

Vector Databases

Qdrant, Pinecone, Weaviate for RAG and knowledge storage