Editing Flows and Loops as JSON

Read, edit, check and save a chat flow or a loop as JSON from the CLI, an agent or the API, with worked examples and where flows and loops differ.

Everything the visual editor builds is plain JSON: a list of nodes (the steps) and a list of edges (the links between them). You can read that JSON, change it, check it and save it back without opening the editor. This is how the CLI and coding agents build flows and loops.

There are two kinds of graph, and they look alike but behave differently in a few places (see "Where flows and loops differ" below):

  • A chat flow is a scripted path a chatbot follows inside a conversation: ask, look up, branch, collect, finish. See chat-flows.md.
  • A loop is an automation that runs in the background, started by an event, a schedule or by hand. See loops-and-recipes.md and loop-nodes.md.

The contract: ask for the node catalog

Never guess a node's settings. Each workspace serves the exact contract its runner follows: every node type, every key it reads, which are required, the allowed values, what each node outputs, and the rules for edges and references.

GraphCatalogCLI
Chat flowchat:flows:node_catalogoalo call chat:flows:node_catalog
Looploops:node_catalogoalo call loops:node_catalog

oalo pull also saves it as .oalo/catalog/flow.json and .oalo/catalog/loop.json, next to the files you edit. Keys marked editor are written by the visual editor for its own use (canvas position, display hints) and do nothing at run time; keep them when you round-trip a graph so the editor still lays it out.

The workflow

  1. Read the current version. For a flow, chat:bots:flows:get with the flow's id (or chat:bots:flows:list for a bot). For a loop, loops:list_for_org and pick it by name.
  2. Edit the JSON. A save replaces the whole graph (and, for a loop, the whole definition), so keep every node, edge and setting you are not changing.
  3. Check the draft before saving. chat:flows:lint with graph (and bot_id, so tool checks see that bot's tools), or loops:lint with nodes, edges and name. Nothing is saved. Fix every finding with severity error; read the warnings.
  4. Save with chat:bots:flows:upsert or loops:update (loops:create for a new loop). Send the version you read as base_version: if someone saved in between, you get conflict with the current version instead of overwriting their work. Send strict: true to have the save refused while any error-level finding remains.
  5. Test it. For a flow, a test conversation (oalo run bot <id> "<msg>"). For a loop, oalo loops test <name> --input '<event>' runs its steps with sends simulated (an app-called loop takes {"type": "api", "payload": {...}}). oalo run loop <name> runs it for real: its messages go out. To check the trigger too, oalo emit <event> --dry-run lists the loops that event would fire; without --dry-run it fires them for real (admins and members with Developer access only).

From the CLI: pull, edit, lint, push

The CLI runs these steps on files in your project:

oalo pull flows --bot <bot id> --name <flow>   # or: oalo pull loops --name <loop>
# edit .oalo/flows/<bot>/<flow>.json or .oalo/loops/<loop>.json
oalo lint      # checks the edited files; nothing is saved
oalo push      # lints, then saves every edited file
oalo status    # clean, modified, behind or conflict, per file
  • Edit the flow part of a flow file, or loop and triggers in a loop file. version and base_hash are the CLI's: push sends version as base_version, and the hash tells your edits apart from the server moving on.
  • oalo push saves with strict on, so an error-level finding refuses the save (refused: 1 error(s)). --no-strict saves anyway, but a graph that is broken as a graph is still refused.
  • A conflict (someone saved since your pull) saves nothing. Their version is written beside yours as <name>.server.json: copy your change into it, move it over your file, and push again. oalo push --force skips the version check and overwrites their change.
  • Going back. Oalo keeps no versions of a flow or a loop, so keep the folder in git. Restore the old file (git checkout <commit> -- <file>) and run oalo push <file> --force. A plain oalo push counts the restored file as unchanged and pushes nothing.
  • After a save the file is rewritten with the new version. Pushing a copy kept outside .oalo/ updates that copy too, and leaves a .oalo/ copy that has edits of its own as it is.

What a save refuses, and what it only reports

Every save, from any client, refuses a graph that is broken as a graph: not an object, a node with no id or type, a node type the runner doesn't know, or a node or edge that isn't an object. The reply has code invalid_graph and the findings.

Everything else (a missing setting, an edge to a node that doesn't exist, a condition that can never match) is a lint finding. Without strict the save goes through, because the visual editor saves half-built steps as you work. With strict: true any finding of severity error blocks the save.

Example: a chat flow

A flow that asks for an order number, looks the order up with a tool, and answers either way. The tool find_order must be on the bot's tool list.

{
  "entry": "ask",
  "nodes": [
    {"id": "ask", "type": "collect",
     "prompt": "What's your order number?",
     "fields": [{"key": "order_number", "label": "Order number", "type": "text", "required": true}]},
    {"id": "lookup", "type": "computation", "tool_name": "find_order",
     "args": {"number": "{{ask.order_number}}"}},
    {"id": "found", "type": "output",
     "text": "Order {{lookup.number}} is {{lookup.status}}."},
    {"id": "missing", "type": "output",
     "text": "I couldn't find order {{ask.order_number}}. Could you check the number?"}
  ],
  "edges": [
    {"from": "ask", "to": "lookup"},
    {"from": "lookup", "to": "found", "condition": "found == true"},
    {"from": "lookup", "to": "missing"}
  ]
}

Things to notice:

  • entry names the first step. A flow without it never starts.
  • Steps read earlier results as {{<node id>.<field>}}, the same syntax loops use. The older {{state.<node id>.<field>}} form still works.
  • An edge condition reads the source step's own output with no prefix (found == true, not state.lookup.found == true).
  • lookup has two outgoing edges, so the conditional one is tried first and the edge without a condition is the default.
  • A single outgoing edge is always followed; a condition on it is ignored.

Example: a loop

A loop that, when a form is submitted, writes a short summary into the conversation and leaves a follow-up in the inbox for the team. It is saved off, as new work should be, until the person turns it on.

{
  "name": "form_follow_up",
  "enabled": false,
  "nodes": [
    {"id": "summarise", "type": "agent_prompt",
     "prompt": "Summarise this form submission in two sentences."},
    {"id": "note", "type": "add_suggestion",
     "params": {"title": "Follow up on a form submission", "body": "{{summarise}}", "kind": "note"}}
  ],
  "edges": [
    {"from": "summarise", "to": "note"}
  ]
}

Then start it on the event with a trigger: loops:triggers:add {"name": "form_follow_up", "type": "event", "event": "form.submitted"} (loops:triggers:catalog lists the events).

Things to notice:

  • There is no entry, so the loop starts at the first node in nodes that no edge points to. Set entry to start somewhere else.
  • Action steps keep their settings inside params.
  • A text agent_prompt output is the text itself, so it is read as {{summarise}}, not {{summarise.text}}.
  • An agent_prompt sees its input (here, the event) appended to the prompt unless the prompt already uses {{input.
  • {{input}} is the previous step's output. The event that started the run is {{trigger}} everywhere ({{loop.input}} is the same value), with the event data under payload. Use a whole value like {{trigger.payload.email}}: an object dropped into the middle of a sentence is not rendered as JSON.

Where flows and loops differ

Chat flowLoop
Where nodes livegraph.nodes, graph.edgesnodes, edges at the top level
First stepgraph.entry (required)entry if set, else the first node no edge points to
Reading an earlier step{{<id>.<field>}}{{<id>.<field>}}
The previous step's outputvia {{<id>...}}{{input}}
Several conditions matchthe first match winsevery match is followed
No condition matches, no defaultthe flow ends quietly (a branch fails)the run fails
One outgoing edge with a conditionfollowed, condition ignoredcondition evaluated
Action settingstop-level keys on the nodeinside params
inspect_video failure defaultroute (continue with _ok: false)halt

Common mistakes

  • Sending a partial graph. A save replaces what is stored. Read, change, send the whole thing.
  • Forgetting base_version. Without it there is no conflict check and a concurrent edit is lost.
  • A state. prefix in an edge condition. Conditions read the source step's output directly.
  • Naming a step after a reserved name. input, loop, trigger, user, contact, session, channel, item, doc, org_file, state and any for_each item name are scopes, so {{contact.email}} never reads a step called contact. Lint warns about such ids.
  • Reading {{contact.*}} after a step made the contact. In a chat flow, contact (id, name, email, phone and its custom fields) is the contact linked when the flow started. A contact a step creates or links during the flow is read from that step's output (its contact_id).
  • Misspelled keys. The runner ignores keys it doesn't know, so a typo like promt silently does nothing. Lint reports unknown keys at info level, which oalo lint and oalo push show only with --verbose.
  • for_each on a step that can't repeat. The catalog marks which types can.
  • Ignoring failed items under for_each. A repeated step whose items fail still continues. Its output carries _ok, error_count and errors, so route on error_count > 0, or set for_each_on_error: "halt" to fail the run when every item failed.
Try it on your own Base

Sign up, install the CLI, and deploy your repo in a few minutes.

bring your repo