5. Set Up Triggers
A trigger is a rule: when this event occurs, run this agent with this prompt. Autoheal keeps triggers next to agents, not in agent.yaml, so one agent can have many triggers.
Before you start
Do chapter 4 first. This chapter uses the GitHub Integration Connection and the repository from that chapter.
Step 1: Send GitHub events to Autoheal
GitHub tells Autoheal about a new pull request through a webhook. You add the webhook to your repository one time. This step is necessary for a GitHub App and for a token.
- Copy the webhook URL and secret
Go to Settings → Integrations and open GitHub. On the Configure tab, find Webhook configuration in the Events Setup section. Copy the Webhook URL and the Webhook signing secret.
- Add the webhook in GitHub
In GitHub, open your repository's Settings → Webhooks and click Add webhook. Paste the URL into Payload URL, set Content type to
application/json, and paste the secret into Secret. - Select the events
Select Let me select individual events, select Pull requests, and click Add webhook. GitHub sends a test event. A green check next to the webhook shows that Autoheal accepted it.
Step 2: Create the trigger
Go to Agent Studio → Triggers, click New trigger, and select On an event. The trigger editor opens. Replace its content with this definition:
apiVersion: triggers.autoheal.ai/v1
name: Review new pull requests
on:
github.pull_request:
- action: opened
- pull_request.draft: false
run:
agent: agents:pr-review
with:
prompt: ${{ event.data.pull_request.html_url }}
post_comment: true
limits:
max_con: 2
| Part | What it does |
|---|---|
on | The event, and the filters on the event's data. All filters must match. |
run.agent | The agent to run, as a reference: agents:<id>. |
with | The agent's inputs. You must give prompt. ${{ event.data.* }} reads a value from the event. |
limits.max_con | The maximum number of runs of this trigger at the same time. |
Step 3: Test the trigger with a sample event
In the Test fire panel, keep Schema sample and run the test. The Dry run result shows Match or No match, and the inputs that the agent would get. The test does not start a run.
When the result is correct, click Save.
Step 4: Open a pull request
Open a new pull request in your repository. A new run starts. You find it in Runs, and the run shows that the trigger started it. When the run ends, check that the pull request has a comment with the review.
Events you can use
| Event | When it occurs |
|---|---|
github.<event> | GitHub sends a webhook, for example github.pull_request, github.push or github.release. Any GitHub webhook event name works. |
servicenow.incident_created, servicenow.incident_updated | Someone creates or changes an incident in ServiceNow. |
slack.app_mention, slack.message | Someone mentions Autoheal in a Slack channel, or sends a direct message to the Autoheal app. |
alertgroup.created | A new alert group opens in Autoheal. |
To run an agent on a schedule, use cron instead of on. To run it once at a later time, use once.
What to know
-
If Computers are enabled, set
run.computerto a pool ID from the trigger's project. Each run gets its own VM from that pool. The pool can supply a VM it has already warmed up and retires it when the run finishes.YAMLrun:
agent: agents:code_reviewer
computer: 35c05c8a-1b27-40d0-8a25-e4030afdda34 -
run.branchkeeps the trigger on a branch. Changes onmaindo not reach the trigger until you choose. See chapter 6. -
limits.rate_per_minlimits the number of new runs in one minute. When there are too many events, Autoheal drops the extra events. It does not queue them. -
One agent can have many triggers, for example one for new pull requests and one for a weekly review of open pull requests.
-
This trigger starts a run for each new pull request in each repository that sends events to this Integration Connection. To limit it to one repository, add the filter
repository.full_name: <owner>/<repository>.
From the CLI
autoheal triggers catalog --event github.pull_request --sample > pr-event.json
autoheal triggers dry-run -f trigger.yaml --event pr-event.json
autoheal triggers create -f trigger.yaml
See the Trigger reference.