Understanding Tasks

Tasks are units of work that agents execute. Each task has a clear goal, input requirements, and expected outputs.

Core Components

Task Definition

Clear description of work to be done and expected outputs

Agent Assignment

Matching tasks with capable agents

Tool Access

Resources available for task completion

Output Handling

Managing and formatting task results

Task Configuration

Understanding Tasks




Task Types

1

Basic Task

Simple, single-operation tasks with clear inputs and outputs

2

Decision Task

Tasks involving choices and conditional paths

decision_task = Task(
    type="decision",
    conditions={
        "success": ["next_task"],
        "failure": ["error_task"]
    }
)
3

Loop Task

Repetitive operations over collections

loop_task = Task(
    type="loop",
    items=data_list,
    operation="process_item"
)

Task Relationships

Properly managing task dependencies is crucial for complex workflows. Always ensure proper context sharing and error handling.

Context Sharing

task_a = Task(name="research")
task_b = Task(
    name="analyze",
    context=[task_a]  # Uses task_a's output
)

Task Dependencies

RelationshipDescriptionExample
SequentialTasks run one after anotherResearch → Analysis → Report
ParallelIndependent tasks run simultaneouslyData Collection + Processing
ConditionalTasks depend on previous resultsSuccess → Next Task, Failure → Retry

Advanced Features

Output Handling

  • Multiple output formats
  • Structured data validation
  • File system integration

Task Control

  • Execution flow control
  • Error recovery
  • Progress tracking

Getting Started

1

Install PraisonAI

Install the core package:

Terminal
pip install praisonaiagents
2

Configure Environment

Terminal
export OPENAI_API_KEY=your_openai_key

Generate your OpenAI API key from OpenAI Use other LLM providers like Ollama, Anthropic, Groq, Google, etc. Please refer to the Models for more information.

3

Create Agent

Create app.py:

Best Practices

Design tasks to be atomic and focused. Each task should have a single, clear responsibility.

Task Design Principles

Resource Management

Async Task Execution

Async Task Features

async_task = Task(
    description="Perform async operation",
    expected_output="Async result",
    agent=async_agent,
    async_execution=True,  # Enable async execution
    callback=async_callback  # Optional async callback
)
  • Enable async execution with async_execution=True
  • Perfect for I/O-heavy operations
  • Supports parallel task execution

Pro Tip: Use async execution for tasks that involve I/O operations (like API calls or file operations) to improve overall performance. Keep CPU-intensive tasks synchronous.

Next Steps

Was this page helpful?