Skip to content
TriedDocs
Conversation flow

Code node

Run JavaScript at a fixed step of a flow without an LLM call, store result fields as variables, and branch on them with equations.

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#

  1. Add a Code node.
  2. Write the JavaScript. It is the body of an async function; return a value.
  3. Under Store result fields as variables, write one mapping per line in the form variable = $.path.
  4. Optional: write an Instruction to speak while it runs (set speak_during_execution through the API to enable it).
  5. 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 = $.open

Then 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#

  1. If speak_during_execution is on, the node speaks its instruction.
  2. The code runs (default timeout 10 s, at most 60 s).
  3. Values at the JSON paths in response_variables are saved as collected variables. Booleans are stored as true or false.
  4. 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.