handleEvent callback receives events throughout the agent’s execution lifecycle. Use these events to track progress, display UI updates, or log agent activity.
Event Types
All events are discriminated by thetype field.
Start Event
Emitted when the agent begins execution.Event type identifier
Unique identifier for the agent instance
Number of messages in the conversation history
Error Event
Emitted when an error occurs during execution.Event type identifier
Error message describing what went wrong
Download Status Event
Emitted during model or dependency downloads.Event type identifier
Version being downloaded
Download completion status
Tool Call Event
Emitted when the agent calls a tool.Event type identifier
Unique identifier for this tool call
Name of the tool being called (e.g.,
write_file, run_terminal_command)Input parameters passed to the tool
ID of the agent making the call
ID of the parent agent (if this is a subagent)
Whether to include this tool call in the message history
Tool Result Event
Emitted when a tool call completes.Event type identifier
ID matching the original tool call
Name of the tool that executed
Array of output results from the tool execution
ID of the parent agent (if this is a subagent)
Text Event
Emitted when the agent generates text output.Event type identifier
Text content generated by the agent
ID of the agent generating the text
Finish Event
Emitted when the agent completes execution.Event type identifier
ID of the agent that finished
Total cost in credits for this execution
Subagent Start Event
Emitted when a subagent begins execution.Event type identifier
Unique identifier for the subagent instance
Type of the subagent (e.g.,
file_picker, researcher)Human-readable name for the subagent
Whether this is the only subagent in the current step
ID of the parent agent
Parameters passed to the subagent
Prompt given to the subagent
Subagent Finish Event
Emitted when a subagent completes execution.Event type identifier
ID of the subagent that finished
Type of the subagent
Human-readable name for the subagent
Whether this was the only subagent in the step
ID of the parent agent
Parameters that were passed to the subagent
Prompt that was given to the subagent
Reasoning Delta Event
Emitted during the agent’s reasoning process (streaming chunks).Event type identifier
Chunk of reasoning text
Array of ancestor agent run IDs
ID of the current agent run
Usage Example
Tool Result Output
Theoutput field in tool result events contains an array of output objects:
Type of the output content
JSON Output
JSON value returned by the tool
Media Output
Base64-encoded media data
MIME type of the media (e.g.,
image/png, application/pdf)
