Postgres Agent Orchestrator

Four systems for agents? Try the database you already run.

Coordinating AI agents with pgmq, LISTEN/NOTIFY, JSONB and ltree, and nothing else.

Kevin Keller · kevinkeller.org

Why it matters

Agent frameworks start with four external systems

  • A message broker for task queues.
  • A vector database for memory.
  • A pub/sub system for coordination.
  • A graph database for lineage.

That's four systems before a single line of agent logic. Most teams already run PostgreSQL.

The idea

One PostgreSQL instance is the queue, memory, event bus and audit trail

A demo of about 200 lines of Python, two agents, no extra infrastructure.

The mapping

Native Postgres features replace each external system

JobUsual toolPostgres
Task queueRedis, SQSpgmq
Agent memoryVector databaseJSONB columns
CoordinationKafka, pub/subLISTEN/NOTIFY
LineageGraph databaseltree

The agent flow

Two agents coordinate entirely through the database

  1. The fetcher reads a task from pgmq and fetches Hacker News headlines.
  2. A local LLM via Ollama summarises them.
  3. The result lands in agent_memory with status = 'done'.
  4. A trigger fires pg_notify and wakes the summariser.
  5. It writes an executive briefing with lineage back to the fetcher.

Queue and events

Retries and wake-ups come built in

  • pgmq visibility timeouts: if an agent crashes, the message reappears.
  • The queue is a table with transactional guarantees.
  • LISTEN/NOTIFY: the summariser sleeps until Postgres wakes it. No polling.

Memory and lineage

Flexible memory and a traceable chain in one table

  • JSONB: each agent stores its own shape, no migrations for new agent types.
  • ltree: the fetcher writes fetcher, the summariser fetcher.summarizer.
  • One query reconstructs the full history of any task.

What you get for free

Postgres brings properties you'd otherwise build

  • Transactional safety: crashes roll back
  • Built-in retry: visibility timeouts
  • Fast lineage: GiST indexes on ltree
  • Schema flexibility: JSONB
  • Observability: it's just a table, query it with SQL

Where it fits

Enough for most agent workloads, not all

  • Fits single-digit agents working at human-interaction speeds.
  • Extra infrastructure pays off for sub-millisecond latency or thousands of concurrent producers.
  • It's a demo: no authentication, multi-tenant isolation or horizontal scaling.

The takeaway

Before reaching for Redis and Kafka, see what Postgres does natively.

Read the full article

Kevin Keller · Open-source demo, not a production framework