> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Display Module

> Display and formatting utilities for agent interactions

# 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

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import (
    display_interaction,
    display_self_reflection,
    display_instruction,
    display_tool_call,
    display_error,
    display_generating,
    clean_triple_backticks,
    register_display_callback,
    sync_display_callbacks,
    async_display_callbacks
)
```

## Display Functions

### display\_interaction

Displays an interaction between agents or between an agent and a user.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def display_interaction(
    sender: str,
    receiver: str,
    message: str,
    sender_type: str = "agent",
    receiver_type: str = "agent"
) -> None
```

**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:**

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
display_interaction(
    sender="ResearchAgent",
    receiver="WriterAgent",
    message="I've found 5 relevant sources on AI ethics.",
    sender_type="agent",
    receiver_type="agent"
)
```

### display\_self\_reflection

Displays an agent's self-reflection or internal thoughts.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def display_self_reflection(
    agent_name: str,
    reflection: str
) -> None
```

**Parameters:**

* `agent_name` (str): Name of the agent performing self-reflection
* `reflection` (str): The reflection content

**Example:**

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
display_self_reflection(
    agent_name="AnalysisAgent",
    reflection="The data suggests a trend, but I should verify with additional sources."
)
```

### display\_instruction

Displays instructions given to an agent.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def display_instruction(
    agent_name: str,
    instruction: str
) -> None
```

**Parameters:**

* `agent_name` (str): Name of the agent receiving the instruction
* `instruction` (str): The instruction content

**Example:**

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
display_instruction(
    agent_name="DataAgent",
    instruction="Analyze the sales data from Q4 2023 and identify key trends."
)
```

### display\_tool\_call

Displays a tool being called by an agent.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def display_tool_call(
    agent_name: str,
    tool_name: str,
    parameters: Optional[Dict[str, Any]] = None,
    result: Optional[Any] = None
) -> None
```

**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:**

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
display_tool_call(
    agent_name="SearchAgent",
    tool_name="web_search",
    parameters={"query": "latest AI research papers"},
    result="Found 10 relevant papers..."
)
```

### display\_error

Displays an error message with proper formatting.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def display_error(
    error_type: str,
    error_message: str,
    agent_name: Optional[str] = None
) -> None
```

**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:**

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
display_error(
    error_type="APIError",
    error_message="Rate limit exceeded. Please try again later.",
    agent_name="WeatherAgent"
)
```

### display\_generating

Displays a generating/thinking indicator for long-running operations.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def display_generating(
    agent_name: str,
    action: str = "Thinking"
) -> None
```

**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:**

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
display_generating(
    agent_name="CodeAgent",
    action="Generating code solution"
)
```

### clean\_triple\_backticks

Removes triple backticks from code blocks for clean display.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def clean_triple_backticks(text: str) -> str
```

**Parameters:**

* `text` (str): Text containing triple backticks

**Returns:**

* `str`: Text with triple backticks removed

**Example:**

````python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
code = """```python
def hello():
    print("Hello World")
```"""

clean_code = clean_triple_backticks(code)
# Returns: "def hello():\n    print(\"Hello World\")"
````

## Callback Functions

### register\_display\_callback

Registers a custom display callback function for handling display events.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def register_display_callback(
    callback: Callable,
    event_types: Optional[List[str]] = None
) -> None
```

**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:**

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def custom_logger(event_type, data):
    print(f"[{event_type}] {data}")

register_display_callback(
    callback=custom_logger,
    event_types=["interaction", "error"]
)
```

### sync\_display\_callbacks

Context manager for synchronous display callbacks.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
@contextmanager
def sync_display_callbacks() -> None
```

**Example:**

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
with sync_display_callbacks():
    # All display events within this context will be processed synchronously
    agent.run("Analyze the data")
```

### async\_display\_callbacks

Context manager for asynchronous display callbacks.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
@asynccontextmanager
async def async_display_callbacks() -> None
```

**Example:**

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
async with async_display_callbacks():
    # All display events within this context will be processed asynchronously
    await agent.arun("Analyze the data")
```

## Error Logging

### error\_logs

Retrieves error logs for debugging and monitoring.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def error_logs(
    agent_name: Optional[str] = None,
    limit: Optional[int] = None,
    error_type: Optional[str] = None
) -> List[Dict[str, Any]]
```

**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:**

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Get all error logs
all_errors = error_logs()

# Get last 10 errors for a specific agent
agent_errors = error_logs(agent_name="DataAgent", limit=10)

# Get all API errors
api_errors = error_logs(error_type="APIError")
```

## 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

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import (
    Agent,
    display_instruction,
    display_generating,
    display_interaction,
    display_error,
    register_display_callback,
    error_logs
)

# Register a custom logger
def log_to_file(event_type, data):
    with open("agent_logs.txt", "a") as f:
        f.write(f"[{event_type}] {data}\n")

register_display_callback(log_to_file)

# Create and run agent
agent = Agent(name="AnalysisAgent", instructions="Analyze data trends")

# Display the instruction
display_instruction("AnalysisAgent", "Analyze Q4 sales data")

# Show processing
display_generating("AnalysisAgent", "Analyzing data")

try:
    result = agent.run("What are the key trends in Q4?")
    display_interaction("User", "AnalysisAgent", "What are the key trends in Q4?", "user", "agent")
    display_interaction("AnalysisAgent", "User", result, "agent", "user")
except Exception as e:
    display_error("RuntimeError", str(e), "AnalysisAgent")

# Check for errors
errors = error_logs(agent_name="AnalysisAgent")
if errors:
    print(f"Found {len(errors)} errors")
```

## See Also

* [Agent Module](/docs/sdk/praisonaiagents/agent/agent)
* [Task Module](/docs/sdk/praisonaiagents/task/task)
* [Callbacks Concept](/docs/concepts/callbacks)
* [Telemetry Documentation](/docs/features/telemetry)
