pub enum AgentEvent {
AgentStart,
AgentEnd {
messages: Vec<AgentMessage>,
},
RetryScheduled {
attempt: u32,
max_retries: u32,
delay_ms: u64,
error: String,
},
TurnStart,
TurnEnd {
message: AgentMessage,
tool_results: Vec<ToolResultMessage>,
},
MessageStart {
message: AgentMessage,
},
MessageUpdate {
message: Arc<AssistantMessage>,
assistant_message_event: AssistantMessageEvent,
},
MessageEnd {
message: AgentMessage,
},
ToolExecutionStart {
tool_call_id: String,
tool_name: String,
args: Value,
},
ToolExecutionUpdate {
tool_call_id: String,
tool_name: String,
args: Value,
partial_result: Arc<AgentToolResult>,
},
ToolExecutionEnd {
tool_call_id: String,
tool_name: String,
result: AgentToolResult,
is_error: bool,
},
}Expand description
An event emitted by the agent loop. Mirrors TS AgentEvent (tagged on
type). AgentMessage payloads are owned (cloned) so broadcast subscribers
get independent copies — except AgentEvent::MessageUpdate, which carries
the streaming partial as a cheap Arc because it fires once per delta.
Variants§
AgentStart
Emitted once at the start of a run, before turn_start.
AgentEnd
Emitted once at the end of a run; carries the new messages produced.
Fields
messages: Vec<AgentMessage>RetryScheduled
Emitted after a retryable provider failure, before the backoff wait.
Fields
TurnStart
Emitted at the start of each turn (a turn = one assistant response + its tool calls/results).
TurnEnd
Emitted after a turn’s assistant message + tool results settle. Carries
the assistant message (as an AgentMessage) and the tool-result
messages produced this turn, in source/ordinal order.
MessageStart
Emitted when any message (user prompt, assistant response, tool result, custom) is appended to the transcript.
Fields
message: AgentMessageMessageUpdate
Emitted only for assistant messages, on each streaming delta. Carries
the underlying AssistantMessageEvent plus a shared snapshot of the
partial assistant message.
The snapshot is an Arc, not an owned message: a delta used to deep-clone
the whole growing message here, again in the loop’s context update, and
again in each consumer — quadratic in the output length. Consumers that
need it as JSON use crate::message::assistant_json to keep the wire
shape identical without copying.
MessageEnd
Emitted when a message finishes (complement of MessageStart).
Fields
message: AgentMessageToolExecutionStart
Emitted before a tool call starts executing.
ToolExecutionUpdate
Emitted on a partial tool result pushed via on_update.
ToolExecutionEnd
Emitted when a tool call finishes (success or error). is_error marks
the error path; result carries the final tool result.