#[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
Token(String)
LLM is generating a token (streaming)
ThinkStart
LLM reasoning started
ThinkEnd
LLM reasoning ended
Fields
ToolCall
Preparing to invoke a tool
ToolResult
Tool execution completed
ToolError
Tool execution error
PlanGenerated
Plan-and-Execute engine generated a plan
StepStart
Plan step execution started
StepEnd
Plan step execution ended
GuardTriggered
A guard was triggered
MemoryRecalled
Long-term memory was recalled
ContextCompressed
Context was auto-compressed to fit within token limits
Fields
HandoffStart
Agent-to-agent handoff started
HandoffEnd
Agent-to-agent handoff ended
ReflectionStart
Reflection iteration started
ReflectionEnd
Reflection iteration ended
Fields
CritiqueGenerated
Evaluator produced a critique
Fields
Refining
Refining answer based on reflection
Chart
Chart generation (vega-lite JSON spec)
Error
Generic Agent error (non-tool errors, e.g. LLM call failure, guard rejection, etc.)
FinalAnswer(String)
Final answer
Cancelled
Cancelled
Implementations§
Source§impl AgentEvent
impl AgentEvent
Sourcepub fn prompt_tokens(&self) -> Option<usize>
pub fn prompt_tokens(&self) -> Option<usize>
Return prompt token count for ThinkEnd.
Sourcepub fn completion_tokens(&self) -> Option<usize>
pub fn completion_tokens(&self) -> Option<usize>
Return completion token count for ThinkEnd.
Sourcepub fn total_tokens(&self) -> Option<usize>
pub fn total_tokens(&self) -> Option<usize>
Return total token usage for ThinkEnd.
Sourcepub fn tokens_used(&self) -> Option<usize>
pub fn tokens_used(&self) -> Option<usize>
Compatibility helper for older call sites that tracked a single token count.
Sourcepub fn phase(&self) -> AgentPhase
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);Sourcepub fn is_checkpoint(&self) -> bool
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§
Auto Trait Implementations§
impl Freeze for AgentEvent
impl RefUnwindSafe for AgentEvent
impl Send for AgentEvent
impl Sync for AgentEvent
impl Unpin for AgentEvent
impl UnsafeUnpin for AgentEvent
impl UnwindSafe for AgentEvent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request