> ## Documentation Index
> Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Agentic Orchestrator Worker

> Learn how to create AI agents that orchestrate and distribute tasks among specialized workers.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
flowchart LR
    In[In] --> Router[LLM Call Router]
    Router --> LLM1[LLM Call 1]
    Router --> LLM2[LLM Call 2]
    Router --> LLM3[LLM Call 3]
    LLM1 --> Synthesizer[Synthesizer]
    LLM2 --> Synthesizer
    LLM3 --> Synthesizer
    Synthesizer --> Out[Out]
    
    style In fill:#8B0000,color:#fff
    style Router fill:#2E8B57,color:#fff
    style LLM1 fill:#2E8B57,color:#fff
    style LLM2 fill:#2E8B57,color:#fff
    style LLM3 fill:#2E8B57,color:#fff
    style Synthesizer fill:#2E8B57,color:#fff
    style Out fill:#8B0000,color:#fff
```

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

## Quick Start

<Steps>
  <Step title="Install Package">
    First, install the PraisonAI Agents package:

    ```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    pip install praisonaiagents
    ```
  </Step>

  <Step title="Set API Key">
    Set your OpenAI API key as an environment variable in your terminal:

    ```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    export OPENAI_API_KEY=your_api_key_here
    ```
  </Step>

  <Step title="Create a file">
    Create a new file `app.py` with the basic setup:

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonaiagents import Agent, AgentFlow
    from praisonaiagents 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 = AgentFlow(
        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]}...")
    ```
  </Step>

  <Step title="Start Agents">
    Type this in your terminal to run your agents:

    ```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    python app.py
    ```
  </Step>
</Steps>

<Note>
  **Requirements**

  * Python 3.10 or higher
  * OpenAI API key. Generate OpenAI API key [here](https://platform.openai.com/api-keys). Use Other models using [this guide](/models).
  * Basic understanding of Python
</Note>

## Understanding Orchestrator-Worker Pattern

<Card title="What is Orchestrator-Worker?" icon="question">
  Orchestrator-Worker pattern enables:

  * Dynamic task distribution and routing
  * Specialized worker execution
  * Result synthesis and aggregation
  * Coordinated workflow management
</Card>

## Features

<CardGroup cols={2}>
  <Card title="Task Routing" icon="route">
    Intelligently distribute tasks to specialized workers.
  </Card>

  <Card title="Worker Specialization" icon="user-gear">
    Dedicated agents for specific task types.
  </Card>

  <Card title="Result Synthesis" icon="object-group">
    Combine and process worker outputs effectively.
  </Card>

  <Card title="Process Control" icon="sliders">
    Monitor and manage the orchestrated workflow.
  </Card>
</CardGroup>

## Configuration Options

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# 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
      # 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

<CardGroup cols={2}>
  <Card title="Routing Issues" icon="triangle-exclamation">
    If task routing fails:

    * Check routing conditions
    * Verify worker availability
    * Enable verbose mode for debugging
  </Card>

  <Card title="Synthesis Flow" icon="diagram-project">
    If result synthesis is incorrect:

    * Review worker outputs
    * Check context connections
    * Verify synthesis logic
  </Card>
</CardGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="AutoAgents" icon="robot" href="./autoagents">
    Learn about automatically created and managed AI agents
  </Card>

  <Card title="Mini Agents" icon="microchip" href="./mini">
    Explore lightweight, focused AI agents
  </Card>
</CardGroup>

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