Neural Mastery
← Practice
Supervisor Worker Routing Decisionmedium

Supervisor Worker Routing Decision

medium Agents in Production 15 min

NumPy allowed · plain Python earns 10 bonus points

Interactive
Graph & Tree Traversal, Step by Step
Structure
Algorithm
ABCDE
visiting A -> visited order so far: [A]
queue now: [B, C]
Step 1 / 5
Both modes run the real algorithm from the linked practice problem, one step at a time -- edit the graph or pick different tree nodes and every step recomputes live.

Implement supervisor-worker routing, the decision logic behind a real supervisor-pattern multi-agent graph directing each incoming task to the right specialist worker node.

Task

Implement supervisor_route(task_category, worker_specialties, default_worker). Find the first worker (checking worker_specialties keys in sorted order for determinism) whose specialty list contains task_category. Return that worker's name, or default_worker if none match.

Function Signature

supervisor_route(task_category: str, worker_specialties: dict[str, list[str]], default_worker: str) -> str

Examples

Example 1: matched to specialist
Input: task_category = 'coding' worker_specialties = {'coder': ['coding', 'debugging'], 'researcher': ['search']} default_worker = 'general'
Output: 'coder'
Example 2: no match uses default
Input: task_category = 'cooking' worker_specialties = {'coder': ['coding']} default_worker = 'general'
Output: 'general'
Example 3: multiple workers alphabetical priority
Input: task_category = 'x' worker_specialties = {'zeta': ['x'], 'alpha': ['x']} default_worker = 'general'
Output: 'alpha'

Constraints

  • worker_specialties maps worker name -> list of handled categories
Python3Saved ✓
def supervisor_route(task_category, worker_specialties, default_worker):
# Your implementation here
pass

Case 1: matched to specialist
Input: task_category = 'coding' worker_specialties = {'coder': ['coding', 'debugging'], 'researcher': ['search']} default_worker = 'general'
Expected: 'coder'
Case 2: no match uses default
Input: task_category = 'cooking' worker_specialties = {'coder': ['coding']} default_worker = 'general'
Expected: 'general'
Case 3: multiple workers alphabetical priority
Input: task_category = 'x' worker_specialties = {'zeta': ['x'], 'alpha': ['x']} default_worker = 'general'
Expected: 'alpha'