Skip to main content

AgentEvent

Enum AgentEvent 

Source
#[non_exhaustive]
pub enum AgentEvent {
Show 22 variants Token(String), ThinkStart, ThinkEnd { prompt_tokens: usize, completion_tokens: usize, }, ToolCall { name: String, args: Value, }, ToolResult { name: String, output: String, }, ToolError { name: String, error: String, }, PlanGenerated { steps: Vec<String>, }, StepStart { step_index: usize, description: String, }, StepEnd { step_index: usize, success: bool, }, GuardTriggered { guard: String, blocked: bool, }, MemoryRecalled { count: usize, }, ContextCompressed { before_count: usize, after_count: usize, before_tokens: usize, after_tokens: usize, }, HandoffStart { from: String, to: String, }, HandoffEnd { to: String, }, ReflectionStart { iteration: usize, }, ReflectionEnd { iteration: usize, score: f64, passed: bool, }, CritiqueGenerated { score: f64, passed: bool, feedback: String, }, Refining { iteration: usize, }, Chart { spec: Value, }, Error { source: String, message: String, }, FinalAnswer(String), Cancelled,
}
Expand description

Events produced during Agent execution

Cover each phase of the Agent lifecycle for progress bars, logs, UI updates, etc.

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.
§

Token(String)

LLM is generating a token (streaming)

§

ThinkStart

LLM reasoning started

§

ThinkEnd

LLM reasoning ended

Fields

§prompt_tokens: usize

Number of prompt tokens consumed

§completion_tokens: usize

Number of completion tokens consumed

§

ToolCall

Preparing to invoke a tool

Fields

§name: String

Tool name

§args: Value

Tool arguments (JSON format)

§

ToolResult

Tool execution completed

Fields

§name: String

Tool name

§output: String

Tool execution result (string format)

§

ToolError

Tool execution error

Fields

§name: String

Tool name

§error: String

Error message

§

PlanGenerated

Plan-and-Execute engine generated a plan

Fields

§steps: Vec<String>

List of plan step descriptions

§

StepStart

Plan step execution started

Fields

§step_index: usize

Step index (0-based)

§description: String

Step description

§

StepEnd

Plan step execution ended

Fields

§step_index: usize

Step index (0-based)

§success: bool

Whether the step executed successfully

§

GuardTriggered

A guard was triggered

Fields

§guard: String

Guard name

§blocked: bool

Whether the action was blocked

§

MemoryRecalled

Long-term memory was recalled

Fields

§count: usize

Number of recalled memory entries

§

ContextCompressed

Context was auto-compressed to fit within token limits

Fields

§before_count: usize

Message count before compression

§after_count: usize

Message count after compression

§before_tokens: usize

Estimated token count before compression

§after_tokens: usize

Estimated token count after compression

§

HandoffStart

Agent-to-agent handoff started

Fields

§from: String

Source agent name

§to: String

Target agent name

§

HandoffEnd

Agent-to-agent handoff ended

Fields

§to: String

Target agent name

§

ReflectionStart

Reflection iteration started

Fields

§iteration: usize

Current iteration number (starting from 1)

§

ReflectionEnd

Reflection iteration ended

Fields

§iteration: usize

Iteration number (starting from 1)

§score: f64

Reflection score (0.0-1.0)

§passed: bool

Whether reflection passed

§

CritiqueGenerated

Evaluator produced a critique

Fields

§score: f64

Critique score (0.0-1.0)

§passed: bool

Whether the evaluation passed

§feedback: String

Evaluation feedback text

§

Refining

Refining answer based on reflection

Fields

§iteration: usize

Current iteration number (starting from 1)

§

Chart

Chart generation (vega-lite JSON spec)

Fields

§spec: Value
§

Error

Generic Agent error (non-tool errors, e.g. LLM call failure, guard rejection, etc.)

Fields

§source: String

Error source (e.g. “llm”, “guard”, “config”)

§message: String

Error message

§

FinalAnswer(String)

Final answer

§

Cancelled

Cancelled

Implementations§

Source§

impl AgentEvent

Source

pub fn prompt_tokens(&self) -> Option<usize>

Return prompt token count for ThinkEnd.

Source

pub fn completion_tokens(&self) -> Option<usize>

Return completion token count for ThinkEnd.

Source

pub fn total_tokens(&self) -> Option<usize>

Return total token usage for ThinkEnd.

Source

pub fn tokens_used(&self) -> Option<usize>

Compatibility helper for older call sites that tracked a single token count.

Source

pub fn phase(&self) -> AgentPhase

Return the lifecycle phase of this event

Used for frontend phase-routed rendering, state machine derivation, and similar scenarios.

§Example
use echo_core::agent::{AgentEvent, AgentPhase};

let event = AgentEvent::ThinkStart;
assert_eq!(event.phase(), AgentPhase::Thinking);

let event = AgentEvent::FinalAnswer("done".into());
assert_eq!(event.phase(), AgentPhase::Terminal);
Source

pub fn is_checkpoint(&self) -> bool

Whether this is a persistable snapshot point (phase boundary event)

When these events occur, the Agent state is at a “stable point” — no in-flight LLM calls or tool executions, suitable for checkpoint save, resume-from-checkpoint, or Time Travel debugging.

§Example
use echo_core::agent::AgentEvent;

assert!(AgentEvent::ThinkEnd { prompt_tokens: 100, completion_tokens: 50 }.is_checkpoint());
assert!(AgentEvent::FinalAnswer("done".into()).is_checkpoint());
assert!(!AgentEvent::Token("hello".into()).is_checkpoint());

Trait Implementations§

Source§

impl Debug for AgentEvent

Source§

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

Formats the value using the given formatter. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more