Agent-First PSQL

A PostgreSQL tool for AI agents — SQL in, typed rows out, on a connection that stays open.

The problem: psql was built for a person at a terminal

The standard PostgreSQL client, psql, was built for a person at a terminal. It prints results as tables drawn with text, and it opens a fresh connection every time you run it.

An agent reading those tables has to parse the layout to find a value. When a query fails, it gets an error sentence, not a code it can act on. And an agent running a whole session of queries pays the connection and handshake cost over and over.

What it does: typed JSON rows on a persistent connection

Agent-First PSQL is the same database, addressed differently. SQL goes in; rows come back as structured JSON with real types. A database error comes back as a structured event carrying its exact SQLSTATE code — so the agent knows which error, not just that one happened. And the connection stays warm across the whole session.

Where to use it: queries, long sessions, and precise error handling

Install

brew install agentfirstkit/tap/afpsql   # macOS / Linux
cargo install agent-first-psql          # any platform

Docs