Skip to main content

Overview

The EventType enum defines all possible events that can be emitted during agent execution. These events provide granular visibility into the agent’s processing, enabling real-time streaming, debugging, and monitoring.

Event Categories

LLM Interaction Events

str
Emitted when a request is sent to the language model.Event Data:
  • message_count (int): Number of messages in the context
  • model (str): The model being used
  • temperature (float): Temperature setting for the request
str
Emitted when a complete response is received from the language model.Event Data:
  • content (str): The response content
  • tool_calls (List[Dict]): Any tool calls in the response
  • tokens (Dict): Token usage with prompt_tokens, completion_tokens, total_tokens
  • latency_ms (float): Response time in milliseconds
str
Emitted for each chunk of content during streaming responses.Event Data:
  • content_chunk (str): The partial content chunk

Tool execution events

str
Emitted when a tool is selected for execution.Event Data:
  • tool_name (str): Name of the selected tool
  • arguments (Dict): Arguments passed to the tool
  • tool_call_id (str): Unique identifier for this tool call
str
Emitted when tool execution begins.Event Data:
  • tool_name (str): Name of the executing tool
  • tool_call_id (str): Tool call identifier
str
Emitted when a tool execution completes successfully.Event Data:
  • tool_name (str): Name of the tool
  • result (Any): The tool’s return value
  • duration_ms (float): Execution time in milliseconds
  • tool_call_id (str): Tool call identifier
str
Emitted when a tool execution fails.Event Data:
  • tool_name (str): Name of the tool
  • error (str): Error message
  • tool_call_id (str): Tool call identifier

Message Management Events

str
Emitted when a new message is added to the thread.Event Data:
  • message (Message): The complete message object

Control Flow Events

str
Emitted at the beginning of each agent iteration.Event Data:
  • iteration_number (int): Current iteration number (0-based)
  • max_iterations (int): Maximum allowed iterations
str
Emitted when the maximum iteration limit is reached.Event Data:
  • iterations_used (int): Total number of iterations used
str
Emitted when an error occurs during execution.Event Data:
  • error_type (str): Type of error (e.g., exception class name)
  • message (str): Error message
  • traceback (Optional[str]): Stack trace if available
str
Emitted when agent execution completes.Event Data:
  • duration_ms (float): Total execution time in milliseconds
  • total_tokens (int): Total tokens used across all LLM calls

Usage Examples

Basic Event Handling

Event Counting

Performance Monitoring

Custom Event Handlers

Event Flow

The typical sequence of events during agent execution:
  1. ITERATION_START - Processing begins
  2. LLM_REQUEST - Request sent to language model
  3. LLM_STREAM_CHUNK (multiple) - If streaming, content chunks arrive
  4. LLM_RESPONSE - Complete response received
  5. MESSAGE_CREATED - Assistant message added to thread
  6. If tool calls:
    • TOOL_SELECTED - For each tool to be called
    • TOOL_EXECUTING - Tool execution begins
    • TOOL_RESULT or TOOL_ERROR - Tool completes
    • MESSAGE_CREATED - Tool message added
  7. Repeat from step 2 if more iterations needed
  8. EXECUTION_COMPLETE - All processing finished

See Also

  • ExecutionEvent - The event object structure
  • Agent - Agent streaming documentation
  • Thread - Thread methods for accessing execution information