Pattern 3 of 8
Parallel fan-out/gather
Several agents work at once; one gathers their results.
Independent pieces of work go to agents that run at the same time, here a security, a style and a performance review of one pull request, and one more agent gathers them once they're all in.
What complier holds
The reviewers act concurrently: each has its own call in flight, and none waits for another. The summariser is refused until every reviewer's call has come back. Each branch is its own agents; if two branches shared a role, the policy would be ambiguous about whose step a call is, and FDR refuses it.
In a spec
The example's policy is one line from the library:
Policy = FanOut(<Step(security, review), Step(style, review), Step(performance, review)>, Step(summariser, summarise))FanOut takes a sequence of branches, phases that run at the same time, and a gathering phase that starts once every branch has ended. Step(r, x) is a phase of one call.
The definitions, from patterns.csp
-- Parallel fan-out/gather: the branches run at the same time, and Gather starts once every one of
-- them has ended. Each branch is its own agents: branches that share a role's calls make the policy
-- nondeterministic, and FDR refuses it.
FanOut(Branches, Gather) = Together(Branches) ; Gather
Together(<>) = SKIP
Together(<B>^Bs) = B ||| Together(Bs)The guarantee
The summariser acts only once every reviewer's review has come back. 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.
-- The summariser acts only once every reviewer's review has come back.
assert Before({|result.security.review|}, {|attempt.summariser|}) [T= Policy
assert Before({|result.style.review|}, {|attempt.summariser|}) [T= Policy
assert Before({|result.performance.review|}, {|attempt.summariser|}) [T= PolicyTry it
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.Save the spec
cat > fan-out.csp <<'EOF' -- Parallel fan-out/gather: three reviewers look at a pull request at the same time, and the -- summariser writes the review once all three are done. include "patterns.csp" datatype Role = security | style | performance | summariser datatype Act = review | summarise datatype Value = done | failed Returns(_) = {done, failed} Policy = FanOut(<Step(security, review), Step(style, review), Step(performance, review)>, Step(summariser, summarise)) -- The summariser acts only once every reviewer's review has come back. assert Before({|result.security.review|}, {|attempt.summariser|}) [T= Policy assert Before({|result.style.review|}, {|attempt.summariser|}) [T= Policy assert Before({|result.performance.review|}, {|attempt.summariser|}) [T= Policy Agent = ||| r : Role @ ControllableCHAOS(r) System = prioritise(Agent [| {|attempt, allow, deny, result, refuse|} |] ComplierGuard(Policy), <{|attempt|}, {|refuse|}>) EOFStart the machine
FDR proves the policy and the pattern's guarantee before anything runs:
complier machine up fan-out --spec fan-out.cspTo watch it, run
complier machine log fan-out --followin a second terminal.Play the flow
Each line is one step of the animation above.
actattempts a step as the agent in that role;resultgives its call's result.complier machine act fan-out --role summariser summarise # refused: the policy doesn't take summarise from summariser now complier machine act fan-out --role security review # allowed complier machine act fan-out --role style review # allowed complier machine act fan-out --role performance review # allowed complier machine result fan-out --role style done complier machine act fan-out --role summariser summarise # refused: the policy doesn't take summarise from summariser now (the results of performance.review, security.review haven't come back yet) complier machine result fan-out --role security done complier machine result fan-out --role performance done complier machine act fan-out --role summariser summarise # allowed complier machine result fan-out --role summariser doneStop it
complier machine down fan-out
With real agents, a translation unit names which tool calls are which steps, and each agent starts in its role: COMPLIER_MACHINE=fan-out COMPLIER_ROLE=security claude --plugin-dir plugin. The two-agent guide walks through one.