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

# Triggers and Automations

> Enable an agent, run it now, and trigger it on a schedule or from a webhook with automations

Once an agent is enabled, it can run without anyone pressing a button. People reach it through chat, channels and the Agent API; **automations** run it on a schedule or when another system calls a webhook.

| Trigger | How it starts a run | Set up in |
| - | - | - |
| **Chat** | A message in **Chat** | Nothing to set up |
| **Test run** | Runs your unpublished draft | Agent Builder |
| **Run now** | Fires a saved automation once, on demand | **Automations** tab |
| **Schedule** | Fires an automation once at a set time, or on repeat | **Automations** tab |
| **Webhook** | Fires an automation when another system POSTs to its URL | **Automations** tab |
| **Channels** | A Slack, Teams or Discord mention, an email, a Linear issue, a public chat link | [Channels](/agents/channels) |
| **Agent API** | Your code sends a message to the agent | [Agent API](/api-reference/agent-api/overview) |

***

## Enable or disable an agent

An agent runs only while it is **Enabled**. The status pill at the top of the agent page shows **Enabled** or **Disabled**; click it to switch.

* **Publishing** from the Agent Builder enables the agent.
* **Disabling** stops it everywhere: chat, API calls, public links, email, chat apps, rooms and automations. Building and **Test run** in the builder keep working. Turn it back on to resume.

Only the Admin and Builder roles can enable or disable an agent.

***

## Automations

An automation is a saved invocation of the agent: a prompt, the triggers that fire it, and where its results go. Every firing is a real run of the agent, and each run starts a new conversation.

### Create an automation

<Steps>
  <Step title="Open the Automations tab">
    On the agent page, open **Automations** and click **New Automation**.
  </Step>

  <Step title="Name it and write the prompt">
    Give it a **Name** (for example "Morning digest") and describe the task under **What should it do?**, for example: "Summarize last week's new leads and flag anything unusual."
  </Step>

  <Step title="Add triggers">
    Under **Triggers**, click **Add trigger** and pick **Scheduled** or **Webhook**. Add as many schedules as you need, plus one webhook. With no triggers, the automation runs only when someone presses **Run now**.
  </Step>

  <Step title="Choose where results go">
    Open **Advanced settings** to pick **Destinations**, and optionally the **Model**, **Run as** identity and **Max concurrent runs**. The editor summarizes the choice as **Results go to: ...**.
  </Step>

  <Step title="Save">
    Click **Create**. A webhook URL appears once the automation is saved.
  </Step>
</Steps>

| Setting | What it does |
| - | - |
| **Destinations** | Where each run's result is posted: **Web chat** (a new private conversation in your Chat list, titled after the automation) and the Teams or Discord channels the agent's chat apps operate in. See [Channels](/agents/channels). |
| **Model** | Overrides the agent's default model for this automation. Blank uses the agent's default, then the system default. An API-call model or a model pinned by the harness still takes precedence. |
| **Run as** | The API key that authenticates the run's calls back into DataGen. The key's owner is the run's identity. **Use account default** picks your default key when the run is dispatched. |
| **Max concurrent runs** | How many runs of this automation can run at once. |
| **Automation active** | When off, none of its triggers fire, whatever their own state. |

### Run now

Every automation row on the **Automations** tab has a **Run now** button that fires it once immediately. Run now is available to the Operator, Builder and Admin roles.

***

## Schedules

A **Scheduled** trigger runs the automation at set times, in the **Time zone** you choose.

| Frequency | Runs |
| - | - |
| **Once** | A single run at the **Date and time** you pick |
| **Every hour** | At the minute you pick, every hour |
| **Every day** | At the time you pick |
| **Every weekday** | Monday to Friday at the time you pick |
| **Every week** | On the day and time you pick |
| **Custom (cron)** | Any cron expression |

Custom cron examples:

| Schedule | Cron expression |
| - | - |
| Every day at 9 AM | `0 9 * * *` |
| Every Monday at 2 PM | `0 14 * * 1` |
| Weekdays at 8 AM | `0 8 * * 1-5` |
| Every 6 hours | `0 */6 * * *` |

A paused schedule shows **This schedule is paused.** with a **Resume** button.

***

## Webhooks

A **Webhook** trigger gives the automation its own URL. Any system that can send an HTTP POST can run the agent: n8n, Make, Zapier, GitHub, meeting recorders, your own apps.

The URL has this shape, and the editor shows it with a **Copy URL** button under **How to call this Automation**:

```text theme={null}
https://api.datagen.dev/api/agents/<agent-name>/automations/<automation-id>/trigger
```

### Protect the webhook

Under **API key (Bearer token)**, click **Generate** to require callers to send `Authorization: Bearer <key>`. The key is shown once; DataGen stores only a hash, so save it immediately. **Rotate** issues a new key and stops the old one at once. Without a key, anyone with the URL can fire the webhook.

**Max calls per hour** limits how often the webhook can fire.

### Use the payload in the prompt

The JSON body you POST is available to the prompt. Write `{{ payload.foo }}` in **What should it do?** to insert the request's `foo` field:

```text theme={null}
Enrich the company {{ payload.domain }} and post a summary.
```

### Call it and get the result

<Steps>
  <Step title="Trigger the run">
    ```bash theme={null}
    curl -X POST 'https://api.datagen.dev/api/agents/<agent-name>/automations/<automation-id>/trigger' \
      -H 'Authorization: Bearer <your-token>' \
      -H 'Content-Type: application/json' \
      -d '{"domain": "example.com"}'
    ```

    The response is `202 Accepted` with `{ executionId, statusUrl }`. The run starts asynchronously.
  </Step>

  <Step title="Poll for the result">
    ```bash theme={null}
    curl 'https://api.datagen.dev/api/agent/execution/<executionId>'
    ```

    Poll every 1-2 seconds until `status` is final. The agent's answer is in `result.content`:

    ```json theme={null}
    {
      "executionId": "...",
      "status": "completed",
      "result": { "content": "<the agent's final answer>" },
      "startedAt": "...",
      "completedAt": "...",
      "durationMs": 10180
    }
    ```
  </Step>
</Steps>

Click **Test fire** in the editor to POST `{}` to the URL and confirm it is queued.

<Tip>
  For a request-and-response conversation with an agent from your own code, use the [Agent API](/api-reference/agent-api/overview) instead of a webhook.
</Tip>

***

<AccordionGroup>
  <Accordion title="Older repo-run automations">
    Some older automations use the one-shot repo run, which can commit and open pull requests (**PR mode**: **Create PR**, **Auto Merge** or **Skip**). The editor shows a notice on these with a **Switch to conversation** button. New automations always run as conversations.
  </Accordion>

  <Accordion title="A schedule did not fire">
    1. Check that the agent is **Enabled**.
    2. Check that **Automation active** is on and the schedule is not paused.
    3. Check the **Time zone** on the trigger.
    4. Look for the run in [Agent Logs](/agents/versions-and-logs), filtered by the **Scheduled (Cron)** trigger.
  </Accordion>

  <Accordion title="The webhook returns an error">
    * **401**: the webhook has an API key. Send `Authorization: Bearer <key>`, or **Rotate** to get a new key if you lost it.
    * **404**: check the agent name and automation id in the URL, that **Automation active** is on, and that the automation has an active webhook trigger.
    * **429**: the webhook hit **Max calls per hour**, or you have too many queued or running runs. Retry after the time in the response.
  </Accordion>
</AccordionGroup>

## Next

<CardGroup cols={2}>
  <Card title="Channels" icon="comments" href="/agents/channels">
    Reach the agent from Slack, Teams, Discord, email, web chat and public links
  </Card>

  <Card title="Versions and Logs" icon="clock-rotate-left" href="/agents/versions-and-logs">
    Roll back a version and inspect every run
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.