> ## 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.

# Workflow Error Recovery

> Automatic retries and re-prompting in hierarchical workflows

Hierarchical workflows automatically handle common failure modes with built-in retry mechanisms and intelligent error recovery.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    subgraph "Error Recovery Flow"
        Input[📋 Manager Request] --> Process[🧠 Parse & Validate]
        Process --> Check{Success?}
        Check -->|✅ Yes| Execute[⚡ Execute Task]
        Check -->|❌ Parse Error| Retry[🔄 Retry with Backoff]
        Check -->|⚠️ Invalid ID| Reprompt[📝 Re-prompt Manager]
        Retry --> Process
        Reprompt --> Process
        Execute --> Output[✅ Complete]
    end
    
    classDef input fill:#6366F1,stroke:#7C90A0,color:#fff
    classDef process fill:#F59E0B,stroke:#7C90A0,color:#fff
    classDef output fill:#10B981,stroke:#7C90A0,color:#fff
    
    class Input input
    class Process,Check,Retry,Reprompt process
    class Execute,Output output
```

## Quick Start

<Steps>
  <Step title="Create Hierarchical Workflow">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonaiagents import Agent, Task, AgentTeam

    # Create agents
    researcher = Agent(
        name="Researcher",
        role="Research Analyst", 
        instructions="Conduct thorough research on topics"
    )

    writer = Agent(
        name="Writer",
        role="Content Writer",
        instructions="Write engaging content based on research"
    )

    # Create tasks
    research_task = Task(
        description="Research AI trends",
        agent=researcher
    )

    write_task = Task(
        description="Write article about AI trends", 
        agent=writer
    )

    # Create team with hierarchical process (enables error recovery)
    team = AgentTeam(
        agents=[researcher, writer],
        tasks=[research_task, write_task],
        process="hierarchical",
        manager_llm="gpt-4o"
    )
    ```
  </Step>

  <Step title="Start Workflow">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    # Error recovery happens automatically
    result = team.start()

    # If manager has parse errors or selects invalid IDs,
    # the system retries transparently
    print(result)
    ```
  </Step>
</Steps>

***

## How It Works

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant PraisonAIAgents
    participant Manager as Manager LLM
    participant Worker as Worker Agent

    User->>PraisonAIAgents: start()
    
    loop Manager Retry (up to 3x)
        PraisonAIAgents->>Manager: Request task assignment
        Manager-->>PraisonAIAgents: Response (JSON)
        
        alt Parse Success
            PraisonAIAgents->>PraisonAIAgents: Validate task ID
            alt Valid Task ID
                PraisonAIAgents->>Worker: Execute task
                Worker-->>PraisonAIAgents: Task complete
            else Invalid Task ID (up to 3x)
                PraisonAIAgents->>Manager: Re-prompt with valid IDs
            end
        else Parse Error
            Note over PraisonAIAgents: Wait 2s, 4s, 8s (exponential backoff)
        end
    end
    
    PraisonAIAgents-->>User: Final result or error
    
    classDef user fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef system fill:#189AB4,stroke:#7C90A0,color:#fff
    classDef llm fill:#10B981,stroke:#7C90A0,color:#fff
    
    class User user
    class PraisonAIAgents system
    class Manager,Worker llm
```

***

## Configuration Options

| Setting                  | Value        | Description                   |
| ------------------------ | ------------ | ----------------------------- |
| `MAX_MANAGER_RETRIES`    | `3`          | Maximum parse error retries   |
| `MAX_INVALID_SELECTIONS` | `3`          | Maximum invalid ID re-prompts |
| Backoff timing           | `2s, 4s, 8s` | Exponential backoff delays    |

<Note>
  These constants are not user-configurable today; they are SDK defaults designed for optimal reliability. Future versions may expose configuration options.
</Note>

### Error Recovery Types

<CardGroup cols={3}>
  <Card title="Parse Failures" icon="code">
    **When**: Manager LLM returns invalid JSON
    **Recovery**: Retry with exponential backoff
    **Max**: 3 attempts before abort
  </Card>

  <Card title="Invalid Task IDs" icon="list">
    **When**: Manager selects non-existent task
    **Recovery**: Re-prompt with valid ID list
    **Max**: 3 attempts before abort
  </Card>

  <Card title="Loop File Errors" icon="file">
    **When**: Cannot read loop input file
    **Recovery**: Mark task as failed with error
    **Visibility**: Error shown in TaskOutput
  </Card>
</CardGroup>

***

## Related

<CardGroup cols={2}>
  <Card title="Process Types" icon="diagram-project" href="/concepts/process">
    Understanding hierarchical processes
  </Card>

  <Card title="Hooks" icon="anchor" href="/concepts/hooks">
    Custom error handling with hooks
  </Card>
</CardGroup>
