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.
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.
Supported URL Schemes
PraisonAIDB._detect_backend recognises these schemes:
| Scheme | Backend |
|---|---|
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
- 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..." }, )) - 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
| Provider | Backend | Protocol | Auto-Scale | Edge Replicas | Free Tier |
|---|---|---|---|---|---|
| Neon | PostgreSQL | postgresql:// | ✅ | ❌ | 0.5GB |
| Supabase | PostgreSQL + REST | postgresql:// or https:// | ✅ | ❌ | 500MB |
| Turso | libSQL/SQLite | libsql:// | ✅ | ✅ | 9GB |
| CockroachDB | PostgreSQL | postgresql:// | ✅ | ❌ | 5GB |
| Xata | PostgreSQL | postgresql:// | ✅ | ❌ | 15GB |
Neon, Supabase, CockroachDB, Xata use standard PostgreSQL drivers
Edge-FirstTurso provides SQLite replicas at the edge for microsecond reads
How It Works
Serverless-Resilient Features
All cloud providers get these features automatically:
| Feature | Description | Benefit |
|---|---|---|
| SSL Enforcement | sslmode=require added automatically | Security compliance |
| Cold-Start Retry | 3 retries with exponential backoff | Handles database wake-up |
| Extended Timeout | 30s connect timeout (vs 5s default) | Accommodates scale-up delay |
| Connection Recovery | Broken connections discarded and replaced | Resilient to network issues |
Installation
All Providers
# Install PraisonAI with all database support
pip install "praisonai[databases]"Individual Providers
# PostgreSQL-based (Neon, CockroachDB, Xata, Supabase Direct)
pip install "praisonai[neon]"
# Turso/libSQL
pip install "praisonai[turso]"
# Supabase REST API
pip install supabaseCommon Patterns
Environment-Based Configuration
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
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
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:
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:
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