# Workflows (/luso8/workflows)

> Automate work across Luso8 with event, schedule and webhook triggers, AI agent steps, conditions and human review.

Workflows automate the work that happens between your tools and your team. A workflow starts
from a **trigger**, such as a call ending, a deal being won, a schedule or a webhook, then runs a
chain of **steps**: ask an AI agent, call an external service, wait, branch on a condition, notify
someone or pause for a person to approve.

Build them in **AI tools → Workflows**.

## Create a workflow [#create-a-workflow]

Choose **New Workflow** and pick how to start:

| Option | When to use it |
| --- | --- |
| **Describe it** | Write what you want in plain language ("when a deal is won, email the customer a welcome and create an onboarding ticket") and AI builds the first version |
| **Examples** | Start from one of the ready-made examples and adjust it |
| **Blank** | Build step by step on an empty canvas |

The workflow opens in the **Builder**: a canvas with the trigger at the top and steps below it.

## Triggers [#triggers]

| Trigger | Fires when |
| --- | --- |
| **Event** | Something happens in Luso8 (see the events below) |
| **Schedule** | On a cron schedule in your time zone, for example every weekday at 08:00 |
| **Webhook** | An external system sends a POST request to the workflow's secret URL |
| **Manual / API** | You click **Run**, an AI agent runs it, or it's triggered through the API |

### Events [#events]

| Event | Fires when |
| --- | --- |
| `call.ended` | A call finishes |
| `payment.received` | A payment link is paid |
| `deal.created` | A deal is created |
| `deal.stage_changed` | A deal moves to another stage |
| `deal.won` | A deal is closed won |
| `deal.lost` | A deal is closed lost |
| `contact.created` | A contact is added |
| `message.received` | A customer message arrives in the inbox |
| `appointment.booked` | A meeting is booked |
| `campaign.completed` | A campaign finishes |
| `connector.synced` | A data connection finishes syncing |

Each event comes with a sample payload in the builder so you can see which fields you can use.
A [campaign](/luso8/campaigns) condition branch can also start a workflow.

### Filters [#filters]

Narrow an event trigger with filters on payload fields. Use dotted keys for nested fields; a list
means "any of":

```json title="Only deals reaching proposal or closed won in Malawi"
{
  "stage": ["proposal", "closed_won"],
  "contact.country": "MW"
}
```

### Webhook trigger [#webhook-trigger]

A webhook trigger gives the workflow a secret URL. Send a JSON body to it and the body becomes the
workflow's input:

```bash
curl -X POST "https://api.luso8.rexplore.ai/api/v1/ai-workflows/hooks/<workflow_id>/<secret>" \
  -H "Content-Type: application/json" \
  -d '{"email": "jane@example.com", "plan": "pro"}'
```

Treat the URL like a password: anyone who has it can start the workflow. Only share it with
systems you trust. See
[Webhooks](/developers/webhooks) for more on sending and receiving webhooks.

## Steps [#steps]

| Step | What it does |
| --- | --- |
| **Agent** | Sends a message to one of your [AI agents](/luso8/agents) and uses its reply. The agent can act within its Luso8 access |
| **Skill** | Runs a skill from **AI tools → Skills** |
| **Connector** | Runs a sync on one of your data connections |
| **Condition** | Branches on an expression, for example a deal value or a call disposition |
| **Wait** | Pauses for a duration or until a time |
| **Webhook** | Calls an external URL with data from the run |
| **Code** | Runs a short, sandboxed Python snippet to compute a value |
| **Transform** | Reshapes data for the next step |
| **Notification** | Notifies teammates in Luso8, by email or by SMS |
| **Human review** | Pauses until an assigned teammate approves or rejects |
| **Sub-workflow** | Runs another workflow |
| **End** | Stops the run |

## Use data from earlier steps [#use-data-from-earlier-steps]

Any text field in a step can include expressions in double curly braces, such as
`{{ trigger.contact.email }}`. These names are available:

| Name | Contains |
| --- | --- |
| `trigger` | The event payload or webhook body that started the run |
| `input` | The step's input: its mapped input, else the previous step's output |
| `prev` | The previous step's output |
| `steps` | Outputs of earlier steps, by each step's output key, e.g. `steps.summary` |
| `vars` | Workflow variables |
| `review` | The last human review result: `approved` and `comment` |
| `run`, `workflow` | IDs and the workflow name |

Expressions support comparisons, `and`/`or`/`not`, arithmetic, conditionals and safe helpers such
as `len`, `round`, `sorted`, `get`, `json` and `now`. A missing field never breaks a run: it's
empty, so `{{ input.contact.email or "n/a" }}` falls back cleanly.

<Callout type="info">
A field that contains only one expression keeps its type (number, list or object). Anything mixed
with text becomes a string.
</Callout>

## Compile, activate and run [#compile-activate-and-run]

<Steps>
<Step>
### Compile [#compile]

**Compile** checks the whole workflow before anything runs: the trigger, every step's required
fields, the agents, skills and connections it references, expression syntax, loops and
unreachable steps. The builder shows **Compiles** when it's ready, or marks the steps that need
attention. After an edit it shows **Changed since compile**.
</Step>

<Step>
### Test run [#test-run]

Run the workflow once with sample input to check each step's output before going live.
</Step>

<Step>
### Activate [#activate]

Set the workflow to **Active**. Only active workflows receive triggers.
</Step>
</Steps>

## Runs [#runs]

The **Runs** tab lists every run with its trigger and status. Open a run to see each step's input,
output and any error, which makes it easy to see where something went wrong. Runs waiting on a
**Wait** or **Human review** step resume on their own when the time comes or the reviewer
answers, and you can cancel a run at any time.

## Examples [#examples]

- **Call follow-up.** On `call.ended` with a negative outcome, ask a support agent to open a
  ticket and notify the account owner.
- **Won deal onboarding.** On `deal.won`, send a welcome email, book a kickoff call and notify the
  team.
- **Daily digest.** Every weekday at 08:00, ask an agent to summarize yesterday's pipeline changes
  and email it to sales.
- **Form to CRM.** A webhook from your website form creates the contact and adds it to a nurture
  campaign.

## Related [#related]

<LinkGrid>
<LinkItem href="/luso8/agents" title="AI agents">
The agents your workflows call.
</LinkItem>

<LinkItem href="/developers/webhooks" title="Webhooks">
Trigger workflows from your systems.
</LinkItem>

<LinkItem href="/developers/api-reference" title="API reference">
Trigger and inspect workflows over the API.
</LinkItem>
</LinkGrid>