case studyagentsopen source

Multi-agent code review on rig.rs with a standalone four-tier diff compressor.

code review (rust) — preview
figure · code-review-rs
01 · problem

Problem

Large pull requests blow past context windows long before they reach the model. Naive truncation drops the lines you actually want reviewed. I wanted a reviewer that could fan out across specialist agents — correctness, security, style, tests — without paying for every token in the raw diff.

02 · shape

Shape

Four specialist agents run in parallel through tokio::try_join!, then a synthesizer folds their findings into a single report. The rig.rs abstraction is pinned to one file (llm/vertex.rs) so swapping models does not ripple through the codebase. A mock LLM client makes the whole pipeline deterministic in tests.

03 · build

Build

The diff compressor is a standalone crate with zero runtime dependencies — greedy file packer, hunk splitter, priority line slicer, UTF-8-safe byte slicer. Token accounting is an AtomicU64 in a middleware layer so every request carries its budget. The Axum server and the CLI share the same review::Engine; the CLI is a thin sync wrapper around the async core.

code-review-rs — Rust pipeline Git diff enters a four-tier compressor, then the engine fans out four specialists in parallel via tokio::try_join, then folds them through a synthesizer. Every agent sits behind a wrapped middleware stack. CLI · GIT DIFF read input diff-compressor file · hunk · line · byte 4 tiers · token-budget bins engine tokio::try_join — 4 specialists security performance quality bug detector synthesizer unified report EVERY AGENT · WrappedAgent — token tracker · rate limiter · retry · usage
figure · service topology
04 · result

Result

A typical 2k-line diff compresses from ~80k tokens to ~12k — a 75% reduction — before the first model call. The compressor crate has 62 tests on its own; the main crate adds 81 more, including end-to-end runs against the mock client so CI never talks to Vertex.

75%
token reduction on 2k-line diffs
143
tests across compressor and main crate

stack

RustrigVertex AI GeminiAxumtokio