Skip to main content

PostgreSQL

PostgreSQL is the recommended production database for conversation persistence.

Installation

pip install "praisonaiagents[tools]"

Docker Setup

docker run -d --name praison-postgres -p 5432:5432 \
    -e POSTGRES_PASSWORD=praison123 \
    -e POSTGRES_DB=praisonai \
    postgres:16

Quick Start

from praisonaiagents import Agent

agent = Agent(
    name="Assistant",
    instructions="You are a helpful assistant.",
    memory={
        "db": "postgresql://postgres:praison123@localhost:5432/praisonai",
        "session_id": "my-session"
    }
)

response = agent.start("Hello!")
print(response)

Connection String Format

postgresql://username:password@host:port/database
Example:
from praisonaiagents import Agent

agent = Agent(
    name="Bot",
    memory={"db": "postgresql://user:password@host:5432/mydb"}
)

Environment Variables

export PRAISON_CONVERSATION_URL="postgresql://postgres:praison123@localhost:5432/praisonai"
import os
from praisonaiagents import Agent

agent = Agent(
    name="Assistant",
    memory={"db": os.getenv("PRAISON_CONVERSATION_URL")}
)

CLI

# Validate connection
praisonai persistence doctor \
    --conversation-url "postgresql://postgres:praison123@localhost/praisonai"

# Run with persistence
praisonai persistence run \
    --conversation-url "postgresql://postgres:praison123@localhost/praisonai" \
    --session-id "cli-session" \
    "Hello!"

Schema

Tables are auto-created:
  • praison_sessions - Session metadata
  • praison_messages - Conversation messages

Troubleshooting

Connection refused:
# Check if PostgreSQL is running
docker ps | grep postgres

# Check logs
docker logs praison-postgres
Authentication failed:
  • Verify username/password
  • Check pg_hba.conf for connection rules