Pattern 7 of 8
Advisor
An agent can ask another agent for advice.
A developer works as it likes, and when it's unsure it asks a more experienced agent. It waits for the answer, reads it, and decides what to do; the advisor never does the work itself.
What complier holds
The developer's ask is held until the advisor has answered, and then runs, so its tool call returns with the answer to read. The advisor gets a turn only when asked, sees the question (the held call's arguments), and can do exactly one thing with it: answer.
In a spec
The example's policy is one line from the library:
Policy = Consult(developer, ask, advisor, answer, \ _ @ Work)Consult(r, x, a, y, K) holds r's call x until advisor a has answered with its call y; then r's call runs and its result v carries on as K(v). In the example it's one choice among the developer's steps, so it can ask at any point.
The definitions, from patterns.csp
-- A held call: role r's call x is taken, and answered only once H has ended. Until then r waits (its
-- tool call doesn't return) while H's agents act. Then the call is allowed, and its result v carries
-- on as K(v).
Hold(r, x, H, K) = attempt.r.x -> (H ; allow.r.x -> result.r.x?v : Returns(x) -> K(v))
-- Advisor: r's call x asks advisor a, and is held until a answers with one call y; then r's call
-- runs (and can read the answer). The advisor acts only when asked, and only to answer.
Consult(r, x, a, y, K) = Hold(r, x, Step(a, y), K)The guarantee
The advisor answers only when asked, once per question. 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 advisor answers only when asked, once per question.
assert Alternate({|attempt.developer.ask|}, {|attempt.advisor.answer|}) [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 > advisor.csp <<'EOF' -- Advisor: the developer edits and commits as it likes, and may ask the advisor at any point. Its -- ask waits until the advisor has answered, then runs (and reads the answer). The advisor acts only -- when asked, and only to answer. include "patterns.csp" datatype Role = developer | advisor datatype Act = edit | ask | answer | commit datatype Value = done | failed Returns(_) = {done, failed} Work = Permit(developer, edit, \ _ @ Work) [] Consult(developer, ask, advisor, answer, \ _ @ Work) [] Step(developer, commit) Policy = Work -- The advisor answers only when asked, once per question. assert Alternate({|attempt.developer.ask|}, {|attempt.advisor.answer|}) [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 advisor --spec advisor.cspTo watch it, run
complier machine log advisor --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. A held call waits for its verdict, so it runs in the background; the step that answers it says so, and the held call prints its verdict when it comes.complier machine act advisor --role advisor answer # refused: the policy doesn't take answer from advisor now complier machine act advisor --role developer edit # allowed complier machine result advisor --role developer done complier machine act advisor --role developer ask & sleep 1 # held: its verdict prints when it comes complier machine act advisor --role advisor answer # allowed complier machine result advisor --role advisor done # developer's ask is allowed complier machine result advisor --role developer done complier machine act advisor --role developer commit # allowed complier machine result advisor --role developer doneStop it
complier machine down advisor
With real agents, a translation unit names which tool calls are which steps, and each agent starts in its role: COMPLIER_MACHINE=advisor COMPLIER_ROLE=developer claude --plugin-dir plugin. The two-agent guide walks through one.