Skip to main content

Workflows

A workflow is an automation with steps. A start gives the received data, and each step takes typed fields from the steps before it: an agent works on them, an add-on tool reads or changes something, paths choose where the run goes, a message goes to a chat app, a row goes to your Inbox. A workflow runs where the triggers run, so it needs the triggers feature, and the server option that turns the triggers off turns the workflows off too.

This page is about the API. For a run that is one chat, see Triggers and Event triggers.

Start

A workflow starts in one of two ways.

  • From a trigger. Set trigger_id to one of your triggers. While the workflow is on, each run of the trigger starts the workflow instead of a chat. The trigger keeps its own guards: its schedule, its matches, its gap and its daily limit. A trigger starts at most one workflow. While the workflow is off, the runs of the trigger are skipped.
  • By hand. POST /api/chats/workflows/{id}/run with {"input": {...}}. This works also while the workflow is off.

The received data is one JSON object:

StartReceived data
An event of an add-onThe fields of the event, as the automations catalog lists them.
A webhookThe JSON object of the call, from the whole body. A form (application/x-www-form-urlencoded) comes as an object of its fields, another JSON value as {"body": value}, a text that is not JSON as {"body": text}. An object over 256 KiB is cut to the first 8000 bytes of the body, and so are the events that are merged into a waiting run. A step can take the fields you set on the webhook: a field inside another (contact.email) is given as its record (contact).
A schedule{"time", "schedule"}
A file{"path", "name"}
By handThe input of the request.

Steps

A workflow has at most 200 steps and 1000 links. Each step has an id, a kind, a config and its place on the canvas (x, y). A link joins an output (from, field) to an input (to, input). A link without field only orders two steps. The field of a link is a dot path into the output: message.from.address takes the address inside the sender record. A path through a list of records takes the field of each item, as a list (message.to.address gives the list of addresses). Inside an output that declares no fields, such as the result of a tool that does not describe its answer, any path is accepted and the value is read when the step runs. A Paths or Filter step that tests a field inside an input (people.address) takes that input as a value of any type, so a list of records fits.

KindConfigTakesGives
start{}, or {"moved": true} for a watchnothingthe fields of the start
agent{"agent", "instructions", "send", "limit"}what the agent declares it takes, and each {name} in instructions as textwhat the agent declares it gives, or one text, answer
addon{"addon", "tool", "args"}the inputs of the tool that args does not fixresult, a record
paths{"paths": [{"id", "label", "when", "any"}], "else", "every"}the fields its conditions readone output for each path taken
filter{"when", "any", "items"}the fields its conditions read, or the input that holds the list itemspassed, what came in; with items, items (the matching items) and count
send{"connection", "channel", "text"}each {name} in textnothing
inbox{"title", "message", "attention"}each {name} in the title and the messagenothing

Filter steps

A Filter step lets the run go on only when its conditions hold. The conditions are those of “Only when” and of Paths, with the same typed operators (is, contains, matches with an RE2 pattern, the number, time and list operators, and ignore_case). When they do not hold, the step gives nothing and the steps after it are skipped: a step with a “then” line from it, a step that also has lines from other steps, and the steps after those. The same holds after a Paths step that takes no path, after a Filter or Paths step that runs for each item of an empty list, and after an agent step whose call was rejected. A path of a Paths step that is not taken skips only its own steps, so the paths can meet again. A condition can read any field, also one that no step declares, such as result.sender.address inside the answer of a tool: the value is read as its JSON kind says when the step runs.

Conditions fail closed. A missing field, a null or a value of the wrong type does not match. A condition on every item of a list (every) fails when an item lacks the field. A number is a decimal text of at most 400 characters, with an exponent of at most 400: a longer text, a fraction or a hex number is not a number.

With items, the dot path of a list (message.to, result.messages), the conditions test each item, with paths inside the item. A list of texts or numbers is tested with the path value. The step gives the matching items and their count; when no item matches, the steps after it are skipped. A Filter or Paths step that runs for each item gives null for each item it did not take; a step after it that runs for each item of that list does not run for those items.

{"id": "ours", "kind": "filter", "config": {"items": "message.to",
  "when": [{"path": "address", "type": "text", "op": "contains", "value": "@example.com", "ignore_case": true}]}}

Agent steps

An agent step runs one of your saved agents in a new chat, without a person. The chat is marked with the workflow origin, and you can open it from the run. The agent declares what it takes and gives on the agent itself (takes and gives in the agents API, at most 32 each). The inputs reach the agent as data in its first message, not as instructions.

  • An agent that declares outputs gets the tool give_result. The step ends when the agent calls it, and the outputs are checked against their types.
  • An agent that declares no outputs gives its last answer as the text answer.
  • limit is how long the agent may work: 1 hour by default, at most 24 hours. A step past its limit stops the chat and fails.

The chat of an agent step acts only within the act grants of the workflow (acts) and within the grants of the agent. When the approval of the step is on, each call of a tool that does more than read waits for a person first (see Approvals). It writes to your chat apps only when the step has send: true and the workflow holds act.send, and only to the channels you approved for the connection. The test of a step never sends.

Add-on steps

An add-on step calls one tool of an installed add-on as you, outside any chat. A tool that only reads needs no grant. A tool that writes, sends or deletes needs act.addons or act.addons:<add-on id> in acts. You can use only the add-ons that your account may use.

An argument fixed in the step is not an input: no line and no edit of an approver replaces it. A fixed text argument may hold placeholders, such as "title": "Mail from {sender}". Each placeholder is an input of its own that a link fills, and the call gets the text with the values in place. An input that only fills a placeholder is not sent to the tool.

The result of the step is the result of the tool. The step fails when the add-on refuses the call, and when the change waits for a person to confirm it on the Add-ons page (for example, a connection that is set to ask first). The step is tried again, within its retry setting, when the add-on is not running or asks to slow down. When the answer is lost, a step that changes things is tried again only if its tool says that it is idempotent.

Send message steps

A send message step writes text to an approved channel of one of your connections to a chat app. It needs act.send in acts. It uses the same checks as send_message in a chat: the server switch of the talk-back, the approved channels and the send limit. The Send message steps and the agents of one workflow share one send limit.

Turn on, test and follow

  • A new workflow is off. A workflow with problems is saved with them; turn it on when it has none. A graph that cannot be stored (a loop, a link to a step that does not exist, two steps with one id) is refused with 400 and the problems.
  • Test a step runs one step on the inputs you give, on the inputs of its last run, or on the examples of its fields. Nothing is kept. A step that would write, send or delete says what it would do instead.
  • The events of a run hold no content of the run. Read the run for the inputs and outputs of its steps, while the run keeps its details (keep_details_seconds: 0, 86400, 604800 or 2592000; 86400 by default). The run of the start trigger keeps no copy of the received data: the workflow run holds it, under this setting, and the trigger run keeps only its status and times.

Approvals

Approvals are opt-in. A step asks a person before it runs only when it has an ask setting, in any run, also one started by hand. A step without one runs unattended, also when it can send or delete; it still acts only within its permissions and the act grants of the workflow, the approved channels, the send limit and the server switch of the talk-back. No step needs an approval to be turned on.

The editor warns about a step that can send or delete, may read what other people write (a webhook, mail, data of an add-on) and has no ask setting. The warning blocks nothing. An add-on tool can say what it does (effects, see What a tool does): a tool that only changes data cannot send or delete, and a tool that declares nothing counts as one that can.

ask fieldWhat it does
whoWho may answer: owner (the default), project, or both. project is everyone with write access to the project of the workflow (project_id), through a share of that project. People with read access see the request and cannot answer it.
wait_secondsHow long the run waits for an answer. 24 hours by default.
if_no_answerWhat happens when nobody answers in time: skip (the default) skips the step, stop stops the run.
messageThe text the request shows.
can_editThe person who approves may change the inputs of the step first. A run with zero retention keeps no content, so its requests cannot be edited.
on_reject_outputThe output that a rejection takes. Without it, a rejected step is skipped.
  • The first answer counts. A request that someone answered, that timed out, or whose run ended is closed.
  • The request is in the Inbox of the owner, under Waiting for you. The people of the project see it there too. The row names the automation and the step, in the language of the page.
  • Each step says in approval whether it asks (asks), has an ask setting but the server switch lets it run (skipped), or asks nobody (none), and in risky whether it can send or delete.
  • An agent step does not ask before it starts. With an ask setting, it asks before each call of a tool that does more than read, also in a run started by hand. That is an add-on tool that acts (unless it declares effects that neither send nor delete), an MCP tool, a LocalAI client tool that runs a model, a file write (write_file, edit_file, move_file, delete_file), a command or a job. These tools do not declare what they write, so they count as tools that can send or delete. An agent step with act.files or act.spend in acts and an ask setting therefore asks. Without an ask setting these calls run at once. The call waits, the agent ends its turn, and the step waits with it. When someone approves, the agent is told to make the same call again, and that call runs once, with the arguments the approver changed when the step has can_edit. A rejected call, or one nobody answers in time, ends the step without its outputs, so the steps after it do not run; with if_no_answer: stop the step fails instead. Such a step has no on_reject_output. The time a call waits does not count against the limit of the agent. The request, its answer and the chat are stored, so a call that waits survives a restart of the server. Messages to approved channels (send: true) ask nobody.

An administrator can turn the approvals off for the whole server with --automations-skip-approvals, LOCALAI_AUTOMATIONS_SKIP_APPROVALS or the runtime setting automations_skip_approvals (off by default). Then every step runs without asking, also a step with an ask setting. Each step that runs this way is in the events of its run and in the server log, and the Automations page says that approvals are off. Use it only on a server where nobody else’s data or channels are at stake.

Method and pathWhat it does
GET /api/chats/approvalsThe requests that wait for you, oldest first, with can_answer and approvals_off.
POST /api/chats/approvals/{id}/approveApproves a request. {"edited": {...}} replaces the inputs when the step allows it.
POST /api/chats/approvals/{id}/rejectRejects a request.

A request that is already closed is 409 with the type approval_answered. Read access is 403, and a request you cannot see is 404. The approval routes need the chats feature only, so a person of a shared project can answer.

API

All routes need the triggers feature. A workflow and its runs are visible to their owner only; another person’s workflow is 404.

Method and pathWhat it does
GET /api/chats/workflowsYour workflows, with their problems.
POST /api/chats/workflowsCreates a workflow. 201 with the workflow and its problems. A new workflow is off, except one whose trigger_id names a trigger that is on: that one is turned on in the same save, or the save is 400 with its problems and nothing is stored, so the trigger never skips its events behind a workflow that is off.
POST /api/chats/workflows/checkChecks a workflow and stores nothing: the body of a create, plus id when it changes a saved workflow. 200 with the workflow as a save would see it: its problems and the approval and risky of each step. A graph that cannot be stored is 200 with fatal problems. The editor calls it while you edit.
GET /api/chats/workflows/{id}A workflow with its problems.
PUT /api/chats/workflows/{id}Saves a new version. Send the version you read; a workflow that changed meanwhile is 409.
GET /api/chats/workflows/{id}/exportThe workflow and its start as a file, see Import and export.
DELETE /api/chats/workflows/{id}Stops its runs and deletes it with them. Its trigger stays and starts a chat again. Deleting the trigger that starts a workflow deletes the workflow and its runs too.
POST /api/chats/workflows/{id}/enable, /disableTurns it on or off. A workflow with problems cannot be turned on: 400 with the problems.
POST /api/chats/workflows/{id}/runStarts a run by hand: 202 with the queued run.
POST /api/chats/workflows/{id}/steps/{step}/testTests one step: {"inputs": {...}}, or no body.
GET /api/chats/workflows/{id}/runsThe runs, newest first. limit up to 200.
GET /api/chats/workflows/runs/{rid}A run with the records of its steps.
POST /api/chats/workflows/runs/{rid}/stopStops a run and the chats of its agent steps.
GET /api/chats/workflows/runs/{rid}/eventsServer-sent events of the run, with the seq as the event id. Resume with after or Last-Event-ID. The stream ends after the last event of the run.

When the server has no workflows the routes answer 409 with the type workflows_off.

Distributed mode

The workflows, their versions, runs, step records and events are in the database, beside the triggers. Every frontend serves the API and follows the runs. One frontend advances the runs: the one that holds the leader lock of the triggers. A notice on the message bus wakes the leader and the followers when a run changes, so a run started on one frontend advances at once on the leader.

The chat of an agent step runs on the frontend that started it, never on a chat worker, so its give_result reaches the engine. A run with zero retention keeps the outputs of its steps in the memory of the leader only: a restart of the leader, or a change of leader, fails such a run instead of reading data it never wrote.