from praisonaiagents import Agent, Task, PraisonAIAgentsagent = Agent( name="Retry Agent", instructions="Process requests with retries")task = Task( description="Unreliable operation", agent=agent, max_retries=5, # Try up to 5 times retry_delay=2.0, # Start with 2 second delay # max_retry_delay defaults to 300 seconds)agents = PraisonAIAgents(agents=[agent], tasks=[task])result = agents.start()
2
Custom Retry Policy
from praisonaiagents import Tasktask = Task( description="Critical task with fast retries", max_retries=3, retry_delay=0.5, # Start with 0.5 second delay # Backoff: 0.5s, 1s, 2s (then fail))# Dependent tasks are skipped if this failsdependent_task = Task( description="Depends on critical task", context=[task] # Skipped if 'task' fails)
from praisonaiagents import Task# Aggressive retry policy for critical taskscritical_task = Task( description="Must succeed", max_retries=10, retry_delay=0.1, # Start very fast max_retry_delay=60 # Cap at 1 minute)# Conservative retry policy for expensive operations expensive_task = Task( description="Expensive API call", max_retries=2, retry_delay=30, # Start with 30 seconds max_retry_delay=300 # Cap at 5 minutes)
# Independent tasks - failure of one doesn't affect otherstask_a = Task(description="Independent work A", max_retries=2)task_b = Task(description="Independent work B", max_retries=2)# Dependent task - only runs if both succeedfinal_task = Task( description="Combine results", context=[task_a, task_b], # Skipped if either fails max_retries=1)
# Good: reasonable maximum delaytask = Task( description="API call", retry_delay=1, max_retry_delay=60 # Max 1 minute wait)# Avoid: excessively long delays# max_retry_delay=3600 # 1 hour is usually too long