The Orchestrator workflow uses an LLM to break down complex tasks into manageable subtasks, assign them to appropriate specialized agents, and aggregate the results. It’s ideal for sophisticated, multi-step operations where the optimal task breakdown isn’t known in advance.
Orchestrators automatically generate planning prompts based on available agent capabilities, enabling dynamic task decomposition.
import asynciofrom fast_agent import FastAgentfast = FastAgent("Orchestrator-Workers")# Define specialized worker agents@fast.agent( name="finder", instruction="""You are an agent with access to the filesystem and URL fetching. Your job is to identify the closest match to a user's request, make the appropriate tool calls, and return the URI and CONTENTS of the closest match.""", servers=["fetch", "filesystem"], model="gpt-4.1",)@fast.agent( name="writer", instruction="""You are an agent that can write to the filesystem. You are tasked with taking the user's input, addressing it, and writing the result to disk in the appropriate location.""", servers=["filesystem"],)@fast.agent( name="proofreader", instruction="""Review text for grammar, spelling, and punctuation errors. Identify any awkward phrasing or structural issues that could improve clarity. Provide detailed feedback on corrections.""", servers=["fetch"], model="gpt-4.1",)# Define the orchestrator to coordinate the workers@fast.iterative_planner( name="orchestrate", agents=["finder", "writer", "proofreader"], model="sonnet", plan_iterations=5,)async def main() -> None: async with fast.run() as agent: task = """Load the student's short story from short_story.md, and generate a report with feedback across proofreading, factuality/logical consistency and style adherence. Use the style rules from https://apastyle.apa.org/learn/quick-guide-on-formatting and https://apastyle.apa.org/learn/quick-guide-on-references. Write the graded report to graded_report.md in the same directory as short_story.md""" await agent.orchestrate(task)if __name__ == "__main__": asyncio.run(main())
@fast.agent( "web_researcher", instruction="Search the web and gather relevant information", servers=["fetch"],)@fast.agent( "data_analyzer", instruction="Analyze data and identify patterns and insights",)@fast.agent( "report_writer", instruction="Write comprehensive, well-structured reports", servers=["filesystem"],)@fast.agent( "fact_checker", instruction="Verify facts and check for inconsistencies", servers=["fetch"],)@fast.orchestrator( name="research_orchestrator", agents=["web_researcher", "data_analyzer", "report_writer", "fact_checker"], model="sonnet", plan_type="full",)async def main() -> None: async with fast.run() as agent: await agent.research_orchestrator.send( """Research the current state of quantum computing, analyze key developments, verify all claims, and produce a comprehensive report saved to quantum_report.md""" )
Enable detailed logging to see the execution plan:
import logginglogging.basicConfig(level=logging.DEBUG)# You'll see:# DEBUG: Orchestrator generated plan:# 1. Use 'finder' to locate short_story.md# 2. Use 'proofreader' to review the story# 3. Use 'writer' to create graded_report.md