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

# Routines and triggers

> What starts Software Factory work: board events, failed CI, schedules and Slack mentions, and how these differ from standalone gateway runs.

> [!NOTE]
>
> **Early Access.** Commands and behavior can change between releases.

A Factory starts work when an event matches one of its **triggers**. A trigger is one entry in the
`triggers:` list of `factory.yaml`: a `name`, an `on` that matches an event, and a `run` that says
what to start. `run` is either a **stage**, which starts a staged Factory run, or a **command**, which starts a
Factory command run: one agent runs that command once, in one session.

| Event | What it starts |
| - | - |
| A pickup label, an assignment or a status change on a board item | A Factory run at `plan`, for an eligible item. |
| CI fails on a pull request branch | On a branch this Factory owns, the owning sub-item goes back to build. On another unowned branch, a matching trigger can start a new run at `plan`. |
| A schedule comes due, or you fire it | A **routine**: a Factory command run of its command. It skips plan, build, review and land and their gates. |
| The Mutagent app is mentioned in a configured Slack channel | A Factory command run of the configured command. |

With no `triggers` key, the defaults start a run on each pickup label and on an assignment to the
Factory, and handle failed CI on Factory branches. Triggers only start work: after that, a run moves
from stage to stage on its own and waits for you at its gates.

> [card] [Triggers and routines](https://docs.mutagent.io/factory/triggers.md)
>
> Every event, the defaults, how stages chain, and how to test a trigger.

## Routines

A routine is a `source: schedule` trigger. Each time it fires, on schedule or because you fired it,
the Factory records one command run: one agent runs the command once, in one session. The run
skips the staged pipeline and its approval gates, but it is a Factory run like any other, with its
own run record.

```yaml theme={null}
triggers:
  - name: weekly-arch-review
    on:
      source: schedule
      cron: '0 8 * * 1'  # Mon 08:00
      tz: Europe/Berlin
    run:
      command: /arch-review
      agent: architect
```

Push the file to create or change a routine. To run it now, outside its schedule:

```bash theme={null}
architech factory triggers fire weekly-arch-review --json
```

A schedule trigger's `run.notify` names where the result is posted; Slack is the supported target.
See the [trigger reference](https://docs.mutagent.io/factory/reference/factory-yaml.md#triggers).

## Slack

With Slack connected to your workspace and the Mutagent app invited to a channel:

* **Start work.** A Factory Slack trigger (`source: slack`, `event: mention`) runs its command when
  someone mentions the app in that channel, on the repository the trigger names.
* **Get updates.** A routine's result can be posted to Slack with `run.notify`, and a question the
  Factory posts to Slack is answered in that question's thread.

> [card] [Slack triggers](https://docs.mutagent.io/factory/triggers.md#slack-channel)
>
> Configure a Factory-managed Slack trigger.

> [card] [Connect Slack](https://docs.mutagent.io/integrations/slack.md)
>
> Add the Mutagent Slack app to your workspace.

## In the web app

**Routines** lists your Factory's routines, what is running now and their recent runs. **Triggers**
shows the event triggers from `factory.yaml`, their health and their recent runs.

## Factory triggers and gateway triggers

The [`mutagent gateway`](https://docs.mutagent.io/cli/commands/gateway) commands create a different kind of trigger and
routine: each one starts a single session in a cloud sandbox with an instruction you write. It
creates no Factory run and passes no gate. A Factory routine or other command trigger creates a
Factory command run, and a stage trigger starts a staged run, except failed CI on a branch one of
this Factory's runs owns: that sends the run's sub-item back to build instead of starting a new run.
Use a stage trigger for work that should go through plan, build, review and land. Two enabled triggers can't claim the same Slack channel, so pick one kind
per channel.


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