Learn how to create AI agents that orchestrate and distribute tasks among specialized workers.
A workflow with a central orchestrator directing multiple worker LLMs to perform subtasks, synthesizing their outputs for complex, coordinated operations.
Set your OpenAI API key as an environment variable in your terminal:
Copy
export OPENAI_API_KEY=your_api_key_here
3
Create a file
Create a new file app.py with the basic setup:
Copy
from praisonaiagents import Agent, Workflowfrom praisonaiagents.workflows import route# Create orchestrator agent that decides task routingorchestrator = Agent( name="Orchestrator", role="Task Orchestrator", goal="Analyze tasks and route to appropriate workers", instructions="Analyze the task. Respond with ONLY 'research', 'code', or 'writing' based on task type.")# Create specialized worker agentsresearch_worker = Agent( name="ResearchWorker", role="Research Specialist", goal="Conduct thorough research", instructions="You are a research specialist. Provide detailed research findings.")code_worker = Agent( name="CodeWorker", role="Software Developer", goal="Write and review code", instructions="You are a software developer. Write clean, efficient code.")writing_worker = Agent( name="WritingWorker", role="Content Writer", goal="Create written content", instructions="You are a content writer. Write clear, engaging content.")# Create synthesizer agentsynthesizer = Agent( name="Synthesizer", role="Result Synthesizer", goal="Synthesize and summarize results", instructions="Summarize the work completed and provide a final polished output.")# Create orchestrated workflowworkflow = Workflow( steps=[ orchestrator, # First, orchestrator decides routing route({ "research": [research_worker], "code": [code_worker], "writing": [writing_worker] }), synthesizer # Finally, synthesize results ])# Run orchestrated workflowresult = workflow.start("Create a Python function to calculate fibonacci numbers")print(f"Result: {result['output'][:500]}...")
4
Start Agents
Type this in your terminal to run your agents:
Copy
python app.py
Requirements
Python 3.10 or higher
OpenAI API key. Generate OpenAI API key here. Use Other models using this guide.