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 Agentagent = 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.
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.
PR #2122: Passing a URL whose scheme cannot be inferred now raises ValueError instead of falling back to SQLite:Unable to infer DB backend from URL '...'; supported schemes: postgres://, mysql://, sqlite://, redis://, libsql://, http(s)://Set the URL explicitly, e.g. sqlite:///mydata.db.
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 conversationresult = 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"
import osfrom praisonaiagents import Agent# Set environment variables for your provideros.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)
from praisonai.db.adapter import PraisonAIDB# Different stores for different purposesdb = 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)
from praisonai import ManagedAgent, LocalManagedConfig# Create agent with cloud persistencemanaged = ManagedAgent( provider="local", db={"database_url": "libsql://mydb-user.turso.io"}, config=LocalManagedConfig(name="Persistent Agent"))# Save session for later resumesession_ids = managed.save_ids()# Resume from any device/deploymentmanaged2 = ManagedAgent(provider="local", db=db)managed2.resume_session(session_ids["session_id"])
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 NeonDBdb = 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.", db=True # Persistence handles state across scale-to-zero cycles)
Monitor Database Usage
Most providers offer usage dashboards. Set up alerts for: