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 executedresult
(Any): The actual result of the task executionagent
(str): Name of the agent that executed the tasktask_id
(str, optional): Unique identifier for the taskstatus
(str, optional): Status of the task (“completed”, “failed”, “partial”). Defaults to “completed”metadata
(Dict[str, Any], optional): Additional metadata about the task executionexecution_time
(float, optional): Time taken to execute the task in secondserror
(str, optional): Error message if the task failed
Attributes
description
: Task descriptionresult
: Task resultagent
: Agent nametask_id
: Task identifierstatus
: Execution statusmetadata
: Additional metadataexecution_time
: Execution durationerror
: Error message (if any)timestamp
: Timestamp when the output was created
Methods
to_dict()
Converts the TaskOutput to a dictionary representation.Dict[str, Any]
: Dictionary containing all task output data
str()
Returns a string representation of the task output.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 contentagent
(str): Name of the agent performing the reflectionconfidence
(float, optional): Confidence level in the reflection (0.0 to 1.0). Defaults to 1.0insights
(List[str], optional): List of key insights from the reflectionimprovements
(List[str], optional): List of suggested improvementsmetadata
(Dict[str, Any], optional): Additional metadata about the reflection
Attributes
content
: Reflection contentagent
: Agent nameconfidence
: Confidence level (0.0-1.0)insights
: List of insightsimprovements
: List of improvementsmetadata
: Additional metadatatimestamp
: Timestamp when the reflection was created
Methods
to_dict()
Converts the ReflectionOutput to a dictionary representation.Dict[str, Any]
: Dictionary containing all reflection data
add_insight()
Adds a new insight to the reflection.insight
(str): The insight to add
add_improvement()
Adds a new improvement suggestion to the reflection.improvement
(str): The improvement suggestion to add
str()
Returns a string representation of the reflection output.str
: Human-readable string representation
Example Usage
Integration with Agents
Both output classes integrate seamlessly with PraisonAI agents:Best Practices
- Error Handling: Always check the
status
field in TaskOutput before using the result - Metadata Usage: Use metadata to store additional context that might be useful for debugging
- Confidence Levels: Use confidence levels in ReflectionOutput to gauge reliability
- Insights Management: Keep insights concise and actionable
- Serialization: Use
to_dict()
methods for saving outputs to databases or files