# Workflow template format

> The alaskan.workflow JSON format. A trigger, nodes (app, search, news, page, computer, think, decide, write, wait, branch) and edges, with at least one Decide.

Canonical: https://alaskanlabs.com/docs/workflow-templates

A workflow template is one JSON file, `workflows/<slug>.json`, with `kind: "alaskan.workflow"`: a trigger and a graph of nodes. A run walks the graph from the node nothing points to, writing one step of a session per node, and follows one edge at a time.

```json
{
  "kind": "alaskan.workflow", "version": 1, "slug": "new-lead-intro", "name": "New-lead intro, with approval",
  "summary": "…", "for": "Outbound and sales teams", "dog": "kodiak",
  "trigger": { "type": "event", "event": "crm.lead.created" },
  "nodes": [
    { "id": "lead", "type": "app", "title": "Read the new lead", "app": "hubspot", "action": "HUBSPOT_LIST_CONTACTS", "input": { "limit": 1 } },
    { "id": "draft", "type": "think", "title": "Draft the intro", "prompt": "Write a first email …" },
    { "id": "approve", "type": "decide", "kind": "send", "title": "Send this intro?", "prompt": "{{draft}}",
      "options": [{ "key": "send", "label": "Send it" }, { "key": "skip", "label": "Don't send", "effect": "decline" }] },
    { "id": "send", "type": "app", "title": "Send the intro", "app": "gmail", "action": "GMAIL_SEND_EMAIL", "write": true, "input": { "body": "{{draft}}" } },
    { "id": "skipped", "type": "write", "title": "Mark the lead as skipped" }
  ],
  "edges": [["lead", "draft"], ["draft", "approve"], ["approve", "send", "send"], ["approve", "skipped", "skip"]]
}
```

## The shape

```
WorkflowTemplate { kind: "alaskan.workflow", version: 1, slug, name, summary, for?, author?,
                   license?, dog, trigger: {type: "schedule" | "event" | "manual", when?, event?},
                   nodes: [{id, type, title, app?, action?, write?, input?, prompt?, query?,
                   url?, kind?, options?: [{key, label, effect?}]}],
                   edges: [[from, to, when?]] }
```

## Who runs it

`dog` is the key of the dog that runs it. In a team without that dog, the lead runs it.

## Triggers

- `schedule`, with `when` (`weekdays 07:30`, `mon,thu 09:00`; see [the when format](/docs/team-templates#when)),
- `event`, with `event` (`crm.lead.created`),
- `manual`.

In version 1 every workflow can be run by hand. Schedules and events are recorded for what comes next.

## Nodes

Each node has an `id`, a `type` and a `title`.

| Type | What it does |
|---|---|
| `app` | An action in a connected app (`app` slug, `action` slug, `input`). A read runs when the app is connected. Anything that changes the app is marked `"write": true` and runs only after a `decide` in the same run was approved. |
| `search`, `news` | A web or news search (`query`). |
| `page` | Reads a page (`url`). |
| `computer` | A browser task on the dog's screen, in plain words. |
| `think` | The model turns what the run has so far into the next thing (`prompt`). |
| `decide` | An approval gate. It becomes a card in [Decide](/docs/decide) with these `options` (1 to 4, each `key` and `label`, optional `effect: "decline"`), and the run waits. `kind` and `prompt` (the card's summary) are optional. |
| `write` | Records the result with the session. |
| `wait` | A pause. |
| `branch` | Leaves by the edge whose `when` is `found` (the step before produced something) or `empty`. |

Every workflow has at least one `decide`.

## Edges

`[from, to]` or `[from, to, when]`. Out of a `decide`, `when` is the chosen option's key (or its number, 1 to 4). Out of a `branch`, it's `found` or `empty`. There are no loops, so a run always ends.

When a decision is made and its 10-second undo has passed, the run carries on along the edge for the chosen option. A typed answer, an expiry or an undone rule ends the run.

## Text in prompts and inputs

`{{company}}`, `{{today}}`, `{{dog}}`, `{{last}}` (the step before) and `{{<node id>}}` (that step's output).

## When something isn't connected

Anything the server can't do (no lookups, no model key, an app that isn't connected, the computer in demo mode) is simulated, and the step says so in the session: "Simulated: …". A run never pretends.

## Examples

All eight starter workflows are in [Workflow templates](/workflows), each with its graph and its JSON: [Invoice chase](/workflows/invoice-chase), [Morning inbox triage](/workflows/morning-inbox-triage), [New-lead intro](/workflows/new-lead-intro).
