Computed Variables
Let the platform work out a value instead of asking the model to do it mid-conversation
An ordinary dynamic variable receives its value from outside: a request, a call header, a campaign row. A computed variable works its value out — from a stored formula, out of the other variables.
Why
A real example. A collections agent needs the payment date after a rollover: due_date plus 14 days. Asking the model to work that out during the call fails in a stable way — it confuses branches, takes the wrong starting point, and reads the machine format out loud.
The agent should not be computing such a value at all. It should arrive ready:
# System prompt
Your new payment date is {{new_payment_date}}.And next to the ordinary variables in the agent's settings there is a formula:
date({{due_date}}, "yyyy-MM-dd").addDays(14)All the date arithmetic leaves the prompt.
Setting one up
- Agent settings → Variables → add a variable.
- Turn on "Computed by the platform".
- Type the formula. On Ctrl+Space, and right after
{{, the editor offers what this step actually has: the variables with their types, the fields of theagentobject, the functions. Only things that will save are offered — including variables you have just declared and not saved yet. - Check the result under "Try it" — fill in test values and see what comes out.
The formula is checked when you save, not on the call: a syntax error, an unknown name, incompatible types and circular dependencies will not save at all.
When it runs
Once, as the conversation starts, before anything is substituted into the prompt or the first message. The value does not change during the conversation.
Renaming a variable
A formula reads variables by name. Rename a variable a formula refers to and the formula stops being valid — it says so the next time the agent is saved, underlining the exact spot. It will not quietly keep computing the old way.
What you can write
A variable stores a string, a whole number or a number. date and
datetime are what a formula computes in; what leaves it is ISO 8601 text, and
the result schema is {"type":"string"}. That is why there is no "date type"
to pick anywhere: it lives inside the formula and ends there.
References go in double braces, as in the prompt: {{due_date}}. Object fields
are read with a dot: {{agent.title}}, {{agent.timezone}}.
Operators: + - * /, comparisons < <= > >= == !=, logical && || !,
parentheses.
Functions are a closed list; a name outside it does not exist:
| Function | What it gives |
|---|---|
date(value, format) | a calendar date out of text, by pattern |
date(year, month, day) | a date out of numbers: date(2026, 11, 10) |
datetime(value, format) | a date and time, with an offset from UTC or without |
x.toString() / x.toString(format) | the value as text — written after the value |
if(condition, yes, no) | one of two |
case(condition, value, …, otherwise) | the first one that holds |
today() | today's date in the agent's time zone |
dateInZone(value, zone) | the calendar date of a moment in the given zone |
lower(x) / upper(x) | case |
trim(x) | without surrounding spaces |
length(x) | length of the text |
Date patterns
Ordinary .NET custom patterns, invariant culture: yyyy-MM-dd, dd.MM.yyyy,
yyyy-MM-dd HH:mm, HH:mm zzz. Parsing is exact — the text has to match
the pattern in full.
date("2026-11-10", "yyyy-MM-dd") → 2026-11-10
date("10.11.2026", "dd.MM.yyyy") → 2026-11-10
date("10.11.2026", "yyyy-MM-dd") → conversion error
date("2026-02-30", "yyyy-MM-dd") → error: no such dayA pattern written out in the formula is checked when you save. A pattern arriving in a variable is checked when it runs — nothing is known about it beforehand.
A one-character pattern is refused. To .NET "d" means "short date of the
current culture", not "day of month", and any agreement with what was meant is
a coincidence.
What comes out
| Result of the formula | Value of the variable |
|---|---|
date | 2026-11-21 |
datetime with an offset | 2026-11-10T14:30:00+03:00 |
datetime without one | 2026-11-10T14:30:00 |
An offset and fractional seconds are kept when they are there. Neither the browser's zone nor the server's is ever substituted.
Want another shape — .toString(pattern). It is written after the value,
so it chains without naming anything in between:
date({{due_date}}, "yyyy-MM-dd").addDays(11).toString("dd.MM.yyyy") → 21.11.2026
date(2026, 11, 10).toString("dd.MM.yyyy") → 10.11.2026
(42).toString("0000") → 0042
(42.5).toString("0.00") → 42.50Without a pattern, .toString() prints the value the way it reaches the prompt
anyway: a date as 2026-11-10, a number as 42.5, a yes-or-no answer as
true. Text has no pattern — there is nothing in it to lay out, and a pattern
on it will not save. A number's pattern is spelled with digits ("0000",
"0.00"), a date's with letters ("dd.MM.yyyy").
Dates and days
A date is moved by a method — the unit is in its name:
date({{due_date}}, "yyyy-MM-dd").addDays(14)
today().addDays(1)
{{due_date}}.addDays(-{{grace_days}})Positive moves forward, negative back, zero leaves the date alone. What gets added is calendar days: "plus 14" means the date a fortnight later, not plus 14×24 hours. Across a month boundary and across a clock change those are different answers, and the platform gives the first.
The count has to be whole — addDays(1.5) will not save: half a day does not exist in a calendar. A variable or an expression works in place of a literal.
Choosing between values
if gives one of two:
if({{attempts}} >= 3, "manual_review", "continue")case is a ladder of conditions read top to bottom, with a required
"otherwise" at the end:
case(
{{attempts}} >= 5, "blocked",
{{attempts}} >= 3, "manual_review",
"continue"
)The first condition that holds wins: at attempts = 5 the answer is
"blocked", even though the second condition is true as well. At
attempts = 3 it is "manual_review", at attempts = 1 — "continue".
Both branches have to produce the same kind of thing — text or a number, not one of each: a variable has one type, and "text on Mondays" has nowhere to be stored. A condition is always yes-or-no; zero and an empty string do not count as "no".
While the cursor sits inside the call, the signature shows above it with the
current position highlighted — whether a condition, a value or the trailing
"otherwise" is expected here. In a case the two alternate, and there is no
need to count commas by eye.
The branch that was not chosen is not evaluated, which is what makes this work:
if({{has_date}}, date({{due_date}}, "yyyy-MM-dd").toString("dd.MM.yyyy"), "no date yet")With no date, the parse in the first branch simply never happens. A mistake in it is still shown in the editor, though — both branches are checked, so a breakage does not wait for a call.
How many days between two dates
One date minus another is a difference, left minus right:
(date(2026, 11, 24) - date(2026, 11, 10)).days → 14
(date(2026, 11, 10) - date(2026, 11, 24)).days → -14The difference itself does not become a variable's value: "two weeks" is not a value until you say what shape you want it in. So it has two ways out:
.days— the number of calendar days, signed, written without parentheses: it is a property, not a function;.toString()— a duration likeP14D,-P14D,P0D(the sign goes before theP).
Leave it as plain {{due_date}} - {{paid_at}} and the formula will not save; the error names both ways out. Two dates cannot be added — "the day before yesterday plus Tuesday" is not a quantity.
A variable out of a workspace secret
When a variable has to carry a key or a token, there is no need to type it into the agent: the +Add Variable menu has a Workspace secrets group. Picking one creates a variable bound to that secret and inserts the placeholder into the text.
The value is never shown — not in the variable's drawer, not in an API response. It is read and decrypted while the call is being set up, substituted into the prompt and forgotten; it is not stored with the conversation.
For the same reason a formula cannot see such a variable. A computed value
is stored next to the conversation and shown in its card, so {{api_key}} in a
formula would be a one-line way of copying the secret somewhere it is kept in
the clear.
The secret's name is checked when the agent is saved: a renamed or deleted secret would otherwise turn up as an empty placeholder mid-call.
The rules people trip over
Text is text until it is read. A variable of type "string" stays a string, whatever it holds. To treat it as a date, say so:
date({{due_date}}, "yyyy-MM-dd").addDays(14)The formula then shows what shape the text arrived in. This used to be derived
from a setting on the variable, and the same 10.11.2026 was read, or not
read, depending on a checkbox two fields up.
A date and a bare number cannot be added. … + 14 will not save: 14 of
what? Write .addDays(14) — the editor offers the method as soon as you put a
dot after a date.
A moment in time does not become a date by itself. Which calendar date a
datetime falls on depends on the zone, so .addDays() does not apply to it.
Either name the zone or format it:
dateInZone(datetime({{created}}, "yyyy-MM-ddTHH:mm:sszzz"), "Asia/Manila").addDays(1)Offsets are never invented. If a moment was written without one, a pattern that asks for it is an error:
datetime("2026-11-10 14:30", "yyyy-MM-dd HH:mm").toString("HH:mm zzz") → errorPrinting +00:00 here would say "in UTC" where all that is known is "we were
not told where".
A yes-or-no answer is not stored in a variable. 1 > 0 is a perfectly good
formula and a hopeless variable: the word "true" would end up in the prompt.
Comparisons work as usual inside a formula; only the result is refused.
Division by zero. A literal zero divisor is rejected when you save. A zero that arrives as a value is an evaluation error with a readable line in the session card.
One variable out of another
A computed variable may read another computed one — the platform works out the order from the dependencies, and the order of the fields in the form has no effect on it:
shifted = date({{due_date}}, "yyyy-MM-dd").addDays(14)
final_notice = date({{shifted}}, "yyyy-MM-dd").addDays(1)The second formula reads the first as a string — that is exactly how the value is stored.
A formula cannot see itself. A variable may not read its own value, and two formulas may not refer to each other in a circle. Both are rejected when you save: on a call that would be either an infinite loop or, worse, a silently empty spot in the prompt.
Time zone
today() is worked out in the agent's time zone: the agent's zone first, then the space's, and UTC only if neither is set.
This is not cosmetic
From 16:00 to 23:59 in Manila it is still the previous day in UTC. For a collections agent those are the busiest hours: in UTC it would understate the days overdue by one and accept a promise for "tomorrow" that is already today. Set the space's zone (Space settings → Time zone) and, if your agents work in different countries, each agent's zone.
The prompt also has ready-made system variables: {{system__date}} and {{system__time}} in the agent's zone, {{system__timezone}} for the zone's name, {{system__date_utc}} and {{system__time_utc}} in UTC.
When it cannot be computed
A value the formula reads may not arrive — the call header was not there, the campaign row was empty. The variable is then left without a value and a line appears in the session card naming the variable and the reason.
The conversation is not interrupted: one broken formula out of five is a reason to say so loudly, not a reason to drop an incoming call. What stays in the prompt is a visible {{placeholder}} rather than a blank that reads like a real answer.