@cuylabs/agent-session-store-postgres
v6.1.0
Published
PostgreSQL session store for @cuylabs/agent-core
Maintainers
Readme
@cuylabs/agent-session-store-postgres
PostgreSQL-backed SessionStore for @cuylabs/agent-core.
Use this backend when agents need durable session state across restarts or scale-out instances, including Azure App Service with Azure Database for PostgreSQL Flexible Server.
import { SessionManager } from "@cuylabs/agent-core";
import { PostgresSessionStore } from "@cuylabs/agent-session-store-postgres";
const sessionManager = new SessionManager(
new PostgresSessionStore({
connectionString: process.env.AGENT_SESSION_POSTGRES_URL,
poolOptions: {
ssl: { rejectUnauthorized: true },
},
}),
);For scaled Azure App Service deployments, also pass the Postgres-backed turn
lock to createAgent() so multiple app instances cannot run turns for the same
session concurrently:
import { createAgent, SessionManager } from "@cuylabs/agent-core";
import {
PostgresSessionStore,
PostgresSessionTurnLock,
} from "@cuylabs/agent-session-store-postgres";
const connectionString = process.env.AGENT_SESSION_POSTGRES_URL;
const agent = createAgent({
model,
sessionManager: new SessionManager(
new PostgresSessionStore({ connectionString }),
),
sessionTurnLock: new PostgresSessionTurnLock({ connectionString }),
});The store is append-only and stores each session entry as jsonb. By default
it creates the public.agent_session_entries table on first use.
The turn lock uses PostgreSQL advisory locks and holds a dedicated database connection only while the agent turn is running. It does not hold a database transaction open during LLM/tool execution.
Azure PostgreSQL
For Azure Database for PostgreSQL Flexible Server, configure an App Service application setting such as:
AGENT_SESSION_POSTGRES_URL=postgresql://user:[email protected]:5432/database?sslmode=requireIf your deployment uses an Azure-managed CA bundle, pass the CA through
poolOptions.ssl. For private networks and managed identity, create the
pg.Pool in the host app and pass it as pool.
