Display Functions
The display functions provide a standardized way to format and display agent interactions, tool calls, reflections, and other outputs in PraisonAI. These utilities ensure consistent formatting across all agent interactions.Import
Display Functions
display_interaction
Displays an interaction between agents or between an agent and a user.sender
(str): Name of the senderreceiver
(str): Name of the receivermessage
(str): The message contentsender_type
(str, optional): Type of sender (“agent” or “user”). Defaults to “agent”receiver_type
(str, optional): Type of receiver (“agent” or “user”). Defaults to “agent”
display_self_reflection
Displays an agent’s self-reflection or internal thoughts.agent_name
(str): Name of the agent performing self-reflectionreflection
(str): The reflection content
display_instruction
Displays instructions given to an agent.agent_name
(str): Name of the agent receiving the instructioninstruction
(str): The instruction content
display_tool_call
Displays a tool being called by an agent.agent_name
(str): Name of the agent calling the tooltool_name
(str): Name of the tool being calledparameters
(Dict[str, Any], optional): Parameters passed to the toolresult
(Any, optional): Result returned by the tool
display_error
Displays an error message with proper formatting.error_type
(str): Type of error (e.g., “ValidationError”, “ConnectionError”)error_message
(str): The error messageagent_name
(str, optional): Name of the agent that encountered the error
display_generating
Displays a generating/thinking indicator for long-running operations.agent_name
(str): Name of the agent that is processingaction
(str, optional): Description of what the agent is doing. Defaults to “Thinking”
clean_triple_backticks
Removes triple backticks from code blocks for clean display.text
(str): Text containing triple backticks
str
: Text with triple backticks removed
Callback Functions
register_display_callback
Registers a custom display callback function for handling display events.callback
(Callable): The callback function to registerevent_types
(List[str], optional): List of event types to register for. If None, registers for all events
"interaction"
: Agent-to-agent or agent-to-user interactions"reflection"
: Self-reflection events"instruction"
: Instruction events"tool_call"
: Tool calling events"error"
: Error events"generating"
: Processing/generating events
sync_display_callbacks
Context manager for synchronous display callbacks.async_display_callbacks
Context manager for asynchronous display callbacks.Error Logging
error_logs
Retrieves error logs for debugging and monitoring.agent_name
(str, optional): Filter logs by agent namelimit
(int, optional): Maximum number of logs to returnerror_type
(str, optional): Filter logs by error type
List[Dict[str, Any]]
: List of error log entries
Best Practices
- Consistent Display: Use display functions instead of print() for consistent formatting
- Error Handling: Always use display_error() for errors to ensure they’re properly logged
- Custom Callbacks: Register callbacks early in your application lifecycle
- Performance: Use async callbacks for high-volume display events
- Debugging: Use error_logs() to retrieve historical error information