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
| Job | Usual tool | Postgres |
|---|---|---|
| Task queue | Redis, SQS | pgmq |
| Agent memory | Vector database | JSONB columns |
| Coordination | Kafka, pub/sub | LISTEN/NOTIFY |
| Lineage | Graph database | ltree |
The agent flow
Two agents coordinate entirely through the database
- The fetcher reads a task from pgmq and fetches Hacker News headlines.
- A local LLM via Ollama summarises them.
- The result lands in
agent_memorywithstatus = 'done'. - A trigger fires
pg_notifyand wakes the summariser. - 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 summariserfetcher.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.
Kevin Keller · Open-source demo, not a production framework