Database

PostgresDb

Store sessions, memories, metrics, knowledge, evals, and traces in PostgreSQL.

PostgresDb is a class that implements the Db interface using PostgreSQL as the backend storage system. It provides robust, relational storage for agent sessions with support for JSONB data types, schema versioning, and efficient querying.

ParameterTypeDefaultDescription
idOptional[str]-The ID of the database instance. UUID by default.
db_urlOptional[str]-The database URL to connect to.
db_engineOptional[Engine]-The SQLAlchemy database engine to use.
db_schemaOptional[str]-The database schema to use.
session_tableOptional[str]-Name of the table to store Agent, Team and Workflow sessions.
runs_tableOptional[str]-Name of the table to store the runs of each session.
memory_tableOptional[str]-Name of the table to store memories.
metrics_tableOptional[str]-Name of the table to store metrics.
eval_tableOptional[str]-Name of the table to store evaluation runs data.
knowledge_tableOptional[str]-Name of the table to store knowledge content.
traces_tableOptional[str]-Name of the table to store traces.
spans_tableOptional[str]-Name of the table to store spans.
versions_tableOptional[str]-Name of the table to store schema versions.
components_tableOptional[str]-Name of the table to store components.
component_configs_tableOptional[str]-Name of the table to store component configurations.
component_links_tableOptional[str]-Name of the table to store links between components.
learnings_tableOptional[str]-Name of the table to store learnings.
schedules_tableOptional[str]-Name of the table to store cron schedules.
schedule_runs_tableOptional[str]-Name of the table to store schedule run history.
job_tableOptional[str]-Name of the table to store durable background run jobs.
approvals_tableOptional[str]-Name of the table to store human approval requests.
auth_tokens_tableOptional[str]-Name of the table to store OAuth tokens for external services.
service_accounts_tableOptional[str]-Name of the table to store service accounts.
mcp_oauth_clients_tableOptional[str]-Name of the table to store MCP OAuth client registrations.
mcp_oauth_transactions_tableOptional[str]-Name of the table to store MCP OAuth transactions.
mcp_oauth_codes_tableOptional[str]-Name of the table to store MCP OAuth authorization codes.
mcp_oauth_refresh_tokens_tableOptional[str]-Name of the table to store MCP OAuth refresh tokens.
mcp_oauth_keys_tableOptional[str]-Name of the table to store MCP OAuth signing keys.
create_schemaboolTrueWhether to create the database schema if it doesn't exist. Set to False when the schema is managed externally.

Methods

upsert_sessions

Upsert multiple sessions in one method call.

Parameters:

  • sessions (List[Session]): List of sessions to upsert
  • deserialize (Optional[bool]): Whether to deserialize the sessions. Defaults to True
  • preserve_updated_at (bool): Request preservation of the sessions' existing updated_at timestamps; see adapter limitations below. Defaults to False

Returns: List[Union[Session, Dict[str, Any]]]

upsert_memories

Upsert multiple memories in one method call.

Parameters:

  • memories (List[UserMemory]): List of memories to upsert
  • deserialize (Optional[bool]): Whether to deserialize the memories. Defaults to True
  • preserve_updated_at (bool): Request preservation of the memories' existing updated_at timestamps; see adapter limitations below. Defaults to False

Returns: List[Union[UserMemory, Dict[str, Any]]]

Timestamp preservation by adapter

JsonDb, GcsJsonDb, FirestoreDb, RedisDb, DynamoDb, and InMemoryDb accept preserve_updated_at but do not forward it to their individual upserts. Their bulk methods replace timestamps even when it is True.

PostgresDb, SingleStoreDb, and ValkeyDb honor the flag. MySQLDb, SqliteDb, and MongoDb honor it on their optimized bulk path; their per-record fallback paths do not forward it. Verify timestamps when a migration depends on preserving them.