pub enum AgentEvent {
Show 26 variants
TextDelta(String),
ReasoningDelta(String),
ToolCallStreaming {
name: String,
hint: String,
},
ToolCallStarted {
id: String,
name: String,
arguments: String,
},
ToolBatchStarted {
batch_id: String,
calls: Vec<ToolBatchCall>,
},
ToolBatchCompleted {
batch_id: String,
ok: usize,
total: usize,
elapsed_ms: u64,
},
ToolOutputChunk {
call_id: String,
chunk: String,
},
ToolCallResult {
call_id: String,
name: String,
output: String,
success: bool,
duration: Duration,
},
ApprovalNeeded {
tool_name: String,
reason: String,
call: ToolCall,
messages: Vec<Message>,
},
TokenUsage(TokenUsage),
PhaseChange(AgentPhase),
TurnComplete {
duration: Duration,
total_tokens: usize,
turn_count: usize,
tool_call_count: usize,
stop_reason: TurnStopReason,
messages: Vec<Message>,
},
TurnCancelled {
messages: Vec<Message>,
},
MessagesSync {
messages: Vec<Message>,
},
Error {
error: String,
messages: Vec<Message>,
},
Warning(String),
RestorePendingImages {
images: Vec<ImagePart>,
markers: Vec<usize>,
},
VisionPreprocessSuccess {
vl_key: String,
char_count: usize,
},
SubAgentDispatchStart {
tasks: Vec<SubAgentTaskInfo>,
},
SubAgentDispatchEnd,
SubAgentTaskStarted {
index: usize,
},
SubAgentTaskDone {
index: usize,
elapsed_ms: u64,
turns: usize,
summary: String,
},
SubAgentTaskFailed {
index: usize,
elapsed_ms: u64,
turns: usize,
reason: String,
},
BackgroundComplete {
summary: String,
files_edited: Vec<String>,
turns: usize,
success: bool,
},
WorkingDirChanged(PathBuf),
ContextStats {
system_tokens: usize,
sent_tokens: usize,
dropped_tokens: usize,
working_set_tokens: usize,
total_messages: usize,
tool_defs_tokens: usize,
cold_zone_tokens: usize,
ctx_window: usize,
ctx_name: String,
system_prompt: String,
},
}Expand description
Events sent FROM the agent loop TO the UI.
Variants§
TextDelta(String)
LLM text delta (streaming).
ReasoningDelta(String)
LLM reasoning/thinking content (e.g., DeepSeek-R1, MiniMax-M2.7, o1-series). Emitted when the model produces thinking content separately from the final response. UI can optionally display this in verbose mode (Ctrl+O).
ToolCallStreaming
LLM has started emitting a tool call — only the name is known so far, arguments are still streaming. UI uses this to display the tool name immediately instead of waiting for the full args.
ToolCallStarted
A tool call is about to execute (for display).
id pairs with ToolCallResult.call_id so the UI can match start→result
across parallel or interleaved calls without reconstructing ids from counters.
ToolBatchStarted
Multiple tool calls fan out from one assistant message. Fires BEFORE
the per-call ToolCallStarted events, only when ≥ 2 non-duplicate
calls are about to dispatch. UI uses this to render a single
grouped block (▸ Reading 4 files (parallel) + child rows) rather
than N independent ▸ rows. Per-call events still fire for
backward compat — UI dedupes via batch_id membership.
ToolBatchCompleted
Closes the batch opened by ToolBatchStarted. UI finalizes the
group header with · N/M ok · Xs wall summary.
ToolOutputChunk
Real-time output chunk from a running tool (e.g., bash command). Sent during tool execution before ToolCallResult.
ToolCallResult
A tool call completed with a result.
ApprovalNeeded
Waiting for user approval of a tool call.
Fields
TokenUsage(TokenUsage)
Token usage update.
PhaseChange(AgentPhase)
The agent’s current phase changed.
TurnComplete
Turn completed successfully.
Fields
stop_reason: TurnStopReasonWhy the loop stopped. Natural for ordinary completion; see
TurnStopReason for budget / cancel / error variants.
TurnCancelled
Turn was cancelled by user before completion. The conversation has been cleaned up - partial messages removed. Contains the cleaned message list for TUI to sync.
MessagesSync
Response to AgentCommand::SyncMessages. Carries a snapshot of
conversation.messages at the time the agent processed the command.
Used by the TUI to sync session state before backgrounding a session
that is mid-turn (e.g. waiting for tool approval).
Error
An error occurred. Carries a snapshot of conversation.messages
so the TUI can persist mid-turn state even when the turn dies
before TurnComplete/TurnCancelled fire — without this, a
first-turn LLM failure silently drops the user’s typed message
from disk and /resume shows nothing for that conversation.
Producers that don’t hold the conversation (the inline
streaming-error forwarder in run_turn_loop) send messages: Vec::new(); the terminal error path captured at
handle_send_message provides the full snapshot.
Warning(String)
Non-fatal advisory from a provider or other subsystem. UI renders this as a one-line yellow banner; does not abort the turn. Currently sourced from the OpenAI provider’s truncation detector when the proxy reports implausibly few prompt_tokens.
RestorePendingImages
VL preprocessing failed; the agent is returning the user’s pending images so the TUI can re-attach them to the input state. Lets the user retry the same image without re-pasting from clipboard. Hashes are TUI-side state, so the renderer recomputes them from the returned base64 bytes (best-effort; clipboard-equality dedup may fire on a fresh paste of the same image — minor UX, not breaking).
Fields
VisionPreprocessSuccess
VL preprocessing succeeded — surface a one-line success notice
without dumping the (possibly long, sometimes uninformative) VL
description into the UI. The description still rides into
conversation history for the main model. vl_key is the provider
key from config; char_count is text.chars().count() so users
can spot zero/near-zero outputs that would mislead the main model.
SubAgentDispatchStart
Sub-agent batch began. tasks is the ordered list of children
the dispatcher is about to fork — same order as the resulting
SubAgentTaskDone/SubAgentTaskFailed events will arrive in,
so the UI can pre-allocate one display slot per child and
disambiguate same-basename tasks via the index.
Fields
tasks: Vec<SubAgentTaskInfo>Per-task descriptors. path is the workspace-relative file
path (preserved as the model wrote it — no basename-only
truncation). dedup_suffix is the user-facing (#2),
(#3) qualifier when the same path appears N times in one
dispatch; empty for unique entries.
SubAgentDispatchEnd
Sub-agent batch ended (all tasks settled or pool returned). UI clears the override so subsequent thinks/tools resume normal label behaviour.
SubAgentTaskStarted
One sub-agent has been claimed from the pool and is now running.
index indexes into the tasks vector emitted with the
matching DispatchStart so the UI can locate its slot.
SubAgentTaskDone
Sub-agent finished successfully. summary is a one-sentence
human-readable result, already truncated to a reasonable length
by the agent loop.
SubAgentTaskFailed
Sub-agent failed (error, timeout, no-edit). reason is one
short phrase, not a stack trace.
BackgroundComplete
/background task finished. summary is the final assistant text
(truncated if long). success is false on error / timeout / cancel.
WorkingDirChanged(PathBuf)
Working directory changed.
ContextStats
Context budget stats — piped into datalog and cached by the TUI
for /context. Emitted after every turn’s ctx.build_messages
call, so stats reflect the snapshot the model actually saw.
The rich breakdown (tool defs / cold zone / ctx window / ctx name)
only appears on the second emission path in
handle_send_message — the first path (TurnEvent forwarding) uses
the narrow stats from the ctx::render output. TUI merges both.
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 moreAuto 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more