# Workflows

> A workflow is a versioned graph of nodes that Sommatic AI runs step by step when a trigger fires. Design it in the studio or in Git, test the draft, publish a version and follow every run.

Source: https://docs.sommatic.ai/en/workflows/ (updated 2026-11-26)

A workflow turns an event into work: an email arrives, a webhook is called or a schedule ticks, and Sommatic AI runs a
graph of nodes that classify, transform, call systems and, when the case needs a person, open a task. Every run is
recorded node by node, so you can always answer what happened, with which data and why.

Diagram: A run moves node by node: each one leaves its envelope, and the port of flow.if chooses the branch.

## How a workflow is built

A workflow is a **graph**: nodes connected by edges.

- A **node** runs one operator from the [node catalog](https://docs.sommatic.ai/en/nodes.md) (`ai.classify`, `io.http`, `flow.if`…). It has a
  `label`, a stable `node_id`, its `config` and its output **ports**.
- An **edge** connects the port of one node to the next node:
  `{ "from": { "node_id": "…", "port": "out" }, "to": { "node_id": "…" } }`.
- The first node is a **trigger**: it decides how a run starts (webhook, schedule, mailbox, queue, another workflow
  or by hand).

Nodes read data from earlier nodes with [expressions](https://docs.sommatic.ai/en/expressions.md), for example
`{{ $('Classify request').item.json.label }}`.

## Draft, version and run

| Object              | What it is                                                                                                      |
| ------------------- | --------------------------------------------------------------------------------------------------------------- |
| **Flow definition** | The workflow you edit. Its draft (`draft_nodes`, `draft_edges`) changes every time you save.                    |
| **Flow version**    | An immutable snapshot of the draft, created when you publish. Production runs use the latest published version. |
| **Flow instance**   | One run: its status, its variables and the node it is on.                                                       |
| **Node execution**  | The record of one node inside a run: its output, port and timing.                                               |

> **Warning: Test mode runs the draft**
>
> A webhook called in `test` mode runs the **draft**, not the published version. Saving a draft changes what test
> calls execute immediately. Use `prod` mode for traffic that must only see published versions.

## How a run moves

Sommatic AI's engine runs the graph one node at a time:

1. The trigger creates the instance and its input becomes `$json` for the first node.
2. The engine runs the current node. The node returns an **envelope**: `{ ok, data, port, meta? }`.
3. The `port` picks the edge to follow (`out` by default; `true`/`false` in `flow.if`; `error` when something fails).
4. The instance state is saved after every node, so a run can be inspected and resumed.

A run stops when no edge leaves the chosen port. One tick runs at most **100 steps**, a ceiling that protects you
from accidental loops.

## Next steps

- [Quickstart](https://docs.sommatic.ai/en/get-started/quickstart.md): Build, test and publish your first workflow in the portal.
- [Triggers](https://docs.sommatic.ai/en/workflows/triggers.md): Webhooks, schedules, mailboxes, queues and sub-workflows.
- [Expressions](https://docs.sommatic.ai/en/expressions.md): Read the output of any earlier node.
- [Workflows as code](https://docs.sommatic.ai/en/git-sync.md): Keep workflows in Git and deploy them with pull requests.
