← All projects
Complete · 8 build phases

Multi-agent PR reviewer

Four specialist agents review every pull request in parallel. The interesting part is the reliability engineering around them.

Not an LLM in a loop: webhook verification, latency isolation, idempotency, confidence gates and cost control, each built and tested one step at a time.

StackPython · FastAPI · Redis + ARQ · LangGraph · Postgres + pgvector · LangSmith
Speed8.3 s per review with the agents in parallel, versus ~21 s one after another
CostTracked per review in Postgres, cross-checked against LangSmith
Tested16 unit tests and ruff, run in GitHub Actions on every PR
01

Why it's harder than it looks

Calling an LLM on a diff is easy. Running it on real webhooks is not. GitHub times out slow handlers and redelivers events. Four agents writing at once can overwrite each other. A bot that comments on every push gets muted within a day. And a retry loop on a broken PR can quietly spend money forever.

So the project is a study of the patterns around an agent system, with each one built by hand, tested on its happy and failure paths, and written down with the reason it exists.

02

Five ideas carry the design

Each one answers a specific way the naive version breaks.

Fast-ack

The web process only verifies, dedupes, enqueues and returns 202 in milliseconds. The slow review runs in a separate worker, so GitHub never times out.

Fan-out, fan-in

Four agents read the same PR and write into one shared list. An operator.add reducer merges their concurrent writes instead of letting the last one win.

Durable lifecycle

Each delivery is written to Postgres as in_progress before the slow work starts. A crashed review leaves a row you can query instead of vanishing.

Idempotent at three layers

SET NX on enqueue, ON CONFLICT on the PR row, find-then-update on the comment. A PR reviewed ten times has one comment.

Bounded failure and spend

Failures are classified before retrying, retries are capped, and a daily budget is checked before any work begins.

The rule under all five

Code decides; the LLM narrates. Dedupe, tiering and ordering are plain Python that can't hallucinate a finding in or out.

03

Parallel, proven from the trace

All four agents start at t = 0 in one LangGraph superstep. The aggregator is a barrier: it can't run until every agent finishes. The whole run takes 8.3 seconds; one after another, it would take about 21.

Every call is traced in LangSmith, and its token counts are summed onto the delivery row, so each review's cost sits next to its findings.

LangSmith waterfall of one review: docs, quality, security and testing agents run concurrently from zero seconds, and the aggregate step runs after all four finish, 8.28 seconds total
One review run in LangSmith

The cost column looked right. It was off by 50%.

Per-review cost is recorded in Postgres because LangSmith's traces expire after 14 days and can't be joined against findings. To check it, I compared the two. Tokens matched exactly: 5,552. The cost did not. The hardcoded prices were for the wrong Sonnet generation, inflating every figure by about half.

Tokens5,552 = 5,552
Cost, before fix~50% high
After the fix$0.0154 vs LangSmith's $0.0155

The lesson I kept: no amount of checking a number against itself would have caught this. It took a second, independent source.

05

Key engineering decisions

The README explains more than twenty. These four are the ones I'd defend first.

Demote low-confidence findings, don't drop them

An agent's low confidence describes its own certainty, not the issue's importance. High-tier findings reach the PR; demoted ones stay in Postgres, queryable, and never clutter the comment.

Unknown failures are permanent by default

Timeouts, 429s and 5xx retry with backoff, up to three attempts. A 404, a 401 or one of our own bugs fails the same way every time, so retrying it only burns money. A mistake costs one lost review, not an endless loop.

Check the budget before the work

A ceiling checked after the LLM calls is an accounting note, not a control. Over budget, a review returns in 0.05 s having spent zero tokens.

Vector search beside the relational data

pgvector similarity is one ordering in the same SQL that joins findings to deliveries and PRs. No separate vector store to keep in sync, and embeddings run locally with no extra API key.

06

The reviewer, reviewing itself

Once it could post, I pointed it at its own repository. On the PR that added CI, it flagged that pytest was listed as a dependency but never run by the workflow. Lint and import checks had passed cleanly on the same commit.

The next PR fixed it, and the review of that PR suggested boundary tests at the exact confidence thresholds, which I added. The deterministic checks and the semantic review caught entirely different kinds of problems.

07 · Known gaps
  • The budget ceiling is soft: concurrent workers can each pass the check
  • A budget skip leaves no delivery row in Postgres
  • Price constants are hardcoded and unchecked at runtime
  • Embedding runs inside the review transaction
08 · Next
  • Integration tests for the database layer against a real Postgres in CI
  • A hard spend cap with per-call accounting inside the graph
  • A backfill script for findings that predate embeddings