create_variable declares a named value with a type; set_variable updates one later in the pipeline. There are four types: string, number, boolean (collectively "scalar"), entity, and collection.
Scalar (string / number / boolean)
A single typed value. If you don't give an initial value, it defaults to that type's zero-value (empty string, 0, or false). Reference it downstream as {{myVar}}.
Entity
Holds one record — or null. The initial value must be an object (typically a {{step}} reference to a get_entity/create_entity output, or a literal record); anything else fails the step with a 400. Reference fields the same way you would off any entity step: {{myVar.fieldName}}.
Collection
Holds a list. Internally it's { items: [...], count, entityName?, scalarType? } — the same shape list_entities and an ai_call with outputFormat: list produce, which is why formulas and loops can treat all three interchangeably.
- Entity collection —
entityNameis set, items are records of that entity. - Scalar collection —
scalarTypeis set (string/number/boolean), items are plain values. - Shorthand accessors on any collection —
{{myList.count}},{{myList.first}},{{myList.last}}. - Numeric aggregates —
{{myList.min}},{{myList.max}},{{myList.avg}},{{myList.sum}}— only meaningful (and only shown in the picker) for a scalar-number collection.
These accessors are {{...}}-only — not inside a formula
{{myList.sum}} etc. are computed by the same {{...}} resolver every non-formula step config uses. Reference them directly in another step's config (a create_entity field, a connector field mapping, a webhook body). A formula's own bare refs use a different, simpler resolver that doesn't compute these — and formula's COLLECTION_AVG/MAX/MIN/FIND functions only apply to entity collections (they look up a named field on each item), not scalar collections. So a scalar-number collection has no in-formula way to aggregate it — use the {{...}} accessor from a non-formula step instead.
set_variable — updating a variable later
Targets an existing variable by name with an operation:
- `replace` — overwrite the whole value (any type).
- `add` — type-dependent: sums numbers, concatenates strings, appends an item to a collection's
items. Not valid for entity or boolean. - `clear` — resets to empty:
[]/0items for a collection,nullfor an entity.
Worked example — build a collection in a loop, then aggregate
s1: list_entities entity=order_line filters=[{field: order_id, op: eq, value: {{input.order_id}}}]
s2: create_variable name=amounts varType=collection scalarType=number
s3: loop source={{s1}} itemAs=row
s3a: set_variable target=amounts operation=add value={{row.amount}}
s4: create_entity entity=order_summary
fields=[{ order_id: {{input.order_id}} }, { total: {{amounts.sum}} }, { line_count: {{amounts.count}} }] {{amounts.sum}}/{{amounts.count}} in s4 resolve correctly because they're template refs on a non-formula step's config — the same accessor would not resolve inside a formula's own expression syntax (see the warning above).