#[non_exhaustive]pub enum AgentEvent {
Show 15 variants
AgentStart,
AgentEnd {
messages: Vec<Message>,
},
TurnStart,
TurnEnd {
message: Message,
tool_results: Vec<ToolResult>,
},
MessageStart {
message: Message,
},
MessageDelta {
delta: String,
tokens_generated: u32,
tokens_per_sec: f64,
},
MessageEnd {
message: Message,
},
GenerationStats {
tokens_generated: u32,
prompt_tokens: u32,
tokens_per_sec: f64,
time_to_first_token_ms: f64,
generation_time_ms: f64,
},
ToolExecStart {
tool_call_id: String,
tool_name: String,
args: Value,
},
ToolExecUpdate {
tool_call_id: String,
tool_name: String,
partial: String,
},
ToolExecEnd {
tool_call_id: String,
tool_name: String,
result: ToolResult,
},
ToolDenied {
tool_call_id: String,
tool_name: String,
reason: String,
},
ContextBudget {
used_tokens: u32,
max_tokens: u32,
messages_in_context: u32,
messages_pruned: u32,
},
Warning {
message: String,
},
Error {
message: String,
},
}Expand description
Events emitted by the agent loop. Mirrors pi-agent-core’s event system for UI reactivity.
This enum is #[non_exhaustive]: match it with a wildcard arm, as new
event variants may be added in a minor release.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
AgentStart
Agent begins processing a prompt.
AgentEnd
Agent finished all processing.
TurnStart
A new turn begins (one LLM call + any tool executions).
TurnEnd
A turn completed.
Fields
tool_results: Vec<ToolResult>Results of any tools the turn executed.
MessageStart
A message was added (user, assistant, or tool_result).
MessageDelta
Streaming delta for the current assistant message.
Fields
MessageEnd
A message is complete.
GenerationStats
Timing and token statistics for one completed LLM generation.
Emission guarantee. Exactly one GenerationStats is emitted for each
LLM iteration that runs to completion within a single prompt() call -
no more, no less - and always before that turn’s MessageEnd/TurnEnd
and before the run’s closing AgentEnd. When tools fire, a prompt()
spans several iterations; summing the tokens_generated / prompt_tokens
of every GenerationStats in the run therefore yields the exact per-run
totals, with no gaps and no double counting. A generation that is aborted
or errors before completing produces no result and so emits no
GenerationStats (the internal summarization pass likewise does not emit
one). Consumers metering usage can rely on this contract; it is pinned by
tests.
Fields
ToolExecStart
A tool execution started.
Fields
ToolExecUpdate
Streaming progress from a tool execution.
Fields
ToolExecEnd
A tool execution completed.
Fields
result: ToolResultThe tool’s result.
ToolDenied
A tool call was refused by the approval hook and never executed.
Distinct from a ToolExecEnd carrying an error result: that signals a
tool that ran and failed, whereas this signals a call that was blocked
before execution. The same reason is also appended to the conversation
as an error tool result so the model can adapt.
Fields
ContextBudget
Context budget info after formatting.
Fields
Warning
Non-fatal warning during processing.
Error
Fatal error that stopped processing.
Trait Implementations§
Source§impl Clone for AgentEvent
impl Clone for AgentEvent
Source§fn clone(&self) -> AgentEvent
fn clone(&self) -> AgentEvent
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more