Documentation

Run an agent when a pull request opens, changes or gets a review

The repository must be connected to Hydra. See Connect GitHub.

  1. Open New session and describe the agent. Name the repository, the pull requests it works on, and the changes it reacts to:

    Create an agent that reviews each open, non-draft pull request on acme/api for missing tests. It runs when the pull request opens, again when new commits are pushed, and again when someone requests changes.

  2. Answer the session's questions until it creates the agent.

  3. Open Agents in the sidebar and pick the agent. Under Configuration, its definition looks like this:

    agents:
      pr-reviewer:
        prompts:
          - /agents/pr-reviewer/prompt.md
        runs_when:
          review:
            lives_on: github/pr
            where: self.repo == "acme/api" && self.state == "open" && !self.draft
            mode: headless
            receives:
              - event: github/pr/updated
                where: event.subject == self && event.old.exists(old => old.head_sha != event.subject.head_sha)
              - event: github/review/submitted
                where: event.subject == self && event.data.state == "changes_requested"

    Check these parts against your request:

    • where names the repository and the pull requests the agent works on. The agent starts on each pull request that matches, including the ones that are already open when you create it.
    • Each receives rule names a change the agent hears about while where holds. head_sha changes when someone pushes commits.
    • When where stops matching, such as when the pull request merges or closes, the agent stops.
  4. Open a pull request on the repository. Open Sessions in the sidebar and pick the agent's new session.

  5. Request changes on the pull request. The session's chat shows New review.

Ask for other events in the same way, such as github/ci/failed for a failed CI run or github/comment/posted for a new comment. The events reference lists every GitHub event and its fields. The data model reference lists the fields of a pull request. The agent definition reference lists every key of a runs_when entry.