Customizing AI Prompts
Relevant source files
The following files were used as context for generating this wiki page:
Customizing AI Prompts allows you to define how the PR-Agent and autonomous repair tools interact with Large Language Models (LLMs) like Gemini. This system uses structured prompts to guide the AI in reviewing code, generating descriptions, and repairing build failures across the JWEB0689 fleet.
This configuration ensures consistent AI behavior by centralizing instructions in global settings while allowing repository-specific overrides.
Sources: README.md:1-15, scripts/autofix.py:32-35
Prompt Structures for Autonomous Repair
The autofix.py script defines specific system prompts that govern two primary modes of AI intervention: review-fix and ci-fix. These prompts enforce strict JSON output schemas to ensure the AI's response is programmatically actionable.
Review Findings Prompt
When the system detects review findings from PR-Agent, it uses the REVIEW_SYSTEM_PROMPT. This prompt instructs the AI to fix bugs and security issues while ignoring minor style nitpicks.
REVIEW_SYSTEM_PROMPT = """You are an autonomous senior software engineer fixing code review findings.
An AI code reviewer left the findings below on a pull request. For each finding:
1. Fix genuine bugs, errors, security issues, and broken logic the reviewer flagged.
2. Skip open questions, requests for discussion, and pure style nitpicks unless the fix is trivial and clearly safe.
3. Keep changes minimal, surgical, and idiomatic to the codebase.
Respond ONLY with a JSON object conforming strictly to this schema:
{
"summary": "Short explanation of what was fixed",
"files": [
{"path": "relative/path/to/file", "content": "Full, complete updated file contents"}
]
}
"""
Sources: scripts/autofix.py:169-185
CI Failure Repair Prompt
If build or test failures occur, the CI_SYSTEM_PROMPT directs the AI to diagnose the root cause and provide minimal, idiomatic fixes based on error logs.
Sources: scripts/autofix.py:187-200
AI Interaction Workflow
The following diagram illustrates how the system selects a prompt mode and interacts with the Gemini API to obtain fixes.
The workflow ensures that the AI receives the correct instructions (prompts) based on the current state of the Pull Request.
Sources: scripts/autofix.py:270-344
Configuration Hierarchy
The AI tools inherit settings through a layered configuration model. This allows for a baseline "personality" or "prompt style" across all repositories while enabling local customization.
| Level | File Location | Description |
|---|---|---|
| Global | JWEB0689/pr-agent-settings/.pr_agent.toml | Central settings loaded by PR-Agent for all repositories. |
| Repository | [target-repo]/.pr_agent.toml | Local overrides that change tool behavior for a specific project. |
| Environment | GitHub Actions Secrets/Variables | Defines the model (e.g., GEMINI_MODEL) used during prompt execution. |
Sources: README.md:10-25, scripts/autofix.py:46-51
Context Injection into Prompts
Prompts are not static strings; they are augmented with real-time repository data before being sent to the AI. The system assembles a comprehensive context block including findings, error logs, and file contents.
- Findings Injection: The
get_review_findingsfunction fetches inline comments and review summaries via the GitHub API. - File Context: The
read_file_contextfunction reads up to 12 modified or flagged files, provided they are under 80,000 bytes. - Prompt Assembly: The final string combines the System Prompt, a JSON-encoded findings list, and a JSON-encoded map of file paths to their full contents.
prompt = (REVIEW_SYSTEM_PROMPT
+ f"\n--- REVIEW FINDINGS (PR #{pr_number}) ---\n{findings_text}\n"
+ f"\n--- FILE CONTENTS ---\n{json.dumps(contexts, indent=2)}\n")
Sources: scripts/autofix.py:114-142, scripts/autofix.py:288-294
Summary of AI Constraints
To maintain stability, the prompts and their execution logic enforce several constraints on the AI:
- Response Format: The AI must return a JSON object with a
summaryand afileslist. - Surgical Changes: Prompts explicitly demand "minimal, surgical" changes to prevent unnecessary code churn.
- Verification: Every fix generated by a prompt is re-verified using the repository's native test runner (e.g.,
cargo check,npm test,pytest) before being committed.
Sources: scripts/autofix.py:84-112, scripts/autofix.py:236-250