pg_agent (In-Database Autonomous Agents via WAL Integration)Hi Supabase Team,
Supabase has democratized Postgres for the modern web, but the current paradigm for AI applications is fundamentally inefficient. Right now, to build an AI agent with Supabase, a developer must:
This creates latency, race conditions, and massive network overhead.
I propose a groundbreaking architectural addition to the Supabase ecosystem: pg_agent - A native PostgreSQL extension for autonomous AI.
Instead of externalizing the AI, we embed the autonomous logic directly into the database engine using the Write-Ahead Log (WAL) and native Postgres background workers.
When a row is inserted (e.g., INSERT INTO support_tickets (issue) VALUES (...)), the pg_agent extension intercepts the event at the WAL level. It queries a locally hosted SLM (or an API) inside the database transaction lifecycle.
-- Proposed Paradigm
CREATE EXTENSION pg_agent;
-- Attach an autonomous agent to a table
SELECT agent.attach(
'support_tickets',
'model=gpt-4o, system_prompt="You are a support bot. Categorize and resolve the issue.", tools=[refund_user, escalate_to_human]'
);
-- When a user inserts data:
INSERT INTO support_tickets (issue) VALUES ('My app keeps crashing on launch');
-- The pg_agent intercepts, runs the LLM inference asynchronously in C,
-- and executes the resulting tool call (e.g., UPDATE support_tickets SET category='bug', status='escalated')
-- with ZERO network hops to an external application server.
The user proposes a new feature called pg_agent, a PostgreSQL extension for embedding AI logic directly into the database using WAL and background workers. This would reduce latency and network overhead by eliminating the need for external AI orchestration. The user offers their engineering team's expertise to develop this feature for Supabase.
Supabase already dominates pgvector. But vector storage is just memory. pg_agent is the pre-frontal cortex.
By allowing developers to define autonomous agents using pure SQL that react to database mutations natively, Supabase would completely eliminate the need for LangChain, AutoGen, or external Node.js orchestration servers. The database becomes the entire AI backend.
If the core architecture team is interested in this paradigm shift, my engineering team (allornothingai) specializes in C-level Postgres extensions and AI architecture. We are prepared to design, build, and PR the pg_agent extension for the Supabase ecosystem.
Let's make the database think for itself.