Understanding PR-Agent
Relevant source files
The following files were used as context for generating this wiki page:
PR-Agent facilitates automated code review, description generation, and autonomous code repair across repositories. The system centralizes global configurations and provides an autonomous fixer script to resolve issues flagged during reviews or CI failures.
The architecture relies on GitHub Actions, the PR-Agent tool, and a custom autonomous repair script (autofix.py) powered by the Gemini AI model. Users interact with the system via repository comments or automated triggers during the Pull Request lifecycle.
Sources: README.md:1-25, scripts/autofix.py:1-25
Configuration and Governance
The system employs a hierarchical configuration model to manage tool behavior across multiple repositories.
Global and Repository Settings
The central repository JWEB0689/pr-agent-settings hosts the .pr_agent.toml file. PR-Agent loads this file globally for every Pull Request in all repositories owned by @JWEB0689. Individual repositories can override these global defaults by including their own .pr_agent.toml file.
Sources: README.md:9-16
Interactive Commands
Users trigger specific PR-Agent functionalities by posting comments on a Pull Request.
| Command | Action |
|---|---|
/review | Performs code review including security and test analysis. |
/describe | Generates a comprehensive PR description and changelog. |
/improve | Provides commit-ready inline code suggestions. |
/ask <question> | Answers specific questions regarding PR changes. |
Sources: README.md:20-25
Autonomous Repair System
The autofix.py script serves as an autonomous agent that repairs code based on review findings or CI failures. It operates in two primary modes: review-fix and ci-fix.
Sources: scripts/autofix.py:10-20
Logic Flow for Autofix
The following diagram illustrates the decision logic used by the autonomous fixer to determine the repair mode.
The script attempts to address human or AI review comments first. If no comments exist or review-fixing fails, it attempts to resolve CI build or test failures.
Sources: scripts/autofix.py:350-380
Execution Modes
1. Review-Fix Mode
The script fetches inline review comments and summaries from the GitHub API. It filters for genuine bugs and logic issues while skipping style nitpicks. The AI model receives the findings and relevant file contents to generate surgical fixes.
Sources: scripts/autofix.py:171-205, scripts/autofix.py:255-265
2. CI-Fix Mode
If the local test runner fails, the script extracts error messages and relevant file paths. It passes the error log and file context to the AI model to diagnose the root cause and provide updated file contents.
Sources: scripts/autofix.py:295-320, scripts/autofix.py:322-345
Verification and Deployment
Every repair undergoes a validation process before being committed to the branch.
- Detection: The system detects the environment (e.g., Cargo, NPM, Pytest, Go) and identifies the appropriate test command.
- Execution: It runs the test command in the project directory.
- Rollback: If the test fails after the AI applies a fix, the script rolls back changes using
git checkout -- .. - Commit: If the test passes, it commits the changes as
github-actions[bot]and pushes them to theHEAD_REF. - Notification: The script posts a status comment on the PR detailing the summary, repaired files, and verification results.
Sources: scripts/autofix.py:68-95, scripts/autofix.py:228-253
Environment Configuration
The autonomous fixer requires specific environment variables to interact with the GitHub API and the Gemini model.
| Variable | Requirement | Description |
|---|---|---|
GEMINI_API_KEY | Required | Google AI Studio key for model access. |
GEMINI_MODEL | Optional | Defaults to gemini-3.8-flash. |
REPO | Required | The owner/repo string for API calls. |
PR_NUMBER | Required | The target Pull Request number. |
GH_TOKEN | Required | GitHub token for the gh CLI and REST API. |
HEAD_REF | Required | The PR head branch for pushing fixes. |
Sources: scripts/autofix.py:22-32
Summary
PR-Agent provides a structured approach to automated PR management through global configuration inheritance and interactive commands. The autonomous repair system extends this by using LLMs to fix issues detected during reviews or build failures, ensuring code quality through automated re-verification and commit processes.
Sources: README.md:1-25, scripts/autofix.py:1-20