Module praisonaiagents.task.task

Classes

Task

Represents a task to be executed by an agent.

Parameters

  • description: str - Task description
  • expected_output: str - Expected output description
  • agent: Agent | None = None - Agent assigned to the task
  • name: str | None = None - Task name
  • tools: List[Any] | None = None - Tools available for the task
  • context: List[Task] | None = None - Context from other tasks
  • async_execution: bool | None = False - Enable async execution
  • config: Dict[str, Any] | None = None - Task configuration
  • output_file: str | None = None - Output file path
  • output_json: Type[BaseModel] | None = None - JSON output schema
  • output_pydantic: Type[BaseModel] | None = None - Pydantic output schema
  • callback: Any | None = None - Task callback
  • status: str = 'not started' - Task status
  • result: TaskOutput | None = None - Task result
  • create_directory: bool | None = False - Create output directory
  • id: int | None = None - Task ID
  • images: List[str] | None = None - Task images
  • next_tasks: List[str] | None = None - Next tasks
  • task_type: str = 'task' - Task type
  • condition: Dict[str, List[str]] | None = None - Task conditions
  • is_start: bool = False - Is start task
  • loop_state: Dict[str, str | int] | None = None - Loop state

Async Support

The Task class supports asynchronous execution through the following features:

  • async_execution: Boolean flag to enable async execution
  • callback: Supports both sync and async callback functions
  • execute_callback: Internal async method for handling callbacks

Example usage:

from typing import Coroutine
from praisonaiagents import Task, TaskOutput

# Define an async callback
async def async_callback(output: TaskOutput):
    await some_async_operation()
    print(f"Processed: {output.raw}")

# Create task with async execution
task = Task(
    description="Async task example",
    expected_output="Async result",
    async_execution=True,  # Enable async execution
    callback=async_callback  # Async callback
)

Callback Types

The Task class supports both synchronous and asynchronous callbacks:

# Type definition
callback: Optional[Union[
    Callable[[TaskOutput], Any],  # Sync callback
    Callable[[TaskOutput], Coroutine[Any, Any, Any]]  # Async callback
]]

Async Task States

  • not started: Initial state
  • in progress: Task is being executed
  • completed: Task finished successfully
  • failed: Task execution failed

Was this page helpful?