## See it in one minute ``` make demo PG_CONFIG=/path/to/pg_config ``` The same role, with the same privileges, first as an ordinary user and then registered as an agent. After every attempt a superuser prints the database: ``` WITHOUT the gate: an ordinary role, the way an agent connects today database now: customers: 4 · orders: 8 1. the model 'cleans up' the orders: DELETE FROM orders database now: customers: 4 · orders: 0 2. the model 'fixes' the schema: DROP TABLE customers CASCADE database now: customers: TABLE GONE · orders: 8 3. the model reads another customer's data: set_config('app.tenant_id', '2') + SELECT Iris|iris@TWO.example Juan|juan@TWO.example WITH the gate: the same role, registered as an agent (max_rows 5, no DDL) 1. DELETE FROM orders, typed directly ERROR: pg_agent_gate: this session belongs to agent "assistant": it proposes, it does not execute 2. DROP TABLE customers CASCADE, typed directly ERROR: pg_agent_gate: this session belongs to agent "assistant": it proposes, it does not execute 3. set_config to tenant 2, typed directly ERROR: pg_agent_gate: this session belongs to agent "assistant": it proposes, it does not execute database now: customers: 4 · orders: 8 ...and the same three, PROPOSED through the gate: 1. propose + commit: DELETE FROM orders (8 rows, the agent may touch 5) commit: aborted -- it touched 8 rows, more than this agent may change in one statement 2. propose: DROP TABLE customers refused at propose -- kind_allowed: T_DropStmt changes the schema or the server, and this agent is not allowed DDL 3. propose: a read that moves the tenant from inside the statement refused at propose -- keeps_its_context: set_config() would change, while the proposal runs, a parameter ... database now: customers: 4 · orders: 8 ...while legitimate work still goes through, and is seen before it is kept: dry_run (nothing kept): "rows": [{"after": {..., "email": "ana@new.example"}, "before": {..., "email": "ana@one.example"}}] commit: kept, Ana's email is now ana@new.example ``` A small, free model doing this live — fork-and-run, with the scored report: **[agent-gate-demo](https://github.com/Manuelreyesbravo/agent-gate-demo)** · **[see a live run](https://manuelreyesbravo.github.io/agent-gate-demo/)**. ### Try it with no Rust or PostgreSQL installed `make demo` needs PostgreSQL 18+, Rust and cargo-pgrx. To see the same with/without-gate demo with none of that, run it in a throwaway container — the extension is built into the image, and it needs only Docker or Podman: ``` make docker-demo # builds the image from this repo and runs the demo ``` or pull the prebuilt image instead of building it: ``` docker run --rm ghcr.io/manuelreyesbravo/pg_agent_gate-demo ``` The image is `linux/amd64`; on an Apple-silicon Mac it runs under emulation. ## Run the two side by side ``` make contrast PG_CONFIG=/path/to/pg_config ``` The same `DROP TABLE` that an ordinary connection runs -- and the table is gone, irreversibly -- the gate refuses, with the reason. And where an ordinary server hands back a row count *after* it ran, the gate returns the catalog the agent may touch, every check with its verdict, and the exact before/after of the change, *before* anything is kept. The piece you take out returned a result; the piece in its place returns a decision you can see.