Skip to Content

Context-Aware AI Code Review System

Scaling Engineering Quality with AST Semantic Retrieval and Specialized Multi-Agent Ensembles
November 23, 2026 by
Fouad Sabry
| No comments yet

The Problem:

Generative AI authoring tools have massively accelerated code production, overwhelming manual code review capacity bounded by human cognitive limits (~400 LOC/hour). This throughput mismatch causes comprehension debt and rubber-stamping of critical flaws. Meanwhile, standard diff-only automated reviews achieve low precision (31.37%) and miss architectural regressions, while naive full-repository dumping dilutes context, lowers F1 scores (52.25%), and wastes tokens.

The Approach:

We engineered a context-aware AI review harness decoupling review from code generation. Using Python AST parsing, codebases are partitioned into syntax-aware class/function chunks and indexed in ChromaDB via 3,072-dimensional embeddings (text-embedding-3-large). For each pull request, selective retrieval isolates the top 15 chunks (<3,500 chars), integrating Jira task requirements (DX-3 acceptance criteria) and Confluence rules. Analysis is executed via an ensemble of parallel, specialized agents—a Security Agent (2,300-char prompt) targeting OWASP/injection vectors and a Pattern Compliance Agent (1,700-char prompt) enforcing architecture/error patterns—followed by programmatic deduplication and risk triage.

The Results:

Evaluated across a standardized 15-PR benchmark on a FastAPI service, selective context retrieval reduced token bloat by 88.9% and increased context efficiency 10.5x (0.176 vs. 0.017 F1/KB) over full context. The specialized ensemble achieved 55.40% precision and a 71.10% F1 score (vs. 60.61% for general review), winning 10 of 15 PRs with 100% recall on 11 PRs. Integrating Jira and Confluence context eliminated requirements gaps, while a Review-Judge-Codify-Reuse loop codified recurring bugs into permanent, reusable Agent Skills.

Fouad Sabry November 23, 2026
Share this post
Tags
Archive
Sign in to leave a comment