Agentic AI code review for Pull Requests, aligned to your architecture standards, with deterministic safeguards for CI.
- What This Tool Solves
- What It Does
- Agentic Safeguards (Latest)
- How It Works
- Project Structure
- Setup
- Usage
- Output Report Format
- Testing
- CI/CD Integration
Architecture docs are usually long, and PR reviewers are time-constrained. That creates risk:
- Important rules can be missed.
- Manual reviews can be inconsistent.
- Violations are found late in the cycle.
This project automates architecture-aware PR checks so each PR is reviewed with the same process and quality bar.
For each PR, the tool:
- Fetches changed files and patches from GitHub.
- Loads architecture guidance from
PDF,URL, or text file. - Runs an agentic tool-calling review loop with
gpt-4o. - Produces a structured JSON report.
- Optionally posts review comments back to the PR.
The latest version includes hardening to make the reviewer more reliable and truly CI-safe:
- Mandatory file coverage: review fails if the agent does not inspect every changed file with
fetch_file_content. - Verdict consistency enforcement: if any
errorviolation is recorded, final verdict is automatically forced topassed=false. - Chunked architecture retrieval: architecture doc is chunked and retrieved via relevance scoring, avoiding reliance on only the first few thousand characters.
- Richer file-context tool output:
fetch_file_contentnow returns patch plus metadata (status,additions,deletions,patch_line_count,has_patch). - Safer local/test execution: reviewer supports injected client/token and no longer mutates global
OPENAI_*environment values.
PR Opened
↓
CLI command (src/cli.py)
↓
Fetch PR data (src/github_client.py)
↓
Load architecture document (src/doc_loader.py)
↓
Agentic review loop (src/reviewer.py)
- fetch_file_content
- search_architecture_doc
- flag_violation
- finish_review
↓
Deterministic post-checks
- all files reviewed?
- any error => force fail
↓
Save JSON report (src/reporter.py)
↓
Optional: post PR review comments (src/github_commenter.py)
src/cli.py— command entrypoint and orchestration.src/github_client.py— GitHub API PR + files fetch.src/doc_loader.py— architecture doc ingestion (url/pdf/text).src/reviewer.py— agentic tool loop + safety enforcement.src/tools.py— tool schemas exposed to the model.src/reporter.py— writes JSON reports.src/github_commenter.py— posts PR review comments.src/types.py— shared dataclasses.
copilot-code-reviewer/
├── src/
│ ├── cli.py
│ ├── github_client.py
│ ├── doc_loader.py
│ ├── reviewer.py
│ ├── tools.py
│ ├── reporter.py
│ ├── github_commenter.py
│ └── types.py
├── tests/
│ └── test_agent.py
├── reports/
├── .github/workflows/architecture-review.yml
├── requirements.txt
└── README.md
- Python 3.10+
- GitHub token with repo access
git clone https://github.com/your-org/copilot-code-reviewer.git
cd copilot-code-reviewer
pip install -r requirements.txtCreate .env:
GITHUB_TOKEN=ghp_your_token_herepython -m src.cli review \
--owner your-org \
--repo your-repo \
--pr 42 \
--doc path/to/architecture.pdfpython -m src.cli review \
--owner your-org \
--repo your-repo \
--pr 42 \
--doc https://your-docs-url/architecturepython -m src.cli review \
--owner your-org \
--repo your-repo \
--pr 42 \
--doc architecture.txt \
--output ./review-historypython -m src.cli review \
--owner your-org \
--repo your-repo \
--pr 42 \
--doc architecture.txt \
--post-commentsEach run writes reports/review__YYYYMMDD_HHMMSS.json with this shape:
| Field | Description |
|---|---|
reviewed_at |
Timestamp of report generation |
passed |
Final verdict (true / false) |
summary |
Review summary text |
comments |
Violations found |
files_reviewed |
Changed file metadata list |
{
"reviewed_at": "20260426_184200",
"passed": false,
"summary": "2 architecture violations found. Verdict adjusted: errors were recorded.",
"comments": [
{
"file": "src/config.py",
"line": 14,
"severity": "error",
"message": "Hardcoded secret detected.",
"suggestion": "Use environment variables."
}
],
"files_reviewed": [
{ "filename": "src/config.py", "status": "modified", "additions": 3, "deletions": 1 }
]
}Run all tests:
pytest -qRun agent-focused tests:
python -m pytest tests/test_agent.py -vCurrent baseline after latest improvements:
20 passed- No lints on updated agent modules
Workflow: .github/workflows/architecture-review.yml
It currently performs:
- Install dependencies
- Validate agent tests
- Run agentic review on PR
- Optionally post comments
- Upload generated report artifact
This allows architecture compliance to become an enforceable PR gate (exit 0/1) in GitHub Actions.