interactive · 12 min
A Supervisor & Workers
Objective: a supervisor routes each task to the worker whose role matches, then the workers’ outputs are collected.
Mock is the default and free. Switch the Model toggle above to Real (your key) to run this same code on your own OpenAI-compatible model.
The routing structure is stable in both modes: a role is chosen, then
WORKERS[role] runs. In mock mode, sup.route(t) looks up the role from a
deterministic table. In real mode, parse_role maps the model’s free-text
classification to a role, defaulting to "text" for any non-conforming
output — the same fallback the mock uses for unknown tasks. The supervisor
decides who handles a task; the workers do the work. Coordination logic
and work must not mix.
Best practice: give the supervisor one job — routing — and keep workers independently testable. Coordination logic and work must not mix.
Next: Coordination Failure Modes