Back to Blog

Build AI Apps with Python: Multi-Agent Pipeline — Delegate Specialize Orchestrate | Episode 20

Celest KimCelest Kim

Video: Build AI Apps with Python: Multi-Agent Pipeline — Delegate Specialize Orchestrate | Episode 20 by Taught by Celeste AI - AI Coding Coach

Watch full page →

Build AI Apps with Python: Multi-Agent Pipeline — Delegate, Specialize, Orchestrate

Creating AI applications with multiple specialized agents can improve task quality and efficiency. This example demonstrates a supervisor agent that delegates subtasks to three specialized agents—a researcher, a writer, and a reviewer—each with distinct roles and prompts. The supervisor orchestrates their collaboration into a seamless pipeline producing a polished final report.

Code

class Agent:
  def __init__(self, name, system_prompt):
    self.name = name
    self.system_prompt = system_prompt

  def run(self, input_text):
    # Simulate processing based on role and input
    return f"{self.name} processed: {input_text}"

class Supervisor:
  def __init__(self):
    # Define specialized agents with focused system prompts
    self.researcher = Agent("Researcher", "Find 3 key facts about the topic.")
    self.writer = Agent("Writer", "Write a clear summary based on facts.")
    self.reviewer = Agent("Reviewer", "Check and improve the summary quality.")

  def handle_task(self, task):
    # Delegate to researcher
    facts = self.researcher.run(task)
    # Delegate to writer with research results
    summary = self.writer.run(facts)
    # Delegate to reviewer for final quality check
    final_report = self.reviewer.run(summary)
    return final_report

# Example usage
supervisor = Supervisor()
task = "Explain the benefits of multi-agent AI systems."
report = supervisor.handle_task(task)
print(report)

Key Points

  • Multi-agent systems use specialized agents to improve task accuracy and efficiency.
  • The supervisor pattern delegates subtasks to agents with distinct roles and prompts.
  • Chaining agents in a pipeline enables complex workflows like research, writing, and reviewing.
  • Each agent focuses on a specific part of the task, simplifying development and maintenance.
  • Orchestration by a supervisor ensures smooth collaboration and a high-quality final output.