Configuring Standalone Workflows
Relevant source files
The following files were used as context for generating this wiki page:
Standalone workflows enable individual repositories to execute autonomous code repairs and custom PR-Agent actions independently of global settings. These workflows leverage GitHub Actions and specialized scripts to analyze pull request findings, validate code changes through local test runners, and push automated fixes to the source branch.
Repositories can use the central reusable workflow located at .github/workflows/pr_agent.yml or implement a standalone version to manage specific CI/CD requirements. The workflow integrates with Gemini AI models to interpret review comments and CI failures, providing commit-ready code updates.
Sources: README.md:14-16, scripts/autofix.py:5-13
Workflow Architecture and Modes
The standalone workflow operates in two primary execution modes determined at runtime: review-fix and ci-fix. The system attempts to resolve issues flagged by the AI reviewer first before falling back to repairing general build or test failures.
Autonomous Repair Flow
The following diagram illustrates the decision logic used by the autonomous fixer to determine the repair mode.
Configuration and Environment
Standalone workflows require specific environment variables to interact with the GitHub API and Gemini AI services. Configuration settings are often inherited from .pr_agent.toml but can be overridden at the repository level.
Required Environment Variables
| Variable | Description | Source |
|---|---|---|
GEMINI_API_KEY | Google AI Studio key required for code generation. | scripts/autofix.py:19 |
REPO | The owner/repo string used for fetching review comments. | scripts/autofix.py:21 |
PR_NUMBER | The ID of the pull request for status updates. | scripts/autofix.py:22 |
HEAD_REF | The PR head branch name used for pushing fixes. | scripts/autofix.py:23 |
GH_TOKEN | GitHub token for authentication with the gh CLI and API. | scripts/autofix.py:25 |
Sources: scripts/autofix.py:18-26
Test Runner Detection Logic
The workflow automatically identifies the appropriate test command based on the repository structure. This allows the standalone workflow to validate AI-generated fixes before they are committed to the repository.
| File Pattern | Context/Directory | Command |
|---|---|---|
v2/Cargo.toml | v2 | cargo check --workspace --no-default-features |
ui/mobile/package.json | ui/mobile | npm test --if-present |
Cargo.toml | . | cargo check --workspace |
package.json | . | npm test or npm run build |
pyproject.toml | . | pytest -q |
go.mod | . | go test ./... |
Sources: scripts/autofix.py:64-88
Implementation Details
Review Finding Collection
The get_review_findings function retrieves both inline comments and review summaries. It filters out bot commands like /autofix and limits summary processing to the two most recent entries to maintain context relevance.
def get_review_findings(repo, pr_number):
findings = []
# Fetches inline comments via GitHub API
for c in gh_api_get(f"/repos/{repo}/pulls/{pr_number}/comments") or []:
body = (c.get("body") or "").strip()
if not body or body.strip() == "/autofix":
continue
findings.append({
"path": c.get("path"),
"line": c.get("line"),
"body": body[:2000],
})
return findings
Sources: scripts/autofix.py:175-207
Verification and Commit
After applying a repair, the system executes the detected test command. If the command fails, the script invokes git checkout -- . to revert changes. If it passes, the script configures a github-actions[bot] user and pushes a new commit to the HEAD_REF.
Sources: scripts/autofix.py:249-275, scripts/autofix.py:287-302
Summary
Standalone workflows provide a decentralized method for repositories to automate code maintenance. By integrating Gemini AI with local environment detection and GitHub Actions, the system ensures that automated repairs are both context-aware and verified against the specific test suite of the repository.