Event objects. All events share the same Event class and are distinguished by their type field using the EventType enum.
EventType values
EventType | When emitted | Description |
|---|---|---|
USER_MESSAGE | User input persisted by Runner | The user’s message at the start of a turn |
AGENT_MESSAGE | Agent response | Final answers, thoughts, tool call requests, or partial streaming chunks |
TOOL_RESPONSE | Tool execution result | The result returned by a tool after execution |
AGENT_START | Start of astream() | Marks the beginning of an agent’s execution |
AGENT_END | End of astream() | Marks the end of an agent’s execution |
Convenience properties
| Property | Type | Description |
|---|---|---|
event.text | str | Concatenated text from all text parts in the event’s content |
event.data | dict | None | First data part’s dict, or None |
event.tool_name | str | None | Name of the tool (for TOOL_RESPONSE events) |
event.tool_input | dict | None | Input arguments passed to the tool |
event.tool_calls | list[dict] | List of tool call requests from the LLM response |
event.has_tool_calls | bool | True if the event contains tool call requests |
event.error | str | None | Error message, if the event represents an error |
Key methods
| Method | Description |
|---|---|
event.is_final_response() | Returns True if this is the agent’s final answer (an AGENT_MESSAGE with no tool calls and not a partial streaming chunk) |
event.to_langchain_message() | Converts the event to the corresponding LangChain message type (HumanMessage, AIMessage, ToolMessage, etc.) |
Event.from_langchain_message(msg) | Class method that creates an Event from a LangChain message |
Checking event types
Use theEventType enum and convenience methods instead of isinstance checks:
Metadata conventions
Events use themetadata dict for additional context. Common keys:
| Key | Description |
|---|---|
react_step | The ReAct loop iteration number |
error | Error message string when something went wrong |
exception_type | The Python exception class name (e.g. "ValueError") |
scratchpad | Internal reasoning or planning notes from the agent |
EventActions
Events carryEventActions for side-effects:
LlmResponse
AGENT_MESSAGE events may carry an llm_response: LlmResponse field with token usage and model version: