Run it

From a clone of stackunseen/examples (on Windows, type python where it says python3):

bash
git clone https://github.com/stackunseen/examples
cd examples
cd practice-supervisor-control
python3 -m unittest -v

What you build

A supervisor asks the model what to do next, hands the work to a specialist and feeds the result back until the model answers. Getting that loop to run is the easy part. You write the three things that make it safe to leave running:

  • Hand-offs that come back. Call the specialist the model names and give the model what it returned. A name that is not a specialist goes back to the model as a message, not a crash.
  • A turn budget. Stop after max_turns, however keen the model is to carry on.
  • An approval gate. An action that changes something outside, here sending an email, runs only when approve() says yes.

The model is scripted and the specialists are stubs, so it runs offline in a second. The supervisor is yours.

Checking your work

Six checks in test_supervisor.py say what the supervisor must do, one behaviour each. The first passes before you start; the others fail with the TODO they need. A missing turn budget fails its check after 50 turns instead of running for ever. The code tour below gives one hint per TODO when you want one.

When all three parts work, python3 -m unittest -v reports every check passing (shortened here to the check names):

output
1. Returns the model's answer when it answers straight away ... ok
2. Hands work to the specialists the model names and feeds back what they return ... ok
3. Tells the model about a specialist that does not exist, instead of crashing ... ok
4. Stops at the turn budget when the model never answers ... ok
5. Runs nothing when approve() says no, and tells the model ... ok
6. Asks approve() before an action runs, then runs it once ... ok

Ran 6 tests

OK

When you are done

solution.py in the same folder has one way to do it, and PRACTICE_SOLUTION=1 python3 -m unittest -v runs the same checks against it. Then open Multi-agent orchestration, which runs the same supervisor against a real model with no framework: find where its turn limit is set and where an approval step would go.