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.mdandloop-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.
| Graph | Catalog | CLI |
|---|---|---|
| Chat flow | chat:flows:node_catalog | oalo call chat:flows:node_catalog |
| Loop | loops:node_catalog | oalo 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
- Read the current version. For a flow,
chat:bots:flows:getwith the flow'sid(orchat:bots:flows:listfor a bot). For a loop,loops:list_for_organd pick it byname. - 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.
- Check the draft before saving.
chat:flows:lintwithgraph(andbot_id, so tool checks see that bot's tools), orloops:lintwithnodes,edgesandname. Nothing is saved. Fix every finding with severityerror; read the warnings. - Save with
chat:bots:flows:upsertorloops:update(loops:createfor a new loop). Send theversionyou read asbase_version: if someone saved in between, you getconflictwith the current version instead of overwriting their work. Sendstrict: trueto have the save refused while any error-level finding remains. - 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-runlists the loops that event would fire; without--dry-runit 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
flowpart of a flow file, orloopandtriggersin a loop file.versionandbase_hashare the CLI's: push sendsversionasbase_version, and the hash tells your edits apart from the server moving on. oalo pushsaves withstricton, so an error-level finding refuses the save (refused: 1 error(s)).--no-strictsaves 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 --forceskips 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 runoalo push <file> --force. A plainoalo pushcounts 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:
entrynames 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
conditionreads the source step's own output with no prefix (found == true, notstate.lookup.found == true). lookuphas 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 innodesthat no edge points to. Setentryto start somewhere else. - Action steps keep their settings inside
params. - A text
agent_promptoutput is the text itself, so it is read as{{summarise}}, not{{summarise.text}}. - An
agent_promptsees 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 underpayload. 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 flow | Loop | |
|---|---|---|
| Where nodes live | graph.nodes, graph.edges | nodes, edges at the top level |
| First step | graph.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 output | via {{<id>...}} | {{input}} |
| Several conditions match | the first match wins | every match is followed |
| No condition matches, no default | the flow ends quietly (a branch fails) | the run fails |
| One outgoing edge with a condition | followed, condition ignored | condition evaluated |
| Action settings | top-level keys on the node | inside params |
inspect_video failure default | route (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,stateand anyfor_eachitem name are scopes, so{{contact.email}}never reads a step calledcontact. Lint warns about such ids. - Reading
{{contact.*}}after a step made the contact. In a chat flow,contact(id,name,email,phoneand 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 (itscontact_id). - Misspelled keys. The runner ignores keys it doesn't know, so a typo like
promtsilently does nothing. Lint reports unknown keys at info level, whichoalo lintandoalo pushshow only with--verbose. for_eachon 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_countanderrors, so route onerror_count > 0, or setfor_each_on_error: "halt"to fail the run when every item failed.
Sign up, install the CLI, and deploy your repo in a few minutes.