Flow variables and templates
Use template variables to pass data between steps and reference Flow inputs with {{variable}} syntax.
Basic syntax
Use double curly braces to reference a variable:
Use template variables in prompts, URLs, request bodies, and conditions.
Flow input
To pass values into a Flow through the Runtype API, include them in the inputs field. Reference each value by its key:
For a record-based execution, use _record.metadata to read record metadata:
If you set an ownerId when you created the Record or conversation, read it from
{{_record.ownerId}}, not from metadata. Runtype stores the owner in its own field, so
{{_record.metadata.ownerId}} resolves empty. {{_record.ownerId}} also resolves empty
for a Record that has no owner.
Step outputs
Reference an earlier step’s output by its outputVariable name:
When the output is a JSON object, use dot notation to read nested fields:
Nested properties
Use dot notation to read nested properties:
Array access
Use bracket notation and a zero-based index to read array items:
System variables
Use these built-in variables in Flow templates:
An _agent variable is available only in an Agent’s memory.profileTemplate, not in Flow step templates. It carries {{_agent.id}} and, when the request selected a version, {{_agent.alias}}, {{_agent.versionId}}, and {{_agent.version}} (the version’s label). See Memory namespaces and release pointers.
The _schedule variable is available only in schedule-fired executions. It includes id, name, cron, timezone, lastRunAt, and nextRunAt fields.
An _endUser variable is present when you include an endUser object with an id in the dispatch request or the agents/:id/execute request. Use {{_endUser.id}} in an agent memory profileTemplate to keep long-term memory separate for each end user. _endUser identifies your customer’s end user, not the Runtype account holder in _user. If you omit endUser, a reference to _endUser resolves to an empty string.
A Product Tenant is your customer’s account or workspace inside your product. It sits between the builder organization in _user and the individual end user in _endUser. An _tenant variable is present when you include a tenant object with an id in the same requests. Use {{_tenant.id}} for state shared by a tenant’s end users and {{_endUser.id}} for state scoped to one end user. If you omit tenant, a reference to _tenant resolves to an empty string.
Runtype removes projectedId from both identity objects before it adds them to template context. Runtype uses durable tnt_* and eu_* projection IDs to scope records, secrets, and approval grants. A reference to {{_tenant.projectedId}} or {{_endUser.projectedId}} resolves to an empty value. If you include projectedId in the request, Runtype drops it. Use {{_tenant.id}} or {{_endUser.id}} instead. The flow validator reports a RESERVED_IDENTITY_VARIABLE recommendation.
Default values
Use a fallback when a variable might be undefined:
The || operator uses the first truthy value. Use ?? to fall back only when a value is null or undefined. Empty strings and 0 do not trigger ??.
String concatenation
Combine variables with surrounding text in a template:
Calculations and conditional logic
Use a transform-data step for calculations, ternary expressions, and other complex logic. Template syntax supports variable references and fallback chains, but it does not support arithmetic or comparison operators.
Using variables in JSON
Insert variables into JSON request bodies and metadata as follows:
Quote string values. Leave numeric and boolean values unquoted.
Runtype evaluates variables at runtime. A reference to a step that has not run does not resolve.
Debugging variables
To inspect variable values, add a transform-data step. In the script, reference Flow variables by their outputVariable names:
Check the step output in the execution results to see the returned values.
Variable scope
Within one Flow execution, use variables in these ways:
- Reference an earlier step’s
outputVariablein the same Flow. - Do not reference variables from another Flow.
- Reference variables set inside a conditional branch after the conditional completes.
Best practices
Use these practices when you design variable references:
- Use descriptive step names to make references clear.
- Use defaults or conditionals when data might be missing.
- Keep property chains shallow to reduce errors.
- Test variables with representative data in each scenario.
Next steps
Continue with these Flow guides:
- Using prompt steps: generate responses with variables.
- Using transform-data steps: transform and calculate values.
- Using conditional steps: branch based on variable values.
- Debugging flows: inspect execution results.