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.

python
from praisonaiagents import Agent, Task, AgentTeam

researcher = Agent(name="Researcher", instructions="Research topics thoroughly")
writer = Agent(name="Writer", instructions="Write from research")
team = AgentTeam(
    agents=[researcher, writer],
    tasks=[
        Task(description="Research AI trends", agent=researcher),
        Task(description="Write the article", agent=writer),
    ],
    process="hierarchical",
)
team.start("Write a blog post about AI trends")

The user starts a hierarchical team run; retries and manager re-prompts recover parse and assignment errors automatically.

Diagram

Error Recovery Flow

✅ Yes

❌ Parse Error

⚠️ Invalid ID

📋 Manager Request

🧠 Parse & Validate

Success?

⚡ Execute Task

🔄 Retry with Backoff

📝 Re-prompt Manager

✅ Complete

Quick Start

  1. Create Hierarchical Workflow
    python
    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"
    )
  2. Start Workflow
    python
    # Error recovery happens automatically
    result = team.start()
    
    # If manager has parse errors or selects invalid IDs,
    # the system retries transparently
    print(result)

How It Works

Diagram
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

SettingValueDescription
MAX_MANAGER_RETRIES3Maximum parse error retries
MAX_INVALID_SELECTIONS3Maximum invalid ID re-prompts
Backoff timing2s, 4s, 8sExponential backoff delays

Error Recovery Types


Best Practices

Fail gracefully per branch

Isolate errors in parallel and loop steps so one failure does not abort unrelated work.

Surface errors in TaskOutput

Return structured error details agents and UIs can display instead of silent exceptions.

Combine with hooks for custom recovery

Use before/after hooks to retry, notify, or escalate when steps fail.

Test file and CSV loop errors

Verify missing input files produce clear TaskOutput messages before production runs.

Related