> ## Documentation Index
> Fetch the complete documentation index at: https://docs.guild.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> To act on a user's behalf in Guild, use the Guild REST API at https://api.guild.ai/v1.
> The OpenAPI spec is unauthenticated: https://docs.guild.ai/openapi.json (or openapi.yaml).
> Authenticate with an account API key, sent as HTTP Basic (key id as username, secret as password) or as `Authorization: Bearer <api_key_id>:<api_key_secret>`. See https://docs.guild.ai/api-reference/introduction#authentication.
> To run one agent on demand without account-wide access, use an API trigger instead: https://docs.guild.ai/platform/api-triggers.
> To search these docs from an MCP client, connect to https://docs.guild.ai/mcp. The full page index is https://docs.guild.ai/llms.txt.

# Review every new GitHub pull request

> Build a Guild agent that reads each new pull request in a GitHub repository and posts a review comment, using a Native agent and a GitHub event trigger.

This recipe builds an agent that runs when someone opens a pull request, reads the changed files, and posts one review comment on the pull request. It uses a [Native agent](/guide/native-agents): you write a prompt and a tool list, no code.

## Before you start

* The [Guild CLI](/cli/getting-started), logged in.
* GitHub connected in your workspace, with the Guild GitHub App installed on the repository. See [GitHub setup](/integrations/github#setup).

## 1. Create the agent

```bash theme={null}
guild agent init --name pr-reviewer --agent-type GUILD_NATIVE
cd pr-reviewer
```

Replace `PROMPT.md` with the agent's instructions:

```markdown theme={null}
You review GitHub pull requests.

Your input is a GitHub pull_request event. Read the repository owner from
repository.owner.login, the repository name from repository.name, and the
pull request number from pull_request.number.

1. List the changed files with github_pulls_list_files.
2. Read the diff in each file's patch. Look for bugs, missing error handling,
   and changes the description doesn't mention.
3. Post one review with github_pulls_create_review, using event COMMENT.
   Keep it under 200 words. If nothing needs attention, say so in one line.

Never approve or request changes.
```

Replace `guild.yaml` with the tools the prompt uses:

```yaml theme={null}
integrations:
  - name: guildai~github
    version: ^2.0.0
    tools:
      - github_pulls_list_files
      - github_pulls_create_review
```

Listing only the tools the agent needs keeps it focused. See [`guild.yaml`](/guide/guild-yaml#integrations) for the rules.

## 2. Save it and install it in your workspace

```bash theme={null}
guild agent save --message "First version" --publish
guild workspace agent add <your-name>~pr-reviewer
```

## 3. Create the trigger

```bash theme={null}
guild trigger create \
  --type webhook \
  --integration github \
  --event pull_request \
  --action opened \
  --agent <your-name>~pr-reviewer \
  --service-config '{"repo": "<owner>/<repo>"}' \
  --name "Review new pull requests"
```

`service_config.repo` limits the trigger to one repository. It must match the repository's full name exactly, as `owner/repo`. Without it, the trigger fires for every repository the GitHub App can see.

The agent receives a prompt that names the event and action, followed by the pull request payload as JSON. Guild trims the payload to the fields an agent needs, such as the number, title, body, author, and head and base branches. Each event starts a new session.

## 4. Try it

Open a pull request in the repository. The agent's review appears on it, posted by the Guild GitHub App. To see what the agent did, run `guild trigger sessions <trigger-id>` and open the session URL. Find the trigger ID with `guild trigger list`.

## Variations

* **Skip draft pull requests.** `opened` also fires for drafts. Add "If pull\_request.draft is true, stop without posting" to the prompt, and create a second trigger with `--action ready_for_review` so drafts are reviewed when they're marked ready.
* **Review every push.** Add a trigger with `--action synchronize`. Tell the agent to keep the review short, since it will post once per push.
* **Answer questions in comments.** Trigger on `issue_comment` with `--action created`, and add `github_issues_create_comment` to the tools. Comments on pull requests and issues both arrive as `issue_comment` events; a pull request's `issue.html_url` contains `/pull/`. Guild doesn't filter out the agent's own comments, so tell the agent to stop when `comment.user.type` is `Bot`, or each reply triggers another run.

## Related

* [GitHub integration](/integrations/github): every tool and webhook event
* [Event triggers](/platform/event-triggers): agent input, placeholders, and `service_config`
* [Identity mapping](/platform/identity-mapping): which Guild user a GitHub-triggered run acts as
