Pattern 1 of 8

Sequential pipeline

Each agent picks up where the one before it left off.

Agents work on the same job in a fixed order: a parser turns a document into text, an extractor pulls the data out of it, and a summariser writes it up. Each stage hands over to the next once its part is done.

complier machine pipeline · runningparsermay parseextractorwaitingsummariserwaiting
startEach agent shows what the policy lets it do right now.

What complier holds

Every agent can call its tools at any time, so the order is only an instruction until something checks it. Here an agent that starts early is refused, and a stage whose call fails tries again instead of passing broken work on, because the next stage's turn only comes after a success.

In a spec

The example's policy is one line from the library:

pipeline.csp
Policy = Pipeline(<Stage(parser, parse), Stage(extractor, extract), Stage(summariser, summarise)>)

Pipeline takes a sequence of phases and runs them in order, each starting once the one before it has ended. The example's Stage(r, x) is a phase that ends only when r's call x succeeds.

The definitions, from patterns.csp
patterns.csp
-- Sequential pipeline: the phases run in order, each starting once the one before it has ended.
Pipeline(<>) = SKIP
Pipeline(<P>^Ps) = P ; Pipeline(Ps)

The guarantee

The extractor never acts before the parser's parse has succeeded, and the summariser never before the extractor's extract has. The spec states it as its own assertion, and FDR proves it against the most general agents (one ControllableCHAOS per role) before the machine starts. A spec that breaks the pattern isn't admitted.

pipeline.csp
-- Each stage acts only once the stage before it has succeeded.
assert Before({result.parser.parse.done}, {|attempt.extractor|}) [T= Policy
assert Before({result.extractor.extract.done}, {|attempt.summariser|}) [T= Policy

Try it

You need complier with FDR, with complier doctor saying ready (see Install). The pattern library, held calls and agents acting at the same time are new: until a release has them, build complier from a checkout of main. No agents needed: each command acts as an agent would.
  1. Save the spec

    Terminal
    cat > pipeline.csp <<'EOF'
    -- Sequential pipeline: a parser, an extractor and a summariser work on a document in turn. A stage
    -- hands over only once its call succeeded; a failed one is retried by the same agent.
    include "patterns.csp"
    datatype Role = parser | extractor | summariser
    datatype Act = parse | extract | summarise
    datatype Value = done | failed
    Returns(_) = {done, failed}
    
    Stage(r, x) = Permit(r, x, \ v @ if v == done then SKIP else Stage(r, x))
    
    Policy = Pipeline(<Stage(parser, parse), Stage(extractor, extract), Stage(summariser, summarise)>)
    
    -- Each stage acts only once the stage before it has succeeded.
    assert Before({result.parser.parse.done}, {|attempt.extractor|}) [T= Policy
    assert Before({result.extractor.extract.done}, {|attempt.summariser|}) [T= Policy
    
    Agent  = ||| r : Role @ ControllableCHAOS(r)
    System = prioritise(Agent [| {|attempt, allow, deny, result, refuse|} |] ComplierGuard(Policy),
                        <{|attempt|}, {|refuse|}>)
    EOF
  2. Start the machine

    FDR proves the policy and the pattern's guarantee before anything runs:

    Terminal
    complier machine up pipeline --spec pipeline.csp

    To watch it, run complier machine log pipeline --follow in a second terminal.

  3. Play the flow

    Each line is one step of the animation above. act attempts a step as the agent in that role; result gives its call's result.

    Terminal
    complier machine act pipeline --role extractor extract      # refused: the policy doesn't take extract from extractor now
    complier machine act pipeline --role parser parse           # allowed
    complier machine result pipeline --role parser failed
    complier machine act pipeline --role parser parse           # allowed
    complier machine result pipeline --role parser done
    complier machine act pipeline --role extractor extract      # allowed
    complier machine result pipeline --role extractor done
    complier machine act pipeline --role summariser summarise   # allowed
    complier machine result pipeline --role summariser done
  4. Stop it

    Terminal
    complier machine down pipeline

With real agents, a translation unit names which tool calls are which steps, and each agent starts in its role: COMPLIER_MACHINE=pipeline COMPLIER_ROLE=parser claude --plugin-dir plugin. The two-agent guide walks through one.