# Workflows

Source: https://langbot.app/docs/en/usage/workflows

Handle messages, commands, schedules and platform events with fixed steps, without writing a plugin.

A workflow is a processor next to Chats, Agents and plugin processors. When a message (or a command, schedule, platform event or webhook) arrives, it runs the steps you arranged: classify, call a model or an API, remember something, then reply. Many things that used to need a plugin, such as weather lookups, daily fortunes, keyword alerts, scheduled pushes, welcome messages and sign-in leaderboards, can be built as workflows.

## Create a workflow

1. Open **Processors**, click **Create** and choose **Workflow**.
2. Start from a template: **Blank**, **Route by intent**, **Keyword reply** or **Answer from an API**.
3. Build on the canvas; **Workflow settings**, **Step details** and **Test run** open from the top right. On a phone, **Workflow settings** and **Edit with AI** are in the **More** menu.

## Build and edit with AI

Describe what you need; the Workspace assistant drafts the steps and saves them once you confirm.

- **Create**: choose **Ask assistant** at the bottom right of the page and say "Build a workflow that welcomes new group members", or choose **Describe it to AI** in an empty workflow. The assistant first creates an empty, disabled workflow and opens it, then builds on the canvas while you watch. If you decline the result, the empty workflow stays and can be deleted.
- **Edit**: choose **Edit with AI** in a workflow and say what to change. Steps you do not mention stay as they are. The assistant works on the saved version, so save your own edits first.

The assistant checks the steps and simulates a run, then lists every step for you to confirm. For an edit, added, changed and removed steps are marked. Nothing is saved before you confirm.

- A new workflow is saved **disabled**: try it with **Test run**, then enable it. Changing a workflow in use takes effect at once; the confirmation says so.
- Passwords and tokens are never sent to the model. The assistant leaves empty secrets in **Workflow settings** for you to fill in.
- The simulated run calls no model, API or platform; it only checks that the flow holds together. Use **Test run** to see real results.
- One task runs for at most 40 rounds; choose **Continue** to go on.
- Send messages while it works to add or change something; it reads them before its next step. Stop it at any time and go on in the same conversation.
- The assistant knows which page was open and which step was selected when you sent a message, so you can say "add a check after this step". Above the input it says "Viewing: …"; the cross leaves the page out.
- In the editor of that workflow, a dashed frame appears around the canvas while the assistant builds and the draft appears step by step. The canvas cannot be used meanwhile; choose **Stop** if you need it. While it waits for your confirmation you can move and zoom, and your own edits stay; **Back to mine** shows your version. After saving, the canvas zooms to show the whole workflow.
- Give the assistant the address of a web page or a public GitHub repository, such as "Turn this repository into a workflow: <https://github.com/…>"; it reads the code before building. It opens only addresses you wrote, search results and links on pages it has read; internal addresses, private repositories and pages behind a login cannot be read.
- It can also search the web when the Workspace is connected to a LangBot account. Each search uses credits; reading pages and repositories is free.
- In its [own sandbox](https://langbot.app/docs/en/usage/sandbox/readme.md#assistant-sandbox) it can run code and work with files, and write and build a plugin that you confirm to install.
- Before suggesting a marketplace plugin it reads the README. Installing asks for your confirmation, and the plugin stays disabled until you confirm its permissions.
- When done it opens the page it worked on. Only the tab showing this conversation changes page; if that page has unsaved changes, it stays and you get a button instead.
- Rate any answer with 👍 or 👎; a 👎 can say what went wrong. Assistant conversations are kept with every step (model calls, tool calls, timing and feedback) in this instance's database, for as long as **Settings → Workspace → Assistant** says (until deleted by default). Admins can export a time range there as JSONL; the export holds every member's assistant conversations with secrets masked. Self-hosted LangBot never uploads these records; LangBot Cloud may use them to improve the assistant.

## Build on the canvas

- Every **start** is one way to trigger the workflow and leads into its own flow. One canvas can hold several starts and flows; the bar at the top left of the canvas lists them all.
- Click **Add start** for a message, platform event, command, schedule or webhook. Choosing several events adds one start per event. An event or command can have only one start; when "Groups · all events" and "Member joined" both exist, the specific one wins.
- **Solid lines** are the execution order: drag from the dot under a step to the dot above another. Dropping on an empty spot lets you pick a new step. You can also click **+** under a dot, or hover a line and click **+** to insert a step.
- **Classify** and **Condition** have one dot per branch plus **Other**. Branches and flows may lead into the same step; the run continues from whichever path it took. Loops are not allowed.
- **Colored lines** show where variables come from. Each variable has its own color, also used by the dots beside field names and in the step details. A variable used in several places shares one line that splits at a dot. Point at a line or an output to see only that variable and its name. Selecting a step highlights its lines; the toolbar can show **All variable lines**.
- To use a variable, drag an output dot onto a field of another step, or click `{ }` inside the field. Click a colored line and its cross to remove it. Gray values come from the last test run.
- **Step details** and **Test run** at the top right open and close their panes; the canvas scales with the space left. Drag the left edge of the step details to resize them.
- On a phone, pinch to zoom and drag to move; panes open below the canvas. Connect by dragging, or tap the first dot and then the second.
- In steps shared by several flows, "Current trigger" reads whichever start fired.
- The toolbar has undo, redo, **Tidy up** and zoom. Steps with problems are red; a step no start leads to never runs. A yellow mark means a variable comes from a step that some paths skip, so it is empty there.
- A selected step shows quick actions beside it: add the next step, test this flow, edit, duplicate, disconnect and delete. The cross in a field empties it.

## Triggers

Click a start to set its trigger:

| Trigger        | Notes                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Message        | In a bot's **event routes**, point `message.received` at the workflow. The bot's access rules, rate limits and output settings still apply.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| Command        | For example `/weather Beijing`. Set aliases, arguments (split by spaces, the last one takes the rest), admins only, and which bots offer it. Commands are listed in `/help` with system and plugin commands; system commands win name clashes, then plugin commands. A missing argument gets a usage reply.                                                                                                                                                                                                                                                                                                                         |
| Schedule       | Every day, on chosen weekdays, every N minutes, once, or a cron expression, in the workflow time zone. The start panel shows the next run and recent results, and can run it now or pause it. Choose the bot that sends and the chats to send to; each chat gets its own run and **Reply** goes to that chat. Each schedule start also appears under **Schedules** in the sidebar, where you can see its runs, pause it or run it now.                                                                                                                                                                                              |
| Platform event | Every standard event: messages edited, recalled or reacted to; members joining, leaving or muted and group info changes; friend requests, new and removed friends; the bot invited to, removed from or muted in a group; feedback; plus platform-specific events (such as WeCom customer service sessions). You can also choose a whole group (for example "Groups · all events"); each event shows which of your bots send it. Event fields such as the member name or request ID are outputs of the start. Also point these events at the workflow in the bot's event routes; a route lists only workflows that handle its event. |
| Webhook        | Another system `POST`s a JSON object to the generated URL; it is the "Request body" output of this start. The URL contains a secret, so keep it private.                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |

## Steps

| Group        | Step                            | Use                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ------------ | ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| AI           | Agent                           | An AI that thinks and uses tools and knowledge, set up like on the Agent page: how it runs, model, prompt, tools, knowledge. Its answer can go straight to the user (with streaming) or only to later steps, and it can answer as separate fields                                                                                                                                                                                                                                         |
| AI           | Call a processor                | Use an existing Agent, Chat, workflow or plugin processor, then go on. "Send it right away" lets it reply itself; "Only for later steps" lets you change or extend the answer first                                                                                                                                                                                                                                                                                                       |
| AI           | Single model call               | One prompt, one answer, no tools. Choose how much it thinks, if the model allows it, and turn on **Remove thinking** to keep only the answer                                                                                                                                                                                                                                                                                                                                              |
| AI           | Classify                        | Branch by what the user wants                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| AI           | Extract                         | Pull fields such as an order number or a score, with your own rules. Fields can be text, numbers (with limits), yes/no, one of several options or lists                                                                                                                                                                                                                                                                                                                                   |
| AI           | Knowledge search                | Find related passages in a knowledge base                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| AI           | Text to speech / Speech to text | Produce a voice message, or transcribe one                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| Logic & data | Condition                       | Branch on rules (contains, equals, greater than, regex…) without expressions                                                                                                                                                                                                                                                                                                                                                                                                              |
| Logic & data | Constant                        | A named text, number or yes/no for later steps. Use the same name in different branches and one later step gets whichever ran                                                                                                                                                                                                                                                                                                                                                             |
| Logic & data | Convert                         | Turn one value into another: replace by table, find a phone number, email or link, fill in when empty, replace text, split or join lists, arithmetic, rounding, current time…                                                                                                                                                                                                                                                                                                             |
| Logic & data | Random                          | Pick one, a random number, or the same pick per person per day (daily fortune)                                                                                                                                                                                                                                                                                                                                                                                                            |
| Logic & data | Remember                        | Set, add, append, remove or forget values for this run, each user, this chat, each group, each user of this bot or the whole workflow. They can expire at the end of the day or after some hours: sign-ins, daily limits, leaderboards                                                                                                                                                                                                                                                    |
| Logic & data | Chat history                    | Recent messages of this conversation or group, e.g. for summaries                                                                                                                                                                                                                                                                                                                                                                                                                         |
| Logic & data | Code                            | Python in the sandbox (up to 10 seconds); needs Box                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| Logic & data | Loop                            | Runs the steps under "Each item" once for every item of a list (an earlier result, lines of text, or a number of times), which they read as "Current item"; then the flow goes on under "After the loop", where "Results of each pass" holds what the last step of every pass produced. Up to 500 items                                                                                                                                                                                   |
| Logic & data | Wait                            | Pause for seconds, minutes or hours (up to 24 hours) before going on. Test runs do not wait                                                                                                                                                                                                                                                                                                                                                                                               |
| Logic & data | Data table                      | Add, find, update, delete or count rows of a workspace data table; see below                                                                                                                                                                                                                                                                                                                                                                                                              |
| Actions      | Reply                           | Reply to the sender, optionally with an image or voice. Quoting and @mentions follow the bot's message policy                                                                                                                                                                                                                                                                                                                                                                             |
| Actions      | Send to a chat                  | Send to a group or person through this or another bot                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| Actions      | HTTP request                    | Call an HTTP service and get the status, body and JSON. Internal addresses are blocked                                                                                                                                                                                                                                                                                                                                                                                                    |
| Actions      | Bot action                      | The same bot actions Agents use. "This message or event" needs no IDs: recall this message, mute or remove this member, accept or reject this friend request or group invite, look up the sender or this group. Every other standard platform API (messages, groups, moderation, users and friends, files) runs on the IDs you fill in, and adapter-specific actions are available too. The picker shows which of your bots support an action; the step fails where the platform lacks it |
| Actions      | Use a tool                      | Call a tool of a plugin or MCP server; its parameters follow the tool. Sending email or writing spreadsheets comes from plugins and MCP servers                                                                                                                                                                                                                                                                                                                                           |
| Actions      | Use LangBot                     | Look up or change LangBot itself: bots, Chats, Agents, knowledge bases, monitoring, storage and more, with the same operations plugins and Agents use. Adding such a step takes the permission of its operation; workspace storage is shared with plugins                                                                                                                                                                                                                                 |
| Actions      | Ask a question                  | Send buttons or a form and wait; every button is a branch, and no answer takes "Other". Platforms without buttons get a text to answer, without forms one question after another                                                                                                                                                                                                                                                                                                          |

Every step can go on when it fails, under "If it fails": its results are empty and "What went wrong" tells why. Steps that only read or compute can also be tried again up to 3 times.

## Kinds of data

A small icon beside each result tells whether it is **text**, a **number**, **yes/no**, a **list**, **details** or a **voice**. Some results, such as an HTTP response, are only **known once it runs**.

Conditions offer the comparisons that fit:

- Yes/no values are simply "is yes" or "is no", numbers compare by size, and lists by what or how much they hold.
- Values with few possibilities, such as the chat type or a category, are picked from a list.
- Dragging a variable onto a condition replaces what it compares, and the comparison follows.

A yes/no inserted into text reads as "Yes" or "No" in the Workspace's message language. HTTP requests and bot actions still receive `true` or `false`.

## Example: one reply for group and private chats

1. After **Message received**, add a **Condition** and choose "Is group chat" is yes.
2. Add a **Constant** to each branch, with "group" and "private". The second one takes the same name by itself.
3. Connect both constants to one **Reply** and insert the variable after "Hi, ".

To swap a single word, no branch is needed: **Convert** with "Replace by table" turns yes into "group" and anything else into "private".

## What an event offers

Every event comes with its own actions: accept or reject a friend request, look up or mute a member who joined. Select a start, or press **+** to add a step, to see what the events of this flow offer. They act on the event itself, need no IDs and are the same ones Agents and plugin processors use. Events that need a one-time credential, such as entering a WeCom chat, are answered with **Reply**.

While it waits for an answer, the bot handles other messages. Restarting LangBot ends the wait.

## Data tables

Data tables are tables of the workspace that workflows read and write, such as sign-ups, points or orders. Create them in the editor under **⋯ → Data tables**, or with "Manage tables" in the Data table step: every column has an ID that steps use (e.g. `user_id`), a name and a type (text, number, yes/no, date). You can also view, add, edit and delete rows there.

The **Data table** step takes a table and an action:

- **Find rows**: rows matching conditions (is, contains, greater than, is empty, ...), optionally sorted and limited. "Rows" holds them all, "First row" the first one; read a column as "First row → column". Combine with **Loop** to handle rows one by one.
- **Add a row**: a value per column; variables can be inserted.
- **Update rows / Delete rows**: at least one condition (or a row ID), so that not every row changes; an update changes only the columns you fill in.
- **Count rows**: "Count" is how many rows match.

Test runs read for real when finding and counting, and only check additions, updates and deletions without writing them. A workspace has up to 100 tables; a table has up to 50 columns and 10,000 rows.

## Version history

Each save that changes the steps, name or time zone keeps a version; the last 50 stay. Under **⋯ → Version history** in the editor you can see them and restore any one; the state it replaces stays in the history, so you can go back.

## Workflow settings

Put what changes often, such as wording, limits and recipients, into **Workflow settings** and insert it into steps as a variable. A **secret** is hidden after saving and never appears in run records or exports; use one for request headers instead of typing the key there.

## Listening along

On a bot's **Plugins** tab, add **Workflows that listen along**. They get the same events at the same time as the processor that replies, without affecting it: alerts, records, translation.

Messages one person sends in one chat are handled one after another.

## Test runs and run history

- **Test run** uses the steps currently on the canvas, including unsaved changes. Replies only show there and are not sent to any bot. Steps that ran turn green with their duration, skipped branches turn gray, and clicking a step shows its input and output.
- Messages of one test conversation belong together: remembered values and chat history carry over until you press **Clear**. Nothing outside changes by default: requests other than GET and tools are simulated unless you turn on **Really send requests and use tools**.
- With several starts, choose where to start: type text for messages and commands, edit the sample data for events, or fill in the request body for webhooks. As in Agent debugging, bot actions are simulated and never reach a platform.
- The **Runs** tab lists every run with each step's input, output and errors.
- Every real run — from a message, command, platform event, schedule, webhook or another processor — also appears in the Dashboard's execution records as a **Workflow** row (filter by processor to see one workflow); opening it takes you to the run here. Model calls of **Single model call** steps are counted in the Dashboard's model calls, and failed runs count as failures. Runs in progress, including ones waiting for an answer or at a **Wait** step, show in the **In flight** list at the bottom. Test runs are listed as debug runs.

## Managing workflows from other tools

Everything in the editor is also available to programs: the HTTP Service API (`/api/v1/workflows`), the LangBot [MCP server](https://langbot.app/docs/en/deploy/mcp-server.md) tools (`list_workflows`, `create_workflow`, `test_workflow`, `list_workflow_runs`, `list_workflow_versions`, `list_workflow_data_tables` and so on), `lbctl workflow …` commands and plugins through the Workspace API (`workflow.*` operations). They use the same permissions as the editor.

## Advanced: templates

Inserted variables look like `{{ step_id.result }}`. Remembered values are `{{ memory.user.name }}`, where the scope is `run`, `user`, `group` or `workflow`. Templates use sandboxed Jinja: `{% for item in http_1.json.items %}…{% endfor %}` formats lists, and the filters `length`, `join`, `default`, `truncate`, `date`, `random` and `json` are available.

## Limits

- A run follows one path; there is no parallel execution, and a loop runs its steps item by item. A problem in one flow does not stop the others.
- A run lasts at most 600 seconds (waiting and asking do not count) and takes at most 1,000 steps (every pass of a loop counts).
- Like a question waiting for an answer, a waiting run lets the bot handle other messages meanwhile, but it is lost when LangBot restarts; use a scheduled start for work that should happen later or regularly.
- The **Code** step needs the Box sandbox enabled on the instance.
