Bird
Raised Fist0
Agentic AIml~10 mins

Supervisor agent pattern in Agentic AI - Interactive Code Practice

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a supervisor agent that manages tasks.

Agentic AI
class SupervisorAgent:
    def __init__(self):
        self.tasks = []

    def add_task(self, task):
        self.tasks.[1](task)
Drag options to blanks, or click blank then click option'
Apop
Bremove
Cappend
Dclear
Attempts:
3 left
💡 Hint
Common Mistakes
Using remove instead of append will cause an error because the task is not yet in the list.
Using pop removes an item, which is not what we want here.
2fill in blank
medium

Complete the code to have the supervisor agent execute all tasks.

Agentic AI
class SupervisorAgent:
    def __init__(self):
        self.tasks = []

    def execute_all(self):
        for task in self.tasks:
            task.[1]()
Drag options to blanks, or click blank then click option'
Aexecute
Brun
Cperform
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using run or start may not match the task's method name.
Using perform is uncommon and may cause an AttributeError.
3fill in blank
hard

Fix the error in the supervisor agent's task removal method.

Agentic AI
class SupervisorAgent:
    def __init__(self):
        self.tasks = []

    def remove_task(self, task):
        if task in self.tasks:
            self.tasks.[1](task)
        else:
            print("Task not found")
Drag options to blanks, or click blank then click option'
Adelete
Bremove
Cpop
Ddiscard
Attempts:
3 left
💡 Hint
Common Mistakes
Using delete causes a syntax error.
Using pop requires an index, not a value.
4fill in blank
hard

Fill both blanks to create a dictionary of task statuses.

Agentic AI
task_status = {task.[1]: task.[2] for task in supervisor.tasks}
Drag options to blanks, or click blank then click option'
Aname
Bstatus
Cresult
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using result instead of status may not reflect the current task state.
Using id as key is possible but name is more readable.
5fill in blank
hard

Fill all three blanks to filter and collect completed tasks.

Agentic AI
completed_tasks = [task for task in supervisor.tasks if task.[1] == [2]]
completed_names = [task.[3] for task in completed_tasks]
Drag options to blanks, or click blank then click option'
Astatus
B'completed'
Cname
Dresult
Attempts:
3 left
💡 Hint
Common Mistakes
Using result instead of name for collecting task identifiers.
Comparing status to a wrong string value.

Practice

(1/5)
1. What is the main role of a Supervisor agent in the supervisor agent pattern?
easy
A. To collect raw data from sensors
B. To train a single AI model
C. To replace all other agents with one
D. To manage and coordinate multiple AI agents

Solution

  1. Step 1: Understand the supervisor agent's purpose

    The supervisor agent is designed to oversee and coordinate multiple AI agents working together.
  2. Step 2: Differentiate from other roles

    Unlike training or data collection, the supervisor agent focuses on managing teamwork and quality control.
  3. Final Answer:

    To manage and coordinate multiple AI agents -> Option D
  4. Quick Check:

    Supervisor agent = manager of multiple agents [OK]
Hint: Supervisor agent = team manager of AI agents [OK]
Common Mistakes:
  • Confusing supervisor with data collector
  • Thinking supervisor trains models directly
  • Assuming supervisor replaces all agents
2. Which of the following is the correct way to describe the supervisor agent's function in code?
easy
A. supervisor.replace_agents()
B. supervisor.train_single_model(data)
C. supervisor.collect_results(agents)
D. supervisor.ignore_agent_outputs()

Solution

  1. Step 1: Identify supervisor's interaction with agents

    The supervisor collects and evaluates results from multiple agents, so a method like collect_results fits.
  2. Step 2: Eliminate incorrect options

    Training a single model, replacing agents, or ignoring outputs do not match the supervisor's coordination role.
  3. Final Answer:

    supervisor.collect_results(agents) -> Option C
  4. Quick Check:

    Supervisor collects results = collect_results() [OK]
Hint: Supervisor collects and evaluates agent outputs [OK]
Common Mistakes:
  • Choosing training method instead of collection
  • Thinking supervisor replaces agents
  • Ignoring outputs contradicts supervisor role
3. Given this code snippet for a supervisor agent pattern, what will be the printed output?
class Agent:
    def __init__(self, name, score):
        self.name = name
        self.score = score

class Supervisor:
    def __init__(self, agents):
        self.agents = agents
    def best_agent(self):
        return max(self.agents, key=lambda a: a.score).name

agents = [Agent('A1', 85), Agent('A2', 90), Agent('A3', 88)]
supervisor = Supervisor(agents)
print(supervisor.best_agent())
medium
A. A1
B. A2
C. A3
D. None

Solution

  1. Step 1: Understand the agent scores

    Agents have scores: A1=85, A2=90, A3=88.
  2. Step 2: Identify the agent with the highest score

    The best_agent method returns the name of the agent with the max score, which is A2 with 90.
  3. Final Answer:

    A2 -> Option B
  4. Quick Check:

    Max score agent = A2 [OK]
Hint: Max score agent name is printed [OK]
Common Mistakes:
  • Choosing agent with second highest score
  • Confusing agent names
  • Assuming None if not found
4. Identify the bug in this supervisor agent code snippet:
class Supervisor:
    def __init__(self, agents):
        self.agents = agents
    def best_score(self):
        return max(self.agents, key=lambda a: a.score)

agents = [{'name': 'A1', 'score': 80}, {'name': 'A2', 'score': 95}]
supervisor = Supervisor(agents)
print(supervisor.best_score())
medium
A. Agents should be objects, not dictionaries
B. max() function is used incorrectly
C. Missing return statement in best_score
D. Supervisor class missing __init__ method

Solution

  1. Step 1: Check agent data type and usage

    The best_score method expects agents with attribute score, but agents are dictionaries, not objects.
  2. Step 2: Understand attribute vs key access

    Using a.score on a dictionary causes an error; dictionaries need a['score'].
  3. Final Answer:

    Agents should be objects, not dictionaries -> Option A
  4. Quick Check:

    Attribute access on dict causes error [OK]
Hint: Use objects or adjust attribute access for dicts [OK]
Common Mistakes:
  • Thinking max() usage is wrong
  • Missing return statement (it exists)
  • Ignoring data type mismatch
5. You want to design a supervisor agent that combines outputs from three different AI agents solving a complex task. Which approach best fits the supervisor agent pattern?
hard
A. Collect outputs, evaluate quality, and select the best result
B. Run only the fastest agent and ignore others
C. Train all agents on the same data independently
D. Replace all agents with a single large model

Solution

  1. Step 1: Understand supervisor agent's coordination role

    The supervisor should gather outputs from all agents and decide which is best based on quality.
  2. Step 2: Evaluate other options

    Ignoring agents, training independently without coordination, or replacing agents contradict the supervisor pattern.
  3. Final Answer:

    Collect outputs, evaluate quality, and select the best result -> Option A
  4. Quick Check:

    Supervisor = collect + evaluate + select best [OK]
Hint: Supervisor picks best output from all agents [OK]
Common Mistakes:
  • Ignoring some agents' outputs
  • Confusing training with supervising
  • Replacing agents instead of coordinating