Skip to content

compute

compute

Pure computation with no I/O. The workhorse step type for data transformation, calculation, and output construction. Compute steps use mashin’s expression language (JavaScript-inspired) and are deterministic by construction: same inputs always produce the same output.

When to use

Use compute when you need to:

  • Transform, filter, or reshape data
  • Calculate values from inputs or previous step results
  • Build the final output of a machine
  • Combine results from multiple previous steps

Use ask instead when you need LLM reasoning. Use call when you need to invoke another machine. Use decide for branching logic.

Syntax

compute <name>
<expression>

The expression body is evaluated and its result becomes the step’s output. The last expression in the body is the return value.

Accessing data

ReferenceWhat it accesses
input.<field>Machine input fields
steps.<step_name>.<field>Output from a previous step
context.<key>Execution context values

Examples

Simple output construction

machine greeter
accepts
name as text, is required
responds with
greeting as text
implements
compute greet
{greeting: "Hello, " + input.name + "!"}

Data transformation

machine summarizer
accepts
items as list, is required
responds with
count as number
total as number
average as number
implements
compute analyze
let count = items.length
let total = items.reduce((sum, x) => sum + x, 0)
{count: count, total: total, average: total / count}

Using previous step results

machine pipeline
implements
ask classify, using: "anthropic:claude-sonnet-4-6"
with task "Classify this text as positive, negative, or neutral"
compute format_result
let label = steps.classify.classification
let score = steps.classify.confidence
{
label: label,
score: score,
summary: label + " (confidence: " + score + ")"
}

Conditional logic in expressions

compute categorize
let value = input.amount
{
category: value > 1000 ? "high" : value > 100 ? "medium" : "low",
formatted: "$" + value.toString()
}

Governance

Compute steps are pure by construction (Law I). They cannot perform I/O, call external services, or access the network. This purity is not enforced by a sandbox; the capability simply does not exist. The expression language has no I/O primitives.

This means compute steps:

  • Never require governance approval
  • Never appear in permission checks
  • Always execute, regardless of trust level
  • Are safe to run in any mode (full, test, simulate)

Expression language

The expression language is JavaScript-inspired with these built-in operations:

  • Arithmetic: +, -, *, /, %
  • Comparison: ==, !=, >, <, >=, <=
  • Logical: &&, ||, !
  • Ternary: condition ? then : else
  • String: concatenation with +, interpolation with template literals
  • Array: .map(), .filter(), .reduce(), .length, .find(), .includes()
  • Object: dot access, bracket access, spread ..., destructuring
  • Let bindings: let x = expr (scoped to the step)

Translations

LanguageKeyword
Englishcompute
Spanishcalcula
Frenchcalcule
Germanberechnet
Japanese計算
Chinese
Korean계산

See also