Skip to main content

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.
Parameters:
  • sender (str): Name of the sender
  • receiver (str): Name of the receiver
  • message (str): The message content
  • sender_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”
Example:

display_self_reflection

Displays an agent’s self-reflection or internal thoughts.
Parameters:
  • agent_name (str): Name of the agent performing self-reflection
  • reflection (str): The reflection content
Example:

display_instruction

Displays instructions given to an agent.
Parameters:
  • agent_name (str): Name of the agent receiving the instruction
  • instruction (str): The instruction content
Example:

display_tool_call

Displays a tool being called by an agent.
Parameters:
  • agent_name (str): Name of the agent calling the tool
  • tool_name (str): Name of the tool being called
  • parameters (Dict[str, Any], optional): Parameters passed to the tool
  • result (Any, optional): Result returned by the tool
Example:

display_error

Displays an error message with proper formatting.
Parameters:
  • error_type (str): Type of error (e.g., “ValidationError”, “ConnectionError”)
  • error_message (str): The error message
  • agent_name (str, optional): Name of the agent that encountered the error
Example:

display_generating

Displays a generating/thinking indicator for long-running operations.
Parameters:
  • agent_name (str): Name of the agent that is processing
  • action (str, optional): Description of what the agent is doing. Defaults to “Thinking”
Example:

clean_triple_backticks

Removes triple backticks from code blocks for clean display.
Parameters:
  • text (str): Text containing triple backticks
Returns:
  • str: Text with triple backticks removed
Example:

Callback Functions

register_display_callback

Registers a custom display callback function for handling display events.
Parameters:
  • callback (Callable): The callback function to register
  • event_types (List[str], optional): List of event types to register for. If None, registers for all events
Event Types:
  • "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
Example:

sync_display_callbacks

Context manager for synchronous display callbacks.
Example:

async_display_callbacks

Context manager for asynchronous display callbacks.
Example:

Error Logging

error_logs

Retrieves error logs for debugging and monitoring.
Parameters:
  • agent_name (str, optional): Filter logs by agent name
  • limit (int, optional): Maximum number of logs to return
  • error_type (str, optional): Filter logs by error type
Returns:
  • List[Dict[str, Any]]: List of error log entries
Example:

Best Practices

  1. Consistent Display: Use display functions instead of print() for consistent formatting
  2. Error Handling: Always use display_error() for errors to ensure they’re properly logged
  3. Custom Callbacks: Register callbacks early in your application lifecycle
  4. Performance: Use async callbacks for high-volume display events
  5. Debugging: Use error_logs() to retrieve historical error information

Example: Complete Display Flow

See Also