How to Build an AI Code Review Agent - Daksh Gupta, Greptile

18:272 min readAI Engineer10/26/2026Computing/Software

Key Takeaway

Building an effective internal AI code review agent requires optimizing prompts to filter nitpicks, implementing model inversion, and utilizing dependency-rich sandboxes for autonomous end-to-end testing.

Highlights

  • About 1% of all pull requests on GitHub run through Greptile.

  • Running code reviews with coding agents costs between $3 and $25 per pull request.

  • Claude models produce one-off errors at three times the rate of GPT models.

  • Model inversion between code generation and review yields a 10% higher bug catch rate.

  • Only one out of every 1,000 pull requests contains a catastrophic bug.

Timeline

  1. Introduction to AI Code Review and Initial Architecture

    Code validation bottlenecks emerge as engineers and non-engineers increasingly generate code using AI tools. While a basic webhook and harness setup can return review feedback within five minutes, it quickly exposes systemic flaws. Unfiltered agents flood pull requests with pedantic stylistic complaints that coding agents blindly attempt to fix, resulting in overly defensive codebases.

    • Greptile reviews and tests pull requests across thousands of companies to catch bugs and logical errors from AI-generated code.
    • Building a basic review agent requires a sandbox environment, an open-source harness, and a GitHub or GitLab webhook to receive pull request data.
    • Initial agent setups encounter major issues including missed bugs, missing codebase context, high token costs, and excessive nitpicky comments.
  2. Prompt Optimization and Historical Data Sets

    Prompt modifications cause dramatic fluctuations in comment volume, creating uncertainty about whether critical bugs are being missed. Because catastrophic bugs occur rarely, standard reviews cannot easily prove the absence of errors. Maintaining a real-time updating dataset of past engineering incidents provides a reliable benchmark to evaluate agent performance over time.

    • Cataloging historical outages allows teams to tune prompts to detect specific high-propensity bug types while explicitly excluding nitpicks.
    • Catastrophic bugs appear in roughly one out of every 1,000 pull requests, making it difficult to measure the absence of bugs.
    • Testing agent versions against a historical dataset of past incident-causing pull requests improves review reliability.
  3. Model Inversion and Codebase Context

    Matching the review model to the generation model creates blind spots because both models fail in identical patterns. Inverting models—such as reviewing Claude-generated code with a GPT model—captures errors that would otherwise slip through. Furthermore, reducing reliance on imprecise grep commands by maintaining centralized code knowledge bases and living wikis prevents unnecessary token consumption during context retrieval.

    • Claude models generate one-off errors three times more frequently than GPT models, while GPT models produce more authentication bypasses.
    • Pairing a different model for code review than the one used for generation increases bug catch rates by 10%.
    • Standard grep operations consume vast amounts of inference tokens and lack the precision needed for deep architectural understanding.
  4. Autonomous Testing and Inference Cost Allocation

    Visual UI bugs often bypass static code analysis, requiring virtual machine sandboxes to spin up application stacks and test user flows visually. Because running frontier models across entire review pipelines drives costs up to $20 per pull request, optimizing inference allocation is essential. Delegating routine retrieval to decision models and smaller background agents cuts operational costs significantly.

    • Configurable virtual machine sandboxes enable end-to-end computer use testing for visual and UI regressions.
    • Allocating smaller, cheaper models to exploratory file reads and lightweight tasks preserves expensive frontier models for critical review steps.
    • Complex review pipelines split tasks across roughly 20 different sub-agents to optimize performance per dollar.

Description

Daksh Gupta, co-founder of Greptile, which reviews about 1% of all pull requests on GitHub, shares what Greptile tells companies that want to build their own review agent. Starting from a simple sandbox-plus-webhook setup, he explains why it misses bugs, costs $3-25 per PR and floods you with nitpicks, then walks through the fixes: targeted prompts, a dataset of past incident PRs, model inversion (reviewing Claude-written code with GPT and vice versa catches about 10% more bugs), codebase context and a living wiki, autonomous testing in sandboxes with computer use, and routing cheaper models to most subtasks. Chapters 00:00 Intro: Greptile and why companies build their own 01:22 What makes a great review agent 02:38 The simple version: sandbox, agent, webhook 03:55 What goes wrong 06:02 Fix 1: Better prompts and fewer nitpicks 07:44 Fix 2: A dataset of historical PRs 09:02 Fix 3: Model inversion 11:04 Fix 4: Codebase context 12:36 Docs, tickets and a living wiki 14:26 Fix 5: Autonomous testing with computer use 16:05 Fix 6: Cheaper models for most subtasks Daksh Gupta, Greptile Join us in SF for the second annual AIE CODE summit: https://aie.codes our last flagship summit of 2026. Applications live now!

Write about this video