Skip to main content
This chapter continues the workflow manual.

Deterministic derived values

Language models should interpret evidence, not perform authoritative arithmetic. Derived values provide a serializable calculation layer modeled on the shared-state expression DSL.
Reference a field in a prompt:
Or use a derived field in a condition:
Derived fields may reference earlier derived fields:
The resulting expression tree contains named, allowlisted operators. It has no callable, module path, source code, eval, or lambda. This is invalid:
The builder rejects it because derived fields must be WorkflowExpression objects.

Expression serialization

A mean expression resembles:
Deserialization rejects unknown operators. Dependencies are extracted from the tree and checked against the workflow. Derived references must name an earlier definition and an existing field.

Supported expression operations

The current evaluator supports:
Missing source outputs delay availability. Non-numeric values cause numeric aggregates to fail rather than silently inventing coercions beyond float(). all_equal() compares canonical serialized values, so it also works for lists and mappings such as complete rankings. choose(condition, then, otherwise) evaluates only the selected branch. This short-circuit behavior permits settlement expressions to reference answers on optional branches: outputs from correctly skipped branches are never requested.

Economic settlement primitives

Workflow expressions can consume a single answer or identity-preserving submissions. This supports authoritative arithmetic without asking a model to calculate payoffs:
Two-player normal-form games use a serializable payoff matrix. Explicit action codes avoid ambiguity when labels share an initial letter; matrix keys concatenate the codes in stable participant-ID order:
Codes must be unique one-character strings. Omitting action_codes retains the legacy first-character convention for serialized workflows created before this option was introduced. closest_to(question, target, ties="all") performs identity-aware ranking. DerivedFieldRef.for_participant() projects an identity-keyed mapping into a private recipient prompt. match(role("player"), size=2) deterministically partitions a roster and round-trips as data. Collections also expose serializable reductions:
nth_largest() and nth_smallest() use one-based ranks. During fan-out, an order statistic with too few responses is treated as not yet available, allowing remaining participants to answer before dependent work is rendered. Use a symbolic per-submission binding to apply one expression to every response while retaining participant identity:
The serialized expression contains map_submissions and submission_value operators; it does not contain a Python function. Evaluation returns a mapping from participant ID to result, which can be privately projected with payoffs.field("by_participant").for_participant(). A free own.value outside its map is rejected during authoring. Mapped expressions support the same arithmetic and comparisons as other workflow expressions, including symbolic absolute value:
This keeps distance-based scoring declarative and portable. Answers from multiple stages can be joined by participant identity before mapping a longitudinal payoff:
Every source must contain the same nonempty participant set. Incomplete joins remain unavailable rather than silently dropping respondents. The serialized tree uses join_submissions, joined_value, and map_joined_submissions. Static tables can select values or expressions without raw Python:
Keys are normalized to strings during serialization. A missing key raises an error unless default= is supplied. Named experimental constants belong in workflow metadata rather than being repeated throughout settlement expressions:
Parameters round-trip with the workflow and evaluate as ordinary expressions. Names must be unique and values must be JSON-serializable. Units are retained as metadata; automatic unit checking and prompt formatting are intentionally not yet implied.