Skip to content
const WebsiteFlow = new Flow<{ url: string }>({ slug: 'website' })
.step({ slug: 'fetch' }, input => scrape(input.run.url))
.step({ slug: 'sentiment', dependsOn: ['fetch'] },
input => analyzeSentiment(input.fetch))
.step({ slug: 'summary', dependsOn: ['fetch'] },
input => summarize(input.fetch))
.step({ slug: 'save', dependsOn: ['sentiment', 'summary'] },
input => save({ ...input.sentiment, ...input.summary }));
  • Postgres-Native and 100% in Supabase
  • Type-Safe DSL with autocomplete
  • Retries, Concurrency & Observability

Build AI Agent Workflows on Supabase

pgflow adds deterministic, parallel orchestration on top of Supabase Background Jobs - no extra servers needed

A complete workflow engine built on Postgres

pgflow is a workflow orchestration system with its core state management in your database, combining:

SQL Core

Pure SQL implementation that handles workflow definitions, state transitions, and ACID-compliant processing directly in your Postgres database.

TypeScript DSL

Type-safe API for defining workflows that automatically infers input/output types between steps, providing compile-time safety.

Edge Worker

Self-restarting worker that processes tasks with built-in retries and error handling, designed for Supabase Edge Functions.

CLI Tools

One-command setup with npx pgflow install that handles migrations, configuration, and deployment.

Type-safe DAG workflows in TypeScript

Define complex workflows with parallel execution and dependencies using a simple, type-safe API:

// Define a workflow with parallel steps
new Flow<{ url: string }>()
.step("website", async ({ url }) => {
const response = await fetch(url);
return { content: await response.text() };
})
.step("sentiment", ["website"], async ({ website }) => {
return await analyzeSentiment(website.content);
})
.step("summary", ["website"], async ({ website }) => {
return await summarizeWithAI(website.content);
})
.step("saveToDb", ["sentiment", "summary"], async (input) => {
return await saveResults({
url: input.run.url,
sentiment: input.sentiment.score,
summary: input.summary
});
});

End-to-end workflow orchestration

Single source of truth

All workflow definitions, state, and execution history stored in your Postgres database—simplifying monitoring and debugging.

Reliable task processing

Built on PGMQ for at-least-once delivery with automatic retries, timeouts, and dead-letter handling.

Supabase-native

Deploy as Edge Functions with automatic restarts and zero-config integration with your existing Supabase project.

Developer experience

Full type inference between workflow steps with IDE autocompletion and compile-time safety for your entire workflow DAG.

From workflow DSL to execution

Create and run workflows with a straightforward process:

  1. Define your workflow in TypeScript with the Flow DSL, specifying handlers and dependencies
  2. Generate SQL migrations from your workflow definition
  3. Create a dedicated worker as a Supabase Edge Function for your flow
  4. Start workflows from your application code, SQL triggers, or APIs

The execution system handles the rest—scheduling steps when dependencies complete, retrying failed tasks, and aggregating results automatically.

Ready to get started?

Install pgflow in your Supabase project with a single command:

Terminal window
npx pgflow install