Skip to main content
PostgreSQL persists agent conversations with JSONB metadata, connection pooling, and automatic serverless retry.
The user talks to production agents; PostgreSQL stores conversations with JSONB metadata.

Quick Start

1

Simple Usage

2

With Configuration

When you pass structured credentials (PostgresDB(host=..., user=..., password=...)), special characters in user/password are URL-encoded automatically — you don’t need to quote_plus them yourself. This applies only to the structured constructor; if you pass a raw database_url= string, escape it yourself as before.

How It Works


Init-Failure Handling

PostgreSQL initialization distinguishes transient outages from fatal misconfiguration so a typo never hides behind a cooldown window.
  • Transient (memoized for the cooldown, retried after): ConnectionError, TimeoutError, OSError, and DBAPI operational errors matched by class name across the MRO (for example psycopg2.OperationalError, psycopg.errors.OperationalError) — no optional-dependency import needed.
  • Fatal (raised immediately on every call): PermissionError, credential/typo/misconfiguration errors, ValueError/TypeError from bad config.
  • KeyboardInterrupt / SystemExit / other BaseExceptions bypass the handler entirely and never poison the memoized state.

Configuration Options

URL formats

Aliases: neon, cockroachdb, crdb, xata resolve to the postgres backend. For async, use create_conversation_store("async_postgres", ...).

Best Practices

Agent(db=db(database_url="postgresql://...")) is the simplest path — store wiring is automatic.
Set sslmode=require in the URL for encrypted connections.
Point at Neon or Xata URLs — SSL and retry are applied automatically.
Reuse the same session_id — conversation history loads on the next agent.start().

SQLite Persistence

Local file database for development

Database Persistence

Compare all persistence backends