The Code node (type: "code") runs JavaScript in the same sandbox as the code tool as soon as the flow reaches it. There is no LLM call for arguments: the code reads dynamic variables directly. Use it to compute values (a quote, an age, a business-hours check) and route on the result.
Configure#
- Add a Code node.
- Write the JavaScript. It is the body of an async function;
returna value. - Under Store result fields as variables, write one mapping per line in the form
variable = $.path. - Optional: write an Instruction to speak while it runs (set
speak_during_executionthrough the API to enable it). - Add equation transitions on the stored variables. New code nodes start with no transitions and an Else edge.
// args, dv (dynamic variables) and metadata are in scope
const hour = Number(dv.current_hour);
const open = hour >= 8 && hour < 18;
return { open, message: open ? "We are open" : "We are closed" };is_open = $.openThen add an equation transition {{is_open}} == true to the open path and connect Else to the closed path.
What is in scope#
| Name | Contents |
|---|---|
dv |
All dynamic variables as strings, including system variables such as current_hour and collected values |
metadata |
The call's metadata |
args |
Always {} in a code node |
fetch |
Guarded HTTP, as in the code tool |
How it runs#
- If
speak_during_executionis on, the node speaks its instruction. - The code runs (default timeout 10 s, at most 60 s).
- Values at the JSON paths in
response_variablesare saved as collected variables. Booleans are stored astrueorfalse. - Equation transitions, then prompt transitions and global nodes (separate LLM call), then the else edge are evaluated.
If the code throws or times out, no variables are saved and the transitions are evaluated anyway, so give the else edge a safe destination.
Fields#
| Field | Type | Description |
|---|---|---|
type |
"code" |
|
code |
string, up to 20,000 characters | |
timeout_ms |
integer, 1,000 to 60,000 | Default 10,000 at runtime |
response_variables |
object of name to JSON path | |
speak_during_execution |
boolean | Speak the instruction first |
instruction |
{type, text} |
Optional |
edges, else_edge |
Limits#
The sandbox limits are listed on the code tool page: QuickJS, 32 MB memory, fetch to public addresses only, 15,000-character result.