Skip to main content

Overview

PostgresStorage provides a PostgreSQL-based storage backend. Ideal for production deployments, multi-node systems, and applications requiring ACID compliance.

Install

Install the PostgreSQL storage optional dependency group:
uv pip install "upsonic[postgres-storage]"

Basic Usage

from upsonic import Agent, Task
from upsonic.storage.memory import Memory
from upsonic.storage.postgres import PostgresStorage

storage = PostgresStorage(
    db_url="postgresql://user:password@localhost:5432/mydb"
)

memory = Memory(
    storage=storage,
    session_id="session_001",
    user_id="user_123",
    full_session_memory=True,
    summary_memory=True,
    user_analysis_memory=True,
    model="openai/gpt-4o"
)

agent = Agent("openai/gpt-4o", memory=memory)

result1 = agent.do(Task("My name is Alice"))
result2 = agent.do(Task("What's my name?"))
print(result2)  # "Your name is Alice"

Parameters

ParameterTypeDefaultDescription
db_urlstr | NoneNonePostgreSQL connection URL
db_engineEngine | NoneNonePre-configured SQLAlchemy Engine
db_schemastr | None"public"PostgreSQL schema to use
session_tablestr | None"upsonic_sessions"Session table name
user_memory_tablestr | None"upsonic_user_memories"User memory table name
create_schemaboolTrueAuto-create schema if not exists
idstr | Noneauto-generatedStorage instance ID

Storage Type

PostgresStorage is a synchronous storage implementation using SQLAlchemy with psycopg2 driver.