Skip to main content

Automations

An automation does something when a thing changes, a call arrives, a time comes or a file arrives. Open Agents, then Automations. The list shows every watch, webhook, event, schedule and file trigger, and every workflow, with the shape of its steps. The switch of a row turns the automation on or off at once, and the word beside it says which. A row shows Last run failed only when its last run failed or was blocked, and Can change things on its own only when it holds permissions to act. The history of runs is below the list. The old addresses /app/triggers, /app/triggers/{id} and /app/triggers/{id}/edit open the list and the editor. With no automation yet, the list offers templates that use no add-on (a morning plan on a schedule, new files in a folder, requests from a form); Use this opens the wizard with the start and the instructions filled in.

Create an automation

Select New automation and answer in order.

  1. When it happens. Something changes (an add-on that reports changes), a call arrives (a webhook), a time, or a file arrives.
  2. Data it receives. The fields that the start gives. For a webhook, paste a sample, add fields by hand, or send a test request after you save.
  3. Only when… Typed conditions on those fields, including RE2 patterns. These apply to a webhook and to add-on events. Schedules and files have none. See Only when.
  4. What to do. Ask an agent, or, for a change of an item with a time, remind you (see Watches and reminders), or Run several steps: the editor opens after you save, with the start and the agent you chose as the first step. A new workflow is off until you turn it on.

An event of an add-on can need choices before it can start anything, such as the connection to read and a folder. The wizard asks for them under When it happens, from what the add-on declares; lists that come from your account, such as folders, are read after you choose the connection. A watched event takes one event type. The Start step of the editor shows the same choices.

More settings holds four groups: how often it may run (the daily limit, the longest run, the gap between runs), what it may do on its own (the permissions), where the answer goes, and the files and the Home widget it uses.

Edit an automation

Every automation opens in the editor, from a one-step watch, webhook, schedule or file to a workflow of many steps. Graph is the default view. Form shows the same automation as the wizard does. Runs lists its runs.

In the graph, each step shows the fields it takes on its left and the fields it gives on its right. Select a step to see them in the panel, each with its type, its description and an example.

A watch with steps keeps the reminders it set, and they work as before. A new item runs the steps instead of a chat with the model. When an item only moves to another time, the watch moves its reminder and the steps do not run, unless Also run when only the time moves is on in the Start step ("moved": true in the config of the start step).

  • Connect a field. Drag from a field on the right of a step to a field on the left of another, or choose Use a field from… in the panel. The list has every field inside the outputs too, such as the address inside the sender, and a field of the items of a list gives the list of those values. Another field… takes a path that the step does not declare, such as a field of the answer of a tool; after a test run of that step, its fields are in the list, with examples. A line with no field (from the diamond at the right of a step) only runs a step after another one.
  • Add step. An agent, a tool of an add-on, Paths, Filter, Send message or Send to Inbox. A text with {name} takes a field of that name.
  • Arguments of a tool. The panel of an add-on step lists the arguments of its tool. Type a value to set it in the step; leave it empty to connect a field of an earlier step to it. A text with {name} mixes fixed words with a field: each {name} is an input you connect.
  • Step name. A step of a workflow can have its own name, shown on the graph and in the runs.
  • Paths. One card for each path with its conditions, and Anything else. The run follows the first path that matches; Follow every path that matches is in the advanced settings of the step. The fields the conditions read are connected for you from the steps before it.
  • Filter. The run goes on only when the conditions hold, with the operators of Only when, patterns included. With Items of a list, it keeps the items that match and gives them on, with their count. A field that the steps before do not declare can be typed.
  • Run once for each item. A step runs once for each item of a list it takes, with a limit, the number at a time, and what happens when one item fails.
  • Test this step. Runs only that step, with the data of its last run or the examples of its fields. A step that would change something only says what it would do.
  • Problems. The panel of the automation lists what must be fixed before it can be turned on. Select a problem to open its step.

The panel of the automation also sets how long a run may take (one hour by default), how many steps run at the same time (four by default) and how long the details of each run are kept (24 hours by default for a new workflow).

Approvals are optional and off by default: a step runs without asking anyone, also when it can send or delete. To approve a step before it runs, turn on Ask before it runs under Before it runs and choose who is asked (you, or anyone in the project of the automation), how long the run waits (1 hour to 3 days), what happens if nobody answers (the step does not run, or the run stops and tells you), a message, whether the person may edit before approving, and, for a step that asks before it starts, an If rejected output that carries the reason on. Then the step shows Asks you first. A run that waits for you shows Waiting for you on its step. What a step may do is still limited by its permissions, the approved channels and the send limit.

When a step can send or delete, may read what other people write (mail, webhook calls, data of an add-on) and does not ask first, the editor warns you. It suggests a Filter step before it, or its approval. The warning does not stop you from turning the automation on.

An agent step reads only, unless you let it act through one of its add-ons. With that permission the agent acts without asking, unless you turn on the approval of the step: then each call of the agent that may send or delete waits for an approval in your Inbox, and a rejected call ends the step.

An agent step can send messages itself to the channels you approved. When the start reads what other people write (a webhook, mail, the items an add-on watches) or the agent can read it with the tools of its add-ons, the editor warns that this text could steer what the agent sends. A Send message step is safer.

When you save a one-step automation, it stays a trigger. When you add steps, it becomes a workflow of the same trigger, in one save. If the automation is on, the steps are saved only when they have no problems, and they take over turned on; until then the automation keeps working as it was. If you later turn the steps off, or a change gives them a problem, each start of the trigger is skipped, and the editor says so.

Test run starts a run at once. The run opens in Runs, lit on the graph or as a table, and it updates while it runs.

Webhooks

Choose who will call: a repository webhook, a script that sends a bearer secret, or a sender that signs with a timestamp. The choice changes only the setup help. The server accepts all three schemes. Let LocalAI make the secret, or paste one from the sender (at least 16 characters). The address and a made secret appear after you save.

The sender must be able to reach this server. A service on the public internet cannot call a LocalAI that is only on your home network. That needs a public address, such as a tunnel or a reverse proxy with HTTPS.

Events that LocalAI checks for

Some events happen outside LocalAI, such as a new mail. For these, LocalAI asks the add-on at intervals. The start of such an automation needs the choices that the event declares, for example a connection and a folder.

  • Interval. At most once a minute for each source, and not more often than the add-on declares. An administrator can set a longer interval with --automations-poll-interval (LOCALAI_AUTOMATIONS_POLL_INTERVAL). Automations with the same event, connection and choices share one check.
  • No backlog. The first check after you turn an automation on only notes where the source is now. Nothing that happened before, or while it was off, starts it.
  • Limits. One check returns at most 50 events. One person takes at most 200 polled events in an hour. LocalAI skips the rest and puts one notice in the Inbox.
  • Failures. After three checks in a row fail, or at once when a connection must be connected again, the Inbox says so. LocalAI waits longer after each failure, up to one hour, and respects a wait that the service asks for. The Inbox also says when a source lost its place and events may be missing.
  • Permissions. The add-on needs the grant to report changes (events.emit), and the person needs access to add-ons and to the connection.
  • Where it runs. See Several frontends.

Import and export

Export, in the menu of the editor, saves one automation as a JSON file (localai.automation/1): its start, its conditions and its steps. Import, on the Automations page, makes a new automation from such a file.

The file never holds a secret, a sample, a run, a permission, a delivery channel, a project, an approver or a connection. A step that sends a message loses its connection and channel, an agent step loses its permission to send, and an add-on argument whose name looks like a credential is left out. Your instructions, conditions and other fixed values are in the file as you typed them, so read it before you share it.

An imported automation is always off. Agents are matched by name. The import names the agents and add-ons that this account does not have. A watched event asks for its connection and other choices again. A webhook gets a new address and secret. Give the permissions again before you turn it on. A file is at most 256 KiB, and the import applies the same rules to a file that was written by hand.

Administrators

The administrator page of chats lists the triggers and the workflows of every person with their owner. An administrator can read the status and time of their runs, switch one off and delete it. Deleting a workflow also deletes its runs and the trigger that starts it, and deleting a trigger deletes the workflow that it starts. The page shows no instructions, step arguments or received data of a workflow.

Several frontends

  • Single runner. One frontend leads the triggers. It alone starts scheduled runs, advances workflow runs and checks the sources of watched events. The positions, triggers, workflows and runs are in the database, so another frontend goes on from there when the leader changes.
  • Checks need add-ons on the leader. A check of a watched event runs only on a leading frontend that runs the add-ons itself. When the leader does not (for example --addons-role frontend), nothing is checked and no notice is made.
  • Zero retention. A run started at zero retention keeps its metadata only. The outputs of its steps are in the memory of the leader, so a restart or a change of leader fails such a run.
  • Limits per frontend. The webhook limit of 60 calls a minute applies to each frontend. The limit of 200 polled events an hour and the one-minute cache of folder and label lists are in memory, and start empty on a new leader or another frontend.

API

GET /api/chats/automations is the list. An automation with steps shows as on only when its trigger and its workflow are both on. GET /api/chats/automations/catalog is what an automation can be built from. It lists only the add-ons you may use, with your connections as the choices of a connection. Its limits are the bounds the server checks on a step: max_retries (3) and each_cap (50 items). POST /api/chats/automations/catalog/describe lists the choices that an add-on reads from your account, such as folders. A trigger of an event takes these choices in setup. GET /api/chats/triggers/{id}/export and GET /api/chats/workflows/{id}/export give the file, and POST /api/chats/automations/import takes {"file": {...}, "setup": {...}}. Administrators use /api/chats/admin/workflows (list, {id}/runs, {id}/disable, DELETE {id}) beside /api/chats/admin/triggers. Create and change automations with the trigger routes (/api/chats/triggers), and their steps with the workflows API.