Use this file to discover all available pages before exploring further.
Turso provides SQLite-compatible databases at the edge with embedded replicas, delivering microsecond reads and global distribution for your AI agents.
from praisonaiagents import Agentagent = Agent( name="Edge Agent", instructions="You are a fast AI assistant with edge persistence.", db={ "database_url": "libsql://mydb-user.turso.io", "auth_token": "eyJhbGci..." })# Microsecond reads from local replicaresult = agent.start("I need responses with minimal latency")print(result)
3
Test Edge Performance
import time# Time a conversation round-tripstart = time.perf_counter()result = agent.start("What's the quickest database option?")end = time.perf_counter()print(f"Response time: {(end - start) * 1000:.1f}ms")print(f"Agent: {result}")# Typically 1-5ms for local reads
from praisonai.persistence.conversation.turso import TursoConversationStorestore = TursoConversationStore( url="libsql://mydb-user.turso.io", auth_token="eyJhbGci...", local_path="agent_replica.db", # Local SQLite file sync_on_write=True # Sync to remote after writes)# Reads are microsecond-fast from local file# Writes sync to global edge network
store = TursoConversationStore( url="libsql://mydb-user.turso.io", auth_token="eyJhbGci...", local_path=None # No local replica)# All operations go to remote - higher latency but always consistent
store = TursoConversationStore( url=None, # No remote sync local_path="dev_agent.db")# Fastest possible - no network calls# Perfect for development and testing
# Add replica in Europeturso db replicate mydb --region fra# Add replica in Asia turso db replicate mydb --region nrt# List all replicasturso db show mydb --replicas
from praisonai.db.adapter import TursoDB# Embedded replica: microsecond reads, durable writesdb = TursoDB( local_path="fast_agent_replica.db", # Local SSD storage sync_on_write=True # Immediate durability)# For highest performance, batch writesstore = TursoConversationStore(sync_on_write=False)# ... multiple operations ...store._sync() # Single sync operation
Handle Network Partitions
Embedded replicas continue working during network outages:
# Agent keeps working even if network failsagent = Agent( name="Resilient Agent", instructions="You work offline with local replica.", db=TursoDB(local_path="offline_replica.db"))# Reads always work from local file# Writes queue for next sync when network returns
Monitor Replica Size
Local replicas grow with conversation history:
import osreplica_path = "agent_replica.db"if os.path.exists(replica_path): size_mb = os.path.getsize(replica_path) / 1024 / 1024 print(f"Replica size: {size_mb:.1f}MB") # Archive old conversations if replica gets large if size_mb > 100: # 100MB threshold # Implement archiving logic pass
Use Multiple Databases
Separate different data types for optimal performance:
# Separate DBs for different purposesconversation_db = TursoDB( database_url="libsql://conversations.turso.io", local_path="conversations.db")analytics_db = TursoDB( database_url="libsql://analytics.turso.io", local_path="analytics.db")# Agent uses conversation DB, analytics service uses analytics DBagent = Agent(name="Chat Agent", db=conversation_db)
import osreplica_path = "agent_replica.db"# Check if directory is writableif not os.access(os.path.dirname(replica_path) or ".", os.W_OK): print("Directory not writable!")