Overview
TheEventType
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
Emitted when a request is sent to the language model.Event Data:
message_count
(int): Number of messages in the contextmodel
(str): The model being usedtemperature
(float): Temperature setting for the request
Emitted when a complete response is received from the language model.Event Data:
content
(str): The response contenttool_calls
(List[Dict]): Any tool calls in the responsetokens
(Dict): Token usage withprompt_tokens
,completion_tokens
,total_tokens
latency_ms
(float): Response time in milliseconds
Emitted for each chunk of content during streaming responses.Event Data:
content_chunk
(str): The partial content chunk
Tool execution events
Emitted when a tool is selected for execution.Event Data:
tool_name
(str): Name of the selected toolarguments
(Dict): Arguments passed to the tooltool_call_id
(str): Unique identifier for this tool call
Emitted when tool execution begins.Event Data:
tool_name
(str): Name of the executing tooltool_call_id
(str): Tool call identifier
Emitted when a tool execution completes successfully.Event Data:
tool_name
(str): Name of the toolresult
(Any): The tool’s return valueduration_ms
(float): Execution time in millisecondstool_call_id
(str): Tool call identifier
Emitted when a tool execution fails.Event Data:
tool_name
(str): Name of the toolerror
(str): Error messagetool_call_id
(str): Tool call identifier
Message Management Events
Emitted when a new message is added to the thread.Event Data:
message
(Message): The complete message object
Control Flow Events
Emitted at the beginning of each agent iteration.Event Data:
iteration_number
(int): Current iteration number (0-based)max_iterations
(int): Maximum allowed iterations
Emitted when the maximum iteration limit is reached.Event Data:
iterations_used
(int): Total number of iterations used
Emitted when an error occurs during execution.Event Data:
error_type
(str): Type of error (e.g., exception class name)message
(str): Error messagetraceback
(Optional[str]): Stack trace if available
Emitted when agent execution completes.Event Data:
duration_ms
(float): Total execution time in millisecondstotal_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:ITERATION_START
- Processing beginsLLM_REQUEST
- Request sent to language modelLLM_STREAM_CHUNK
(multiple) - If streaming, content chunks arriveLLM_RESPONSE
- Complete response receivedMESSAGE_CREATED
- Assistant message added to thread- If tool calls:
TOOL_SELECTED
- For each tool to be calledTOOL_EXECUTING
- Tool execution beginsTOOL_RESULT
orTOOL_ERROR
- Tool completesMESSAGE_CREATED
- Tool message added
- Repeat from step 2 if more iterations needed
EXECUTION_COMPLETE
- All processing finished
See Also
- ExecutionEvent - The event object structure
- Agent - Agent streaming documentation
- Thread - Thread methods for accessing execution information