# Workflows

> Automate multi-step backend work that runs on a schedule, when data changes, when people sign up, or when another service calls it.


A workflow is a **trigger** plus **steps**. Describe what should happen in the chat, for example *"When a new lead signs up, email them a welcome, wait 2 days, and follow up if they haven't booked a call"*, and Draftship builds it. Each workflow is a file in `draftship/workflows/` and appears in **Dashboard → Workflows** as a diagram.

Workflows replace [automations](/docs/logic/automations) for new work. Apps that already have automations keep them.

## Triggers

| Trigger | Starts when | Example |
|---|---|---|
| Schedule | every N minutes (at least 5), at a time of day (in your time zone, optionally on certain weekdays), or once at a date and time | "Every morning at 8:00, email me yesterday's orders" |
| Data change | a record is created, updated or deleted, optionally only when a condition holds, like "status changed to shipped" | "When an order ships, email the customer" |
| Sign-up / sign-in | someone creates an account in your app or signs in | "Welcome new users and add them to my newsletter" |
| Agent chat | someone starts a conversation with one of your [AI agents](/docs/logic/ai-agents) | "Email me when someone starts a support chat" |
| Publish | a new version of your app goes live | "Post in Slack when I publish" |
| Webhook | another service POSTs to the workflow's secret URL | "When Stripe sends a payment, mark the order as paid" |
| Manual | only when you click **Run now** | |

## Steps

| Step | Does |
|---|---|
| Backend function | runs one of your app's [backend functions](/docs/logic/backend-functions) with the trigger data; its answer is available to later steps |
| Email | sends an email ([needs email set up](/docs/logic/sending-emails)) |
| Create / update record | writes to your data |
| Ask AI | asks the AI, optionally for structured data like `{ "severity": "high" }` |
| Wait | pauses for seconds up to 30 days, then continues automatically, even after a restart |
| Condition | takes a "yes" or "no" path depending on the trigger data or earlier steps |

Steps can use values from the trigger and earlier steps, such as the new record's email or the AI's answer.

## Watching runs

Open a workflow to see its diagram, with a check or cross on each step of the latest run, and its run history. Click a run to see what each step received and returned, and why a step failed.

- **Run now** starts the workflow immediately. It does real work.
- **Replay** runs it again with the data of an earlier run.
- **Cancel run** stops a run that's in progress or waiting.
- The **Active** switch pauses a workflow; runs already waiting finish as planned.

Changing a workflow creates a new **version**. Runs already in progress finish on the version they started with. If you remove a workflow from the app, it's archived with its history.

A workflow never re-triggers itself when it changes the record that started it. The [testing agent](/docs/building/testing-agent) doesn't start workflows.
