The language
Build a factoryModules, units, steps, ports, bindings, loops and the expressions that connect them.
A factory is written in the spec's own small DSL and saved as .fct files.
This page is the working tour; the specification is the
authority on grammar and execution semantics.
Modules
A factory is multi-file. One root module is the entry point; imports are followed transitively:
import "types" as t
import "runners" as r
trigger start:
kind: manual
out: { ticket: t::Ticket }
step draft:
runner: r::agent
in: { prompt: "Draft a reply.", ticket: start.ticket }
out: { text: text }
import "types" as tloadstypes.fctbeside the importing module; a declaration is then referenced ast::Ticket.file "prompts/planner.md"injects the content of a file, resolved relative to the module that declares it. The file's content is part of the factory digest.- The root module is the one a caller names. Its directory (for imports) and
each declaring module's directory (for
file) are the resolution roots.
Comments start with #.
Units: leaf and composite
A unit is a named, reusable definition. It is a leaf when it names a
runner: and a composite when it contains nested step: entries:
unit planner:
runner: platform
in: { issue: Issue }
out: { plan: Plan }
unit review:
in: { issue: Issue }
out:
plan: Plan = plan_step.plan
verdict: text = check.verdict
step plan_step:
use: planner
in: { issue: inputs.issue }
step check:
runner: platform
in: { plan: plan_step.plan, command: "make lint" }
out: { verdict: text }
- A leaf's
runner:names an implementation the deployment provides. Itsin:andout:describe the interface the implementation expects or produces. - A composite is a scope: its steps form a dataflow graph, and only the
unit's
out:ports cross its boundary. - Inside a composite,
inputs.<port>andoutputs.<port>name its own boundary ports — thein:andout:it declares. The words are the same forunitandloop, andinputs.never repeats thein:block key. loop:is a composite that must contain aprev(feedback) cycle.unit:may or may not.- A unit may invoke itself. Recursion must terminate through a guard or the max-firings bound.
Declare a unit only when it is reused or imported; otherwise inline its payload at the step.
Steps
A step is one node in a composite (or at the root). It has three forms:
# 1. a reference: inherits the unit's out ports
step p:
use: planner
in: { issue: start.ticket }
# 2. a provider-kind invocation: leaves the interface to the adapter
step notify:
kind: webhook
in: { text: p.plan }
# 3. an inline unit: declares its own out ports
step draft:
runner: agent
in: { prompt: "Draft a reply.", ticket: start.ticket }
out: { text: text }
A step may carry a when: guard, and both steps and units may have an optional
config: map of static data (a prompt, a command, a timeout) that belongs to
the adapter, not to the dataflow.
Ports and bindings
A binding is a target port on the left and a source on the right:
in:
issue: start.ticket # a producer port
repo: checkout(issue: start.ticket) # an external-port call
prompt: file "prompts/review.md" # injected content
retries: 3 # a literal
- Sources are paths (
step.port,inputs.port,outputs.port,this), external-port calls, built-in calls, literals, or record/list/map literals whose leaves are themselves sources. - A target is one port name: a record-typed port is supplied whole, not field by field.
name?:marks a binding optional: an absent source drops the binding instead of blocking the node. At least one binding must be required.name: Type = sourceis an optional upper bound on the bound value; the source's own type still has to conform.if <expr>on a binding andwhen: <expr>on a node are guards.prev name: sourceis a loop-carried binding: it becomes active on the node's next firing.prev name: Type = value then sourceseeds the first firing.
step draft:
runner: agent
in:
prompt: "Draft a reply."
ticket: start.ticket
prev feedback: review.text if not review.approved and draft.attempt < 3
out: { text: text }
The feedback edge makes draft re-fire while the review rejects it, up to
three attempts. attempt is an implicit port (see below), so a loop budget is
ordinary data.
Implicit ports and identity
Every trigger and step that fires exposes:
terminated_at: time— the instant of its most recent firing;attempt: int— the 1-based ordinal of that firing.
Binding either one orders one node after another: draft.attempt waits for
draft to have fired.
The reserved source this exposes opaque execution identities:
this.metadata.run.id, this.metadata.node.id and this.metadata.step.id.
Adapters also stamp them on external effects (an S3 object's metadata, for
example) so a listener can recognise its own output and avoid a feedback loop.
Treat the ids as opaque strings.
External ports and built-ins
An external port is a typed call the deployment implements — a credential store, a repository checkout, a clock:
external port checkout(issue: Issue) -> Folder
external port credential(key: text) -> secret
external port config(key: text, default?: text) -> text
They are called in a binding: repo: checkout(issue: start.ticket). When they
run and whether they memoize is the implementation's choice.
List and map values have pure core built-ins:
list::append,list::concat,list::find,list::map,list::filter,list::length, and friends — see the spec's §8.1.map::at,map::has,map::keys,map::values,map::merge, … — §8.2.
They are called positionally: list::append(labels, "new").
Expressions
Arithmetic (+ - * / %), comparisons (< <= > >= == !=) and boolean logic
(and or not) work in guards and in values. The special test x is tag checks
a choice value's tag. Operators are whitespace-delimited, so write a + b,
not a+b.
Checking a factory
Uploading a version runs the same validation as CI's in-memory bundle compiler. The example bundle suite exercises parsing, resolution and validation for the shipped factories.
A shape error is reported at upload and the version is not accepted. A factory that is valid but names an adapter this deployment lacks is accepted and rendered, and marked not runnable — see Adapters.
Your factories will appear here. Create one and open it beside this guide.