Skip to main content

GitHub Integration

In this page we will cover how to install and run PR-Agent as a GitHub Action or GitHub App, and how to configure it for your needs.

Run as a GitHub Action​

You can use our pre-built GitHub Action Docker image to run PR-Agent as a GitHub Action.

  1. Add the following file to your repository under .github/workflows/pr_agent.yml:

    on:
    pull_request:
    types: [opened, reopened, ready_for_review, synchronize]
    issue_comment:
    jobs:
    pr_agent_job:
    if: ${{ github.event.sender.type != 'Bot' }}
    runs-on: ubuntu-latest
    permissions:
    contents: read
    issues: write
    pull-requests: write
    name: Run pr agent on every pull request, respond to user comments
    steps:
    - name: PR Agent action step
    id: pragent
    uses: the-pr-agent/pr-agent@main
    env:
    OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  2. Add the following secret to your repository under Settings > Secrets and variables > Actions > New repository secret > Add secret:

    Name = OPENAI_KEY
    Secret = <your key>

    The GITHUB_TOKEN secret is automatically created by GitHub, but you must pass it to the action through env as shown above. If it is missing or empty, events with a PR or issue target fail with a nonzero exit status and a GITHUB_TOKEN not set message. Ignored comments and events without a target still skip successfully.

  3. Merge this change to your main branch. When you open your next PR, you should see a comment from github-actions bot with a review of your PR, and instructions on how to use the rest of the commands.

  4. You may configure PR-Agent by adding environment variables under the env section corresponding to any configurable property in the configuration file. Some examples:

    env:
    # ... previous environment values
    OPENAI.ORG: "<Your organization name under your OpenAI account>"
    PR_REVIEWER.REQUIRE_TESTS_REVIEW: "false" # Disable tests review
    PR_REVIEWER.NUM_MAX_FINDINGS: 5 # Increase number of review findings

See detailed usage instructions in the USAGE GUIDE

When a PR opens with a reviewer already requested, GitHub can send both opened and review_requested. With both actions enabled, the Action skips the initial review_requested event when the PR's creation and update timestamps match, so the commands run once for the opening event stream. A configuration that enables only review_requested still runs that event. Later review requests still run the enabled commands when review_requested is listed in github_action_config.pr_actions. This applies to both pull_request and pull_request_target.

Using with pull_request_target (fork/contribution support)​

By default, the pull_request event does not have access to repository or organization secrets when the PR originates from a forked repository, which means PR-Agent won't be able to access secrets such as OPENAI_KEY. The workflow still receives a GITHUB_TOKEN, but it has read-only permissions for fork pull requests by default. For private repositories, administrators can enable Send secrets to workflows from pull requests to make secrets available, but doing so exposes those secrets to workflows triggered by fork pull requests.

To support PRs from external contributors (forks), use the pull_request_target event instead. This event runs in the context of the base repository and has access to its secrets and GITHUB_TOKEN permissions. PR-Agent uses the GitHub API to fetch PR data and does not require a local checkout of the PR code.

name: PR Agent
on:
pull_request_target:
types: [opened, reopened, synchronize, ready_for_review, review_requested]
issue_comment:
jobs:
pr_agent_job:
if: ${{ github.event.sender.type != 'Bot' && (github.event_name == 'pull_request_target' || github.event.issue.pull_request) }}
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
pull-requests: write
steps:
- name: PR Agent action step
uses: the-pr-agent/pr-agent@main
env:
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
github_action_config.pr_actions: '["opened", "reopened", "synchronize", "ready_for_review", "review_requested"]'
No local checkout needed

PR-Agent uses the GitHub API to fetch PR data directly from the event payload — it does not require a local checkout of the PR code. This means you can safely omit the actions/checkout step entirely, avoiding common pitfalls with pull_request_target like the issue_comment event lacking a pull_request.head.sha ref.

Security considerations

Using pull_request_target gives the workflow access to repository secrets. Neither event checks out code on its own, but under pull_request_target a plain actions/checkout fetches the default branch rather than the pull request, which is a security feature. Checking out the pull request head alone does not execute untrusted code, but do not build, test, install, or otherwise execute that content in the same job with secrets or elevated token permissions. If local files are required, review the GitHub security guide on pull_request_target before checking out the pull request head.

Configuration Examples​

This section provides detailed, step-by-step examples for configuring PR-Agent with different models and advanced options in GitHub Actions.

Fallback models

config.fallback_models should not repeat config.model: a fallback-eligible failure would just run the same model again. The examples below use '[]' for no backup model, or a different model when one is shown. To retry a failed call on the primary model instead, set config.num_retries.

Quick Start Examples​

Basic Setup (OpenAI Default)​

Copy this minimal workflow to get started with the default OpenAI models:

name: PR Agent
on:
pull_request:
types: [opened, reopened, ready_for_review]
issue_comment:
jobs:
pr_agent_job:
if: ${{ github.event.sender.type != 'Bot' }}
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
pull-requests: write
steps:
- name: PR Agent action step
uses: the-pr-agent/pr-agent@main
env:
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Gemini Setup​

Ready-to-use workflow for Gemini models:

name: PR Agent (Gemini)
on:
pull_request:
types: [opened, reopened, ready_for_review]
issue_comment:
jobs:
pr_agent_job:
if: ${{ github.event.sender.type != 'Bot' }}
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
pull-requests: write
steps:
- name: PR Agent action step
uses: the-pr-agent/pr-agent@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
config.model: "gemini/gemini-3.8-flash"
config.fallback_models: '[]'
GOOGLE_AI_STUDIO.GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
github_action_config.auto_review: "true"
github_action_config.auto_describe: "true"
github_action_config.auto_improve: "true"
Claude Setup​

Ready-to-use workflow for Claude models:

name: PR Agent (Claude)
on:
pull_request:
types: [opened, reopened, ready_for_review]
issue_comment:
jobs:
pr_agent_job:
if: ${{ github.event.sender.type != 'Bot' }}
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
pull-requests: write
steps:
- name: PR Agent action step
uses: the-pr-agent/pr-agent@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
config.model: "anthropic/claude-opus-5"
config.fallback_models: '["anthropic/claude-haiku-4-5-20251001"]'
ANTHROPIC.KEY: ${{ secrets.ANTHROPIC_KEY }}
github_action_config.auto_review: "true"
github_action_config.auto_describe: "true"
github_action_config.auto_improve: "true"

Basic Configuration with Command Controls​

Start with this enhanced workflow that includes command configuration:

on:
pull_request:
types: [opened, reopened, ready_for_review]
issue_comment:
jobs:
pr_agent_job:
if: ${{ github.event.sender.type != 'Bot' }}
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
pull-requests: write
name: Run pr agent on every pull request, respond to user comments
steps:
- name: PR Agent action step
id: pragent
uses: the-pr-agent/pr-agent@main
env:
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Enable/disable automatic commands
github_action_config.auto_review: "true"
github_action_config.auto_describe: "true"
github_action_config.auto_improve: "true"
# Configure which PR events trigger the action
github_action_config.pr_actions: '["opened", "reopened", "ready_for_review", "review_requested"]'

Switching Models​

Using Gemini (Google AI Studio)​

To use Gemini models instead of the default OpenAI models:

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Set the model to Gemini
config.model: "gemini/gemini-3.8-flash"
config.fallback_models: '[]'
# Add your Gemini API key
GOOGLE_AI_STUDIO.GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
# Command configuration
github_action_config.auto_review: "true"
github_action_config.auto_describe: "true"
github_action_config.auto_improve: "true"

Required Secrets:

Note: When using non-OpenAI models like Gemini, you don't need to set OPENAI_KEY - only the model-specific API key is required.

Using Claude (Anthropic)​

To use Claude models:

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Set the model to Claude
config.model: "anthropic/claude-opus-5"
config.fallback_models: '["anthropic/claude-haiku-4-5-20251001"]'
# Add your Anthropic API key
ANTHROPIC.KEY: ${{ secrets.ANTHROPIC_KEY }}
# Command configuration
github_action_config.auto_review: "true"
github_action_config.auto_describe: "true"
github_action_config.auto_improve: "true"

Required Secrets:

Note: When using non-OpenAI models like Claude, you don't need to set OPENAI_KEY - only the model-specific API key is required.

Using Azure OpenAI​

To use Azure OpenAI services:

env:
OPENAI_KEY: ${{ secrets.AZURE_OPENAI_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Azure OpenAI configuration
OPENAI.API_TYPE: "azure"
OPENAI.API_VERSION: "2023-05-15"
OPENAI.API_BASE: ${{ secrets.AZURE_OPENAI_ENDPOINT }}
OPENAI.DEPLOYMENT_ID: ${{ secrets.AZURE_OPENAI_DEPLOYMENT }}
# Set the model to match your Azure deployment
config.model: "gpt-4o"
config.fallback_models: '[]'
# Command configuration
github_action_config.auto_review: "true"
github_action_config.auto_describe: "true"
github_action_config.auto_improve: "true"

Required Secrets:

  • AZURE_OPENAI_KEY: Your Azure OpenAI API key
  • AZURE_OPENAI_ENDPOINT: Your Azure OpenAI endpoint URL
  • AZURE_OPENAI_DEPLOYMENT: Your deployment name
Using Local Models (Ollama)​

To use local models via Ollama:

env:
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Set the model to a local Ollama model
config.model: "ollama/qwen2.5-coder:32b"
config.fallback_models: '[]'
config.custom_model_max_tokens: "128000"
# Ollama configuration
OLLAMA.API_BASE: "http://<ollama-host-reachable-from-container>:11434"
# Command configuration
github_action_config.auto_review: "true"
github_action_config.auto_describe: "true"
github_action_config.auto_improve: "true"

Note: Ollama must be reachable from the action's Docker container. localhost inside that container refers to the container itself, not the runner host. If Ollama runs on a self-hosted runner, configure a host address and Ollama network binding that the action container can reach.

Using Amazon Bedrock​

To use Amazon Bedrock models with static IAM credentials:

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
config.model: "bedrock/us.anthropic.claude-sonnet-4-6"
config.fallback_models: '[]'
aws.AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws.AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws.AWS_REGION_NAME: "us-east-1"

Recommended: IAM Role Credentials on AWS Compute

When the GitHub Actions runner is on AWS infrastructure (EC2, ECS, EKS), use the instance/task IAM role directly — no secrets required:

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
config.model: "bedrock/us.anthropic.claude-sonnet-4-6"
config.fallback_models: '[]'
AWS_USE_IMDS: "true"
AWS_REGION_NAME: us-east-1 # source region for the US inference profile

The IAM role must have bedrock:InvokeModel on the inference profile and its destination foundation models. See Bedrock model configuration for the full IAM policy example and supported models.

To route calls through a VPC interface endpoint, add AWS_BEDROCK_RUNTIME_ENDPOINT alongside the credentials above:

env:
AWS_BEDROCK_RUNTIME_ENDPOINT: "https://bedrock-runtime.us-east-1.amazonaws.com"

Advanced Configuration Options​

Custom Review Instructions​

Add specific instructions for the review process:

env:
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Custom review instructions
pr_reviewer.extra_instructions: "Focus on security vulnerabilities and performance issues. Check for proper error handling."
# Command configuration
github_action_config.auto_review: "true"
github_action_config.auto_describe: "true"
github_action_config.auto_improve: "true"
Language-Specific Configuration​

Configure for specific programming languages:

env:
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Language-specific settings
pr_reviewer.extra_instructions: "Focus on Python best practices, type hints, and docstrings."
pr_reviewer.num_max_findings: "5"
# Command configuration
github_action_config.auto_review: "true"
github_action_config.auto_describe: "true"
github_action_config.auto_improve: "true"
Selective Command Execution​

Run only specific commands automatically:

env:
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Only run review and describe; the review also runs when auto_improve is enabled
github_action_config.auto_review: "true"
github_action_config.auto_describe: "true"
github_action_config.auto_improve: "false"
# Only trigger on PR open and reopen
github_action_config.pr_actions: '["opened", "reopened"]'
CI artifact context​

A file produced by an earlier CI step — a test report, a coverage summary, a linter or SAST output — can be injected into the prompts of /review and /describe, so the model reviews the PR with your pipeline's own findings in hand.

Point the action at the file with the artifact_path input. The path is resolved relative to GITHUB_WORKSPACE (an absolute path also works), so the file must already exist in the workspace when PR-Agent runs — produce it in a previous step, or download it with actions/download-artifact:

steps:
- uses: actions/checkout@v4
- name: Run tests
run: pytest --junitxml=reports/pytest.xml || true
- name: PR Agent action step
uses: the-pr-agent/pr-agent@main
env:
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
artifact_path: reports/pytest.xml
artifact_instructions: "These are the failing tests from this PR's CI run. Call out any suggestion that would not fix them."

Setting artifact_path turns the feature on by itself; there is no separate enable switch to flip in the workflow. Supported target commands receive a dedicated artifact section in their prompt. The label and file contents are explicitly marked as untrusted data, while artifact_instructions appears separately as subordinate analysis guidance. The supported targets are pr_reviewer, pr_description, pr_code_suggestions and pr_questions; unsupported names are skipped with a warning.

When overriding a supported command's prompt, keep artifact_context.instructions in the system prompt and render artifact_context.label, artifact_context.content, artifact_context.start_marker, and artifact_context.end_marker in a clearly marked, untrusted section of the user prompt. This replaces the legacy extra_instructions behavior for CI artifacts.

The remaining knobs live in the [artifacts] section of your configuration:

[artifacts]
enable = true # required when configuring paths here
artifact_path = [
{ path = "reports/pytest.xml" },
{ path = "reports/coverage.xml" },
]
artifact_instructions = "" # empty = a generic "treat this as CI context" instruction
artifact_label = "" # shared label; empty = each file's name
target_commands = ["pr_reviewer", "pr_description", "pr_code_suggestions", "pr_questions"]
max_artifact_size = 50000 # characters; longer files are truncated with a marker

artifact_path may also be a single string. For multiple files, each entry can set path, artifact_label, artifact_instructions, target_commands, and truncate_from on its own line; a shared artifact_label applies only to a single file, otherwise each file falls back to its name.

Automatic enabling applies to the action's artifact_path input or the ARTIFACT_PATH / PR_AGENT_ARTIFACT_PATH environment variables. A path set only in [artifacts] requires enable = true.

CI artifacts are checked for recognizable URL credentials, authorization headers, standard GitLab tokens, AWS access keys, and common credential assignments before model submission, with redaction matches logged only by type and count; this pattern-based check does not recognize every secret format, so use sanitized CI logs as input.

Note

A path that resolves outside GITHUB_WORKSPACE is rejected, and a missing or unreadable file is skipped with a warning — in both cases the commands still run, just without the artifact context.

The same settings apply when PR-Agent runs as a CLI from another CI system, with ARTIFACT_PATH set in the job's environment; see the GitLab pipeline example.

Using Configuration Files​

Instead of setting all options via environment variables, you can use a .pr_agent.toml file in your repository root:

  1. Create a .pr_agent.toml file in your repository root:

    [config]
    model = "gemini/gemini-3.8-flash"
    fallback_models = ["anthropic/claude-opus-5"]

    [pr_reviewer]
    extra_instructions = "Focus on security issues and code quality."

    [pr_code_suggestions]
    committable_code_suggestions = true
  2. Use a simpler workflow file:

    on:
    pull_request:
    types: [opened, reopened, ready_for_review]
    issue_comment:
    jobs:
    pr_agent_job:
    if: ${{ github.event.sender.type != 'Bot' }}
    runs-on: ubuntu-latest
    permissions:
    contents: read
    issues: write
    pull-requests: write
    name: Run pr agent on every pull request, respond to user comments
    steps:
    - name: PR Agent action step
    id: pragent
    uses: the-pr-agent/pr-agent@main
    env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    GOOGLE_AI_STUDIO.GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
    ANTHROPIC.KEY: ${{ secrets.ANTHROPIC_KEY }}
    github_action_config.auto_review: "true"
    github_action_config.auto_describe: "true"
    github_action_config.auto_improve: "true"

Troubleshooting Common Issues​

Model Not Found Errors​

If you get model not found errors:

  1. Check model name format: Ensure you're using the correct model identifier format (e.g., gemini/gemini-3.8-flash, not just gemini-3.8-flash)

  2. Verify API keys: Make sure your API keys are correctly set as repository secrets

  3. Check model availability: Some models may not be available in all regions or may require specific access

Environment Variable Format​

Remember these key points about environment variables:

  • Use dots (.) or double underscores (__) to separate sections and keys
  • Boolean values should be strings: "true" or "false"
  • Arrays should be JSON strings: '["item1", "item2"]'
  • Model names are case-sensitive
Rate Limiting​

If you encounter rate limiting (HTTP 429 responses):

env:
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Add a fallback model for better reliability
config.fallback_models: '["your-fallback-model"]'
# Same-model retries of a 429, 5xx or connection error before fallback_models (default 4, max 10),
# each waiting for the provider's Retry-After or backing off. A quota error is retried but never recovers.
config.num_retries: "6"
# Increase timeout for slower models (does not help pure 429 rate-limit responses)
config.ai_timeout: "300"
github_action_config.auto_review: "true"
github_action_config.auto_describe: "true"
github_action_config.auto_improve: "true"

A 429 is returned immediately; raising config.ai_timeout only bounds the duration of each individual request and does not change rate-limit behavior. Use config.num_retries (see pr_agent/settings/configuration.toml) for transient provider errors. Each model listed in config.fallback_models receives its own independent retry budget.

Common Error Messages and Solutions​

Error: "Model not found"

  • Solution: Check the model name format and ensure it matches the exact identifier. See the Changing a model in PR-Agent guide for supported models and their correct identifiers.

Error: "API key not found"

  • Solution: Verify that your API key is correctly set as a repository secret and the environment variable name matches exactly
  • Note: For non-OpenAI models (Gemini, Claude, etc.), you only need the model-specific API key, not OPENAI_KEY

Error: "Incorrect API key provided: dummy_key"

  • Cause: No usable key for the active model's provider reached the run. For automatic runs and commands other than bare /help, /config, or /settings, the step log now shows Stopping before any command runs with the missing variable named, and the job fails at once; older versions logged OPENAI_KEY not set near the top and carried on, so the request went out with PR-Agent's placeholder key instead and failed a full run later.
  • Note: For PR issue_comment and pull_request_review_comment events, bare /help, /config, and /settings skip this model-key check (ignoring case and surrounding whitespace). They still need GITHUB_TOKEN; commands with arguments, including /help <question>, retain the check.
  • Solution: Check which of the three causes applies:
    • The run gets no secrets. On the pull_request event, runs triggered from a fork receive no repository secrets, so ${{ secrets.OPENAI_KEY }} is empty. Use the pull_request_target setup instead. Dependabot pull requests are the same case: their secrets live under Dependabot secrets, not Actions secrets, and the github.event.sender.type != 'Bot' condition in the examples above keeps those runs from starting at all.
    • The secret is missing or misnamed. A reference to a secret that does not exist expands to an empty string rather than failing the workflow, so compare the name in the repository secrets with the one used in env.
    • Another provider's key is set, but the model is not. Keys alone do not switch provider: set config.model (and config.fallback_models) as well, otherwise the default OpenAI model is used and only an OpenAI key counts. See Changing a model in PR-Agent.

Error: "Rate limit exceeded"

  • Solution: Add fallback models and/or set config.num_retries (recommended for transient 429s). Raising config.ai_timeout only helps with timeouts, not pure rate-limit responses. For a manual /review failure, you can also set pr_reviewer.publish_error_details: "true" in the workflow env (it cannot be enabled via .pr_agent.toml) to surface a sanitized failure reason. See the Review command docs.

Error: "Permission denied"

  • Solution: Ensure your workflow has the correct permissions set:
    permissions:
    contents: read
    issues: write
    pull-requests: write
    The default commands need no additional scopes. Add checks: write when github.publish_as_check_run or pr_reviewer.publish_merge_recommendation_status is enabled. Features that push repository contents, such as pr_update_changelog.push_changelog_changes, require contents: write, and so does pr_questions.resolve_threads, because GitHub gates thread resolution on that scope. If you omit contents: write, enable config.restricted_mode so operations that need it are skipped or fall back safely, and keep pr_questions.resolve_threads off, since restricted mode does not cover it. See the Restricted Mode guide for details.

Error: "PR-Agent command was not run" for incomplete GitHub files

  • Cause: GitHub limits pull-request changed-file responses to 3,000 files. A mismatch can also occur when GitHub returns inconsistent file-count metadata.
  • Solution: If the pull request changes more than 3,000 files, split it into smaller pull requests and run the command again. Otherwise, retry the command.

Error: "Invalid JSON format"

  • Solution: Check that arrays are properly formatted as JSON strings:

Correct:
config.fallback_models: '["model1", "model2"]'
Incorrect (interpreted as a YAML list, not a string):
config.fallback_models: ["model1", "model2"]
Debugging Tips​
  1. Enable verbose logging: Add config.verbosity_level: "2" to see detailed logs
  2. Check GitHub Actions logs: Look at the step output for specific error messages
  3. Test with minimal configuration: Start with just the basic setup and add options one by one
  4. Verify secrets: Double-check that all required secrets are set in your repository settings
Performance Optimization​

For better performance with large repositories:

env:
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Optimize for large PRs
config.large_patch_policy: "clip"
config.max_model_tokens: "32000"
config.patch_extra_lines_before: "3"
config.patch_extra_lines_after: "1"
github_action_config.auto_review: "true"
github_action_config.auto_describe: "true"
github_action_config.auto_improve: "true"

Reference​

For more detailed configuration options, see:

Using a specific release​

Tip

if you want to pin your action to a specific release (v0.41.0 for example) for stability reasons, use:

...
steps:
- name: PR Agent action step
id: pragent
uses: docker://pragent/pr-agent:0.41.0-github_action
...

For enhanced security, you can also specify the Docker image by its digest. Resolve the digest for the version you are pinning with docker buildx imagetools inspect pragent/pr-agent:0.41.0-github_action --format '{{.Manifest.Digest}}', then use it in place of the tag:

...
steps:
- name: PR Agent action step
id: pragent
uses: docker://pragent/pr-agent@sha256:<digest>
...

Official Docker Hub release images also publish GitHub Artifact Attestations, so you can verify that a pinned digest was built from this repository before using it:

gh attestation verify \
"oci://index.docker.io/pragent/pr-agent@sha256:<digest>" \
--repo The-PR-Agent/pr-agent

Action for GitHub enterprise server or GHE.com​

Tip

To use the action with a GitHub enterprise server, add an environment variable GITHUB__BASE_URL with the API URL of your GitHub server.

For example, if your GitHub server is at https://github.mycompany.com, add the following to your workflow file:

env:
# ... previous environment values
GITHUB__BASE_URL: "https://github.mycompany.com/api/v3"

For GitHub Enterprise Cloud with data residency (GHE.com), set GITHUB__BASE_URL to the API host https://api.<subdomain>.ghe.com, which the workflow exposes as github.api_url:

env:
# ... previous environment values
GITHUB__BASE_URL: ${{ github.api_url }} # e.g. https://api.mycompany.ghe.com

Run as a GitHub App​

Allowing you to automate the review process on your private or public repositories.

  1. Create a GitHub App from the GitHub Developer Portal.

    • Set the following permissions:
      • Pull requests: Read & write
      • Issues: Read & write
      • Metadata: Read-only
      • Contents: Read-only (or Read & write if using resolve_threads — see note below)
    • Set the following events:
      • Issue comment
      • Pull request
      • Pull request review
      • Push (if you need to enable triggering on PR update)
      • Pull request review comment (required for /ask on review threads)

    Note: If you enable pr_questions.resolve_threads, the GitHub App requires Contents: Read & write permission. GitHub's resolveReviewThread GraphQL mutation is gated behind the Contents permission, even though it only modifies PR thread metadata. See GitHub community discussion for details.

    Important: When enabled, the LLM may resolve threads started by human reviewers — not only bot-generated threads. Use this setting only when your team is comfortable with AI-driven thread resolution. The feature is opt-in and defaults to off.

  2. Generate a random secret for your app, and save it for later. The webhook secret is required: if GITHUB.WEBHOOK_SECRET is not configured, the server rejects every incoming webhook with HTTP 403. For example, you can use:

    WEBHOOK_SECRET=$(python -c "import secrets; print(secrets.token_hex(10))")
  3. Acquire the following pieces of information from your app's settings page:

    • App private key (click "Generate a private key" and save the file)
    • App ID
  4. Clone this repository:

    git clone https://github.com/the-pr-agent/pr-agent.git
    cd pr-agent
  5. Copy the secrets template file and fill in the following:

    cp pr_agent/settings/.secrets_template.toml pr_agent/settings/.secrets.toml
    # Edit .secrets.toml file
    • Your OpenAI key.
    • Copy your app's private key to the private_key field.
    • Copy your app's ID to the app_id field.
    • Copy your app's webhook secret to the webhook_secret field (required).
    • The GitHub App sets deployment_type to app automatically by default. No manual configuration is needed unless github_app.override_deployment_type is disabled.

    The local .secrets.toml file is excluded from the Docker build context. Never bake secrets into a container image. For container deployments, provide secrets at runtime through environment variables or a mounted secret volume. For example, in order to inject a secrets file as a volume in a Kubernetes environment you can update your pod spec to include the following, assuming you have a secret named pr-agent-settings with a key named .secrets.toml:

    volumes:
    - name: settings-volume
    secret:
    secretName: pr-agent-settings
    // ...
    containers:
    // ...
    volumeMounts:
    - mountPath: /app/pr_agent/settings_prod
    name: settings-volume

    Service images run as UID/GID 10001: mounted secrets must be readable, and mounted data paths writable, by that user. Home-relative mounts belong under /home/pragent.

    Another option is to set the secrets as environment variables in your deployment environment, for example OPENAI__KEY, GITHUB__APP_ID, GITHUB__PRIVATE_KEY, and GITHUB__WEBHOOK_SECRET.

  6. Build a Docker image for the app and optionally push it to a Docker repository. We'll use Dockerhub as an example:

    docker build . -t pr-agent:github_app --target github_app -f docker/Dockerfile

    # Optional, to push it to your own Docker repository:
    docker tag pr-agent:github_app <your-registry>/pr-agent:github_app
    docker push <your-registry>/pr-agent:github_app
  7. Host the app using a server, serverless function, or container environment. Alternatively, for development and debugging, you may use tools like smee.io to forward webhooks to your local machine. You can check Deploy as a Lambda Function

  8. Go back to your app's settings, and set the following:

    • Webhook URL: https://<PR_AGENT_HOSTNAME>/api/v1/github_webhooks, or your smee.io channel URL with forwarding configured to that endpoint.
    • Webhook secret: The secret you generated earlier.
  9. Install the app by navigating to the "Install App" tab and selecting your desired repositories.

  10. The app runs under gunicorn with multiple worker processes. See Sizing a self-hosted webhook server for the GUNICORN_WORKERS / GUNICORN_MAX_WORKERS knobs and memory guidance — worth reading before setting a memory limit.

Note: When running PR-Agent from GitHub app, the default configuration file (configuration.toml) will be loaded. However, you can override the default command parameters by uploading a local configuration file .pr_agent.toml To use organization-level global configuration, set config.global_settings_repo = "pr-agent-settings", create <organization>/pr-agent-settings with a .pr_agent.toml file, and install the GitHub App on that repository too. The app needs read access to the settings repository as well as the pull request repositories. This applies to both GitHub.com and GitHub Enterprise Server. For more information please check out the USAGE GUIDE


Additional deployment methods​

Deploy as a Lambda Function​

Note that since AWS Lambda env vars cannot have "." in the name, you can replace each "." in an env variable with "__".
For example: GITHUB.WEBHOOK_SECRET --> GITHUB__WEBHOOK_SECRET

  1. Follow steps 1-5 from here.

  2. Build a docker image that can be used as a lambda function

    docker buildx build --platform=linux/amd64 . -t pr-agent:github_lambda --target github_lambda -f docker/Dockerfile.lambda

    (Note: --target github_lambda is optional as it's the default target)

  3. Push image to ECR

    docker tag pr-agent:github_lambda <AWS_ACCOUNT>.dkr.ecr.<AWS_REGION>.amazonaws.com/pr-agent:github_lambda
    docker push <AWS_ACCOUNT>.dkr.ecr.<AWS_REGION>.amazonaws.com/pr-agent:github_lambda
  4. Create a lambda function that uses the uploaded image. Add the IAM permission lambda:InvokeFunction on the function itself to the execution role: the webhook is acknowledged as soon as its signature is verified, and the review runs in a second, asynchronous invocation of the same function. Set the lambda timeout for the review length (for example 5m) — it no longer needs to cover the webhook acknowledgement. Lambda retries a timed-out or failed asynchronous invocation twice by default, which would run the review again; set the function's asynchronous invocation retry attempts to 0 if you do not want that.

  5. Configure the lambda function to have a Function URL.

  6. In the environment variables of the Lambda function, specify AZURE_DEVOPS_CACHE_DIR to a writable location such as /tmp. (see link)

  7. Go back to steps 8-9 of Method 5 with the function url as your Webhook URL. The Webhook URL would look like https://<LAMBDA_FUNCTION_URL>/api/v1/github_webhooks

Using AWS Secrets Manager​

For production Lambda deployments, use AWS Secrets Manager instead of environment variables:

  1. Create a secret in AWS Secrets Manager with JSON format like this:

    {
    "openai.key": "sk-proj-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "github.app_id": 123456,
    "github.webhook_secret": "your-webhook-secret-from-step-2",
    "github.private_key": "-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEA...\n-----END RSA PRIVATE KEY-----"
    }
  2. Add IAM permission secretsmanager:GetSecretValue to your Lambda execution role

  3. Set these environment variables in your Lambda:

    AWS_SECRETS_MANAGER__SECRET_ARN=arn:aws:secretsmanager:us-east-1:123456789012:secret:pr-agent-secrets-AbCdEf
    CONFIG__SECRET_PROVIDER=aws_secrets_manager

AWS CodeCommit Setup​

Not all features have been added to CodeCommit yet. As of right now, CodeCommit has been implemented to run the PR-Agent CLI on the command line, using AWS credentials stored in environment variables. CodeCommit pull requests with multiple targets are reviewed across every target repository and commit comparison; single-target pull requests keep the same behavior. The following is a set of instructions to have PR-Agent do a review of your CodeCommit pull request from the command line:

  1. Create an IAM user that you will use to read CodeCommit pull requests and post comments
    • Note: That user should have CLI access only, not Console access
  2. Add IAM permissions to that user, to allow access to CodeCommit (see IAM Role example below)
  3. Generate an Access Key for your IAM user
  4. Set the Access Key and Secret using environment variables (see Access Key example below)
  5. Set the git_provider value to codecommit in the pr_agent/settings/configuration.toml settings file
  6. Set the PYTHONPATH to include your pr-agent project directory
    • Option A: Run export PYTHONPATH="/PATH/TO/PROJECTS/pr-agent" in your shell. PR-Agent does not automatically load .env files.
    • Option B: Set PYTHONPATH and run the CLI in one command, for example:
      • PYTHONPATH="/PATH/TO/PROJECTS/pr-agent" python pr_agent/cli.py [--ARGS]

AWS CodeCommit IAM Role Example​

Example IAM permissions to that user to allow access to CodeCommit:

  • Note: The following is a working example of IAM permissions that has read access to the repositories and write access to allow posting comments
  • Note: If you only want pr-agent to review your pull requests, you can tighten the IAM permissions further, however this IAM example will work, and allow the pr-agent to post comments to the PR
  • Note: You may want to replace the "Resource": "*" with your list of repos, to limit access to only those repos
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"codecommit:BatchDescribe*",
"codecommit:BatchGet*",
"codecommit:Describe*",
"codecommit:EvaluatePullRequestApprovalRules",
"codecommit:Get*",
"codecommit:List*",
"codecommit:PostComment*",
"codecommit:PutCommentReaction",
"codecommit:UpdateComment",
"codecommit:UpdatePullRequestDescription",
"codecommit:UpdatePullRequestTitle"
],
"Resource": "*"
}
]
}

AWS CodeCommit Access Key and Secret​

Example setting the Access Key and Secret using environment variables

export AWS_ACCESS_KEY_ID="XXXXXXXXXXXXXXXX"
export AWS_SECRET_ACCESS_KEY="XXXXXXXXXXXXXXXX"
export AWS_DEFAULT_REGION="us-east-1"

AWS CodeCommit CLI Example​

After you set up AWS CodeCommit using the instructions above, here is an example CLI run that tells pr-agent to review a given pull request. (Replace your specific PYTHONPATH and PR URL in the example)

PYTHONPATH="/PATH/TO/PROJECTS/pr-agent" python pr_agent/cli.py \
--pr_url https://us-east-1.console.aws.amazon.com/codesuite/codecommit/repositories/MY_REPO_NAME/pull-requests/321 \
review