Writing a Formula
A formula mixes metric references in{{double braces}} with operators.
References
In Studio you reference metrics by name. Studio stores them by id, so renaming a source metric doesn’t break the formula. Through the API, write the id:
{{id:<metric definition id>}} and {{id:<metric definition id> >= 4}}.
A plain reference reads Numeric, Count, and Scale values as they are, and a Boolean as 1 or 0. Compare a value inside the braces with:
Text metrics can’t be used in a formula.
Operators
Output
A formula returns a Numeric or a Boolean:- Numeric for arithmetic over plain references:
({{Empathy}} + {{Resolution}}) / 2. - Boolean for comparisons combined with
AND,OR, andNOT. Any non-zero result is true.
Rules
- At least two metric references, up to 500 characters, with balanced parentheses.
- Every source must record a value per call. Metrics that only record values per segment or turn, such as Response Time, can’t be referenced. To build on those, use a pattern or a threshold.
- A formula can reference other formulas and thresholds, as long as they don’t loop back to it. Roark computes the sources first.
Creating a Formula
In Studio
Open Studio in Author mode and pick the Formula engine. The engine is locked after the first save.![Studio Author mode with the Formula engine selected: the formula {{Task Completion >= 2}} AND {{Instruction Follow >= 4}} AND {{Call Reason != "Wrong number"}}, a toolbar with Insert metric and the AND, OR, NOT and parenthesis operators, a Boolean badge, the letter map A Task Completion, B Instruction Follow, C Call Reason, the preview [A] >= 2 AND [B] >= 4 AND [C] != "Wrong number", and the True and False labels Successful call and Unsuccessful call](https://mintcdn.com/roark/s80NtcBbMfjE9Dti/images/metrics/formula-metric.png?fit=max&auto=format&n=s80NtcBbMfjE9Dti&q=85&s=aa2f13dfa70fdfe5c1c71a05e453cfe1)
{{ or click Insert metric to pick a source. Studio only offers metrics the formula can use. Click a comparison to change its operator or value. The toolbar shows the operators for the output you’re building, and the preview underneath shows the formula with each source as a letter.
With the SDK or API
Create the metric withcalculationType: "FORMULA". List every metric the formula references in sources:
formula.
To change the expression later,
PUT /v1/metric/definitions/{idOrSlug} with the new formula, and sources if they changed. The same request sets booleanTrueLabel and booleanFalseLabel on a Boolean formula. Each change creates a new metric version.
Formulas aren’t part of config as code yet. Create them in Studio or through the API.
Reading the Result
Each value carries its working in the reasoning, with every source’s value, for example:When a source is missing
If any source has no value on the call, the formula records N/A, and the reasoning names the sources it couldn’t read. It never fills a missing source with zero. Add the sources to the same collector or run plan as the formula, so they run on the same calls. A formula that can’t produce a finite number, such as a division by a source that is0, fails on that call instead of recording a value. Guard divisions with MAX({{Turns}}, 1).
What’s Next
LLM Judge
Write the focused metrics a formula combines
Thresholds
Turn a single metric into a pass/fail check
Patterns
Detect what follows what within a call
Collectors
Run the formula automatically on live calls