Design a code review agent
I was asked this
No reports yet. Sign in to say where you were asked it.
An AI system design interview question asked in Meta's system design round, last asked Mar 2026. It tests llm agents, code review and evaluation.
Design an AI agent that reviews pull requests for developers. It reads the change, pulls in as much of the repository as it needs to understand it, and leaves review comments on bugs, security risks, maintainability problems, style issues and missing tests. Every comment must be specific, actionable and grounded in the actual code. A central part of the design is deciding which steps need an LLM and which are better done by ordinary deterministic tools.
Requirements
- Functional: inspect the diff of a pull request; fetch surrounding repository context when needed; find bugs, security risks, maintainability and style problems, and missing tests; post comments tied to specific lines, optionally with a suggested fix.
- Functional: an orchestrator that plans the review, calls tools and assembles the final set of comments.
- Non-functional: few false positives, so developers keep reading the comments; a review finishes within minutes of the PR opening; a known, bounded cost per review; no code or secrets leave the boundaries the company allows.
Clarifying questions
- Which languages and how large are the repositories and the typical PR?
- Does the agent block merges, or only comment alongside human reviewers?
- Should it propose fixes as suggested edits, or only describe the problem?
- Which tools already exist: linters, type checkers, static analysis, the test suite, a code search index?
- What is the budget per review in money and in time?
What a strong answer covers
- A clear split: linters, type checkers, static analyzers, secret scanners and test runs are deterministic tools; the LLM handles understanding intent, reasoning about logic bugs, and writing the comment. Formatting and style rules never need an LLM.
- The orchestrator: classify the PR and its files, plan which checks to run, gather context, run the LLM review per file or per hunk, then deduplicate, rank and cap the comments.
- Repository context and memory: a code search or embedding index, call-graph lookups for changed functions, the project's conventions and past review comments, and what is cached per repository versus fetched per PR.
- The tools the agent can call: read file, search code, find references, run tests or a linter, read the PR description and linked issue.
- Validating comments before posting: ground each claim in cited lines, check that a suggested fix compiles or passes tests, a second-pass verifier or confidence threshold, and safety checks against prompt injection hidden in the code under review.
- Cost: estimate tokens per PR (diff plus context plus output), choose a smaller model for triage and a larger one for hard files, cache context, and skip generated or vendored files.
- Evaluation: offline on historical PRs with known bugs and human comments, then online by comment acceptance rate, fixes applied and developer feedback.
Follow-ups
- A 5,000-line PR arrives. How does the agent stay within budget and still catch what matters?
- Developers start ignoring the agent's comments. What do you measure, and what do you change?
- How do you stop a malicious PR from instructing the agent to approve it?
- How would the agent learn a team's conventions from accepted and rejected comments over time?
Where it's asked
- Meta · System design · Last asked Mar 202645 min · Design discussion; either an LLM-agent system or a classic product system · Nominally AI-enabled, but the assistant is often not used
What it tests
llm agents · code review · evaluation
No official answer yet. Draw yours on the right; publish it and it shows under Community.
Nothing published yet. Publish your canvas and it shows here for others to open and remix.
