Two agents

A writer and a reviewer, two Claude Code sessions, share one machine and take turns. The writer can't publish until the reviewer approves, and while one works, complier holds the other.

You need complier installed, with complier doctor saying ready. See Install. You'll use four terminals.

  1. Copy the demo

    It comes with complier. Copy it somewhere you can work in:

    Terminal
    cp -R ~/.complier/examples/two-agents ~/two-agents
  2. Read the contract

    It's in ~/two-agents/review-gate.csp. Each step belongs to a role, and the review's result decides what comes next:

    review-gate.csp
    datatype Role = writer | reviewer
    
    Writing  = Permit(writer, submit, \ v @ if v == done then InReview else Writing)
            [] Permit(writer, other, \ _ @ Writing)
    InReview = Permit(reviewer, review, \ v @ if v == approved then Approved
                                             else if v == rejected then Writing else InReview)
            [] Permit(reviewer, other, \ _ @ InReview)
            [] Deny(writer, publish, InReview)
    Approved = Permit(writer, publish, \ v @ if v == done then SKIP else Approved)
            [] Permit(writer, other, \ _ @ Approved)
    
    Agent = ||| r : Role @ ControllableCHAOS(r)

    Agent is one ControllableCHAOS per role: FDR proves the contract against two independent agents. The agents take turns. In each state only one role has anything to do, and other (writing the draft, reading the board) is only offered to that role. The other agent ends its turn, and complier holds it until it's its turn again.

  3. Start the machine

    FDR proves the contract and the CEL verifier proves the unit before anything runs:

    Terminal
    complier machine up review-gate ~/two-agents
  4. Watch it

    In a second terminal:

    Terminal
    complier machine log review-gate --follow
  5. Start the writer

    In a third terminal, go to the shared folder:

    Terminal
    cd ~/two-agents/workspace

    Start Claude Code as the writer:

    Terminal
    COMPLIER_MACHINE=review-gate COMPLIER_ROLE=writer claude --plugin-dir ~/.complier/plugin

    Trust the folder if it asks, then give it:

    prompt
    You are the writer: follow WRITER.md.
  6. Start the reviewer

    In a fourth terminal, the same folder:

    Terminal
    cd ~/two-agents/workspace

    Start Claude Code as the reviewer:

    Terminal
    COMPLIER_MACHINE=review-gate COMPLIER_ROLE=reviewer claude --plugin-dir ~/.complier/plugin

    Then give it:

    prompt
    You are the reviewer: follow REVIEWER.md.
  7. What to look for

    In the log, within a minute or so:

    • The reviewer waits without making a call: complier holds it until there's a submission.
    • The writer submits, then tries to publish before review: denied. It ends its turn and complier holds it.
    • The reviewer is told to continue, and rejects or approves. A rejection wakes the writer to revise and submit again.
    • After the approval, complier wakes the writer, it publishes, and the log ends with finished. Both sessions are free to stop.
  8. Stop the machine

    Terminal
    complier machine down review-gate