Skip to main content

AgentEvent

Enum AgentEvent 

Source
#[non_exhaustive]
pub enum AgentEvent {
Show 14 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, }, 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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

AgentStart

Agent begins processing a prompt.

§

AgentEnd

Agent finished all processing.

Fields

§messages: Vec<Message>

All messages produced during this prompt() call.

§

TurnStart

A new turn begins (one LLM call + any tool executions).

§

TurnEnd

A turn completed.

Fields

§message: Message

The assistant message produced by the turn.

§tool_results: Vec<ToolResult>

Results of any tools the turn executed.

§

MessageStart

A message was added (user, assistant, or tool_result).

Fields

§message: Message

The message that was added.

§

MessageDelta

Streaming delta for the current assistant message.

Fields

§delta: String

The new token/chunk of text.

§tokens_generated: u32

Tokens generated so far in this response.

§tokens_per_sec: f64

Current generation speed.

§

MessageEnd

A message is complete.

Fields

§message: Message

The completed message.

§

GenerationStats

Final timing statistics for a completed generation. Emitted once per successful response so the UI / observability layer can record the real time-to-first-token and generation time (not approximated from tps).

Fields

§tokens_generated: u32

Tokens generated in the response.

§prompt_tokens: u32

Tokens in the formatted prompt.

§tokens_per_sec: f64

Average generation speed in tokens per second.

§time_to_first_token_ms: f64

Time to the first emitted token, in milliseconds.

§generation_time_ms: f64

Total generation time, in milliseconds.

§

ToolExecStart

A tool execution started.

Fields

§tool_call_id: String

Id of the tool call being executed.

§tool_name: String

Name of the tool being executed.

§args: Value

Arguments passed to the tool.

§

ToolExecUpdate

Streaming progress from a tool execution.

Fields

§tool_call_id: String

Id of the tool call reporting progress.

§tool_name: String

Name of the tool reporting progress.

§partial: String

Partial output emitted so far.

§

ToolExecEnd

A tool execution completed.

Fields

§tool_call_id: String

Id of the completed tool call.

§tool_name: String

Name of the completed tool.

§result: ToolResult

The tool’s result.

§

ContextBudget

Context budget info after formatting.

Fields

§used_tokens: u32

Tokens used by the prepared prompt.

§max_tokens: u32

Maximum context tokens available.

§messages_in_context: u32

Number of messages kept in the prompt.

§messages_pruned: u32

Number of messages pruned to fit.

§

Warning

Non-fatal warning during processing.

Fields

§message: String

Human-readable warning text.

§

Error

Fatal error that stopped processing.

Fields

§message: String

Human-readable error text.

Trait Implementations§

Source§

impl Clone for AgentEvent

Source§

fn clone(&self) -> AgentEvent

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AgentEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for AgentEvent

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for AgentEvent

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.