Flow
Conditionally set values in your circuit memory using the Flow primitive
Introduction to Flow
The circuit.core.flow primitive evaluates one or more Boolean expressions (conditions) against the current memory state and then sets a name/value pair in the circuit’s memory depending on the result.
Use it whenever you need simple branching or state flags within a single-step circuit definition.
Step Definition
"steps": [
{
"name": "check_value",
"function": "circuit.core.flow",
"conditions": [
{ "expression": "${{ input.value > `10` }}" }
],
"set_on_true": { "name": "is_large_value", "value": true },
"set_on_false": { "name": "is_large_value", "value": false }
}
]Input Properties
| Field | Type | Required | Description |
|---|---|---|---|
conditions | array<object> | Yes | One or more { expression } objects. All expressions must evaluate to true to take the true branch. |
set_on_true | object | Yes | { name: string, value: any } to write into memory when all conditions pass. |
set_on_false | object | Yes | { name: string, value: any } to write into memory when any condition fails. |
- Each
expressionis a selector template (${{ ... }}) that must resolve to a Boolean. - The
namein each set block is written to<step_name>.output.state.<name>in memory.
Memory State After Flow
If you start with this initial memory:
{
"input": { "value": 15 }
}And run the Flow step above, your memory state is extended with:
{
// ... existing fields ...
"check_value": {
"output": {
"state": {
"is_large_value": true
}
}
}
}If input.value were 5, it would instead set:
{
"check_value": {
"output": {
"state": {
"is_large_value": false
}
}
}
}Multiple Conditions
Provide several conditions; the true branch requires all to pass:
{
"conditions": [
{ "expression": "${{ input.value > `10` }}" },
{ "expression": "${{ input.threshold > `20` }}" }
],
"set_on_true": { "name": "ok", "value": true },
"set_on_false": { "name": "ok", "value": false }
}- If any single condition is
false, the false branch fires.
Error Handling
- If any condition expression fails to parse or evaluate (e.g., missing comparison), the step records an error but still returns a
FlowResult. - Errors are collected in the circuit logs under the step name.
Referencing Flow State
After your Flow step runs, you can use the new state key just like any other memory field:
// In a later step or in outputs:
"value_label": "${{ check_value.output.state.is_large_value }}"Complete Circuit Example
{
"name": "value_check_workflow",
"inputs": [
{ "name": "value", "type": "number", "value": "${{ input.value }}", "required": true }
],
"steps": [
{
"name": "flag_big",
"function": "circuit.core.flow",
"conditions": [
{ "expression": "${{ input.value > `100` }}" }
],
"set_on_true": { "name": "is_too_big", "value": true },
"set_on_false": { "name": "is_too_big", "value": false }
},
{
"name": "report",
"function": "circuit.core.fetch",
"input": { "url": "https://api.example.com/log?big=${{ flag_big.output.state.is_too_big }}", "method": "GET" }
}
]
}Next up: Triggers – schedule your circuits or respond to external events!