Skip to main content

Output Classes

PraisonAI provides structured output classes for handling task results and agent reflections. These classes ensure consistent data formats across all agent operations.

Import

TaskOutput

Represents the output of a task execution, including the result, metadata, and execution details.

Class Definition

Parameters

  • description (str): Description of the task that was executed
  • result (Any): The actual result of the task execution
  • agent (str): Name of the agent that executed the task
  • task_id (str, optional): Unique identifier for the task
  • status (str, optional): Status of the task (“completed”, “failed”, “partial”). Defaults to “completed”
  • metadata (Dict[str, Any], optional): Additional metadata about the task execution
  • execution_time (float, optional): Time taken to execute the task in seconds
  • error (str, optional): Error message if the task failed

Attributes

  • description: Task description
  • result: Task result
  • agent: Agent name
  • task_id: Task identifier
  • status: Execution status
  • metadata: Additional metadata
  • execution_time: Execution duration
  • error: Error message (if any)
  • timestamp: Timestamp when the output was created

Methods

to_dict()

Converts the TaskOutput to a dictionary representation.
Returns:
  • Dict[str, Any]: Dictionary containing all task output data

str()

Returns a string representation of the task output.
Returns:
  • str: Human-readable string representation

Example Usage

ReflectionOutput

Represents the output of an agent’s self-reflection process, including insights and confidence levels.

Class Definition

Parameters

  • content (str): The main reflection content
  • agent (str): Name of the agent performing the reflection
  • confidence (float, optional): Confidence level in the reflection (0.0 to 1.0). Defaults to 1.0
  • insights (List[str], optional): List of key insights from the reflection
  • improvements (List[str], optional): List of suggested improvements
  • metadata (Dict[str, Any], optional): Additional metadata about the reflection

Attributes

  • content: Reflection content
  • agent: Agent name
  • confidence: Confidence level (0.0-1.0)
  • insights: List of insights
  • improvements: List of improvements
  • metadata: Additional metadata
  • timestamp: Timestamp when the reflection was created

Methods

to_dict()

Converts the ReflectionOutput to a dictionary representation.
Returns:
  • Dict[str, Any]: Dictionary containing all reflection data

add_insight()

Adds a new insight to the reflection.
Parameters:
  • insight (str): The insight to add

add_improvement()

Adds a new improvement suggestion to the reflection.
Parameters:
  • improvement (str): The improvement suggestion to add

str()

Returns a string representation of the reflection output.
Returns:
  • str: Human-readable string representation

Example Usage

Integration with Agents

Both output classes integrate seamlessly with PraisonAI agents:

Best Practices

  1. Error Handling: Always check the status field in TaskOutput before using the result
  2. Metadata Usage: Use metadata to store additional context that might be useful for debugging
  3. Confidence Levels: Use confidence levels in ReflectionOutput to gauge reliability
  4. Insights Management: Keep insights concise and actionable
  5. Serialization: Use to_dict() methods for saving outputs to databases or files

Example: Complete Workflow

See Also