Skip to main content
A workflow with a central orchestrator directing multiple worker LLMs to perform subtasks, synthesizing their outputs for complex, coordinated operations.

Quick Start

1

Install Package

First, install the PraisonAI Agents package:
pip install praisonaiagents
2

Set API Key

Set your OpenAI API key as an environment variable in your terminal:
export OPENAI_API_KEY=your_api_key_here
3

Create a file

Create a new file app.py with the basic setup:
from praisonaiagents import Agent, Workflow
from praisonaiagents.workflows import route

# Create orchestrator agent that decides task routing
orchestrator = 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 agents
research_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 agent
synthesizer = Agent(
    name="Synthesizer",
    role="Result Synthesizer",
    goal="Synthesize and summarize results",
    instructions="Summarize the work completed and provide a final polished output."
)

# Create orchestrated workflow
workflow = Workflow(
    steps=[
        orchestrator,  # First, orchestrator decides routing
        route({
            "research": [research_worker],
            "code": [code_worker],
            "writing": [writing_worker]
        }),
        synthesizer  # Finally, synthesize results
    ]
)

# Run orchestrated workflow
result = 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:
python app.py
Requirements
  • Python 3.10 or higher
  • OpenAI API key. Generate OpenAI API key here. Use Other models using this guide.
  • Basic understanding of Python

Understanding Orchestrator-Worker Pattern

What is Orchestrator-Worker?

Orchestrator-Worker pattern enables:
  • Dynamic task distribution and routing
  • Specialized worker execution
  • Result synthesis and aggregation
  • Coordinated workflow management

Features

Task Routing

Intelligently distribute tasks to specialized workers.

Worker Specialization

Dedicated agents for specific task types.

Result Synthesis

Combine and process worker outputs effectively.

Process Control

Monitor and manage the orchestrated workflow.

Configuration Options

# Create an orchestrator agent
router = Agent(
    name="Router",
    role="Task router",
    goal="Distribute tasks based on conditions",
    tools=[get_time_check],  # Tools for routing decisions
    verbose=True  # Enable detailed logging
)

# Create a worker agent
worker = Agent(
    name="Worker",
    role="Specialized worker",
    goal="Handle specific task type",
    instructions="Processing instructions"
)

# Create routing task
router_task = Task(
    name="route_task",
    description="Route tasks to workers",
    agent=router,
    is_start=True,
    task_type="decision",
    condition={
        "1": ["worker1_task"],
        "2": ["worker2_task"]
    }
)

# Create synthesis task
synthesis_task = Task(
    name="synthesize",
    description="Combine worker results",
    agent=synthesizer,
    context=[worker1_task, worker2_task]  # Reference worker tasks
)

Troubleshooting

Routing Issues

If task routing fails:
  • Check routing conditions
  • Verify worker availability
  • Enable verbose mode for debugging

Synthesis Flow

If result synthesis is incorrect:
  • Review worker outputs
  • Check context connections
  • Verify synthesis logic

Next Steps

For optimal results, ensure your routing logic is well-defined and your workers are properly configured for their specialized tasks.