pub enum AgentEvent {
Show 16 variants
AgentStart,
RunIdentified {
identity: RunIdentity,
},
AgentEnd {
messages: Vec<AgentMessage>,
},
TurnStart,
TurnEnd {
message: AgentMessage,
tool_results: Vec<AgentMessage>,
},
MessageStart {
message: AgentMessage,
},
MessageUpdate {
partial: AgentMessage,
chunk: AssistantStreamChunk,
},
MessageEnd {
message: AgentMessage,
},
ToolExecutionStart {
tool_call_id: String,
tool_name: String,
args: Value,
},
ToolExecutionUpdate {
tool_call_id: String,
tool_name: String,
partial: ToolResult,
},
ToolExecutionEnd {
tool_call_id: String,
tool_name: String,
result: ToolResult,
is_error: bool,
},
OutputTokensEscalation {
attempt: u8,
prev_cap: u32,
new_cap: u32,
},
ContextTransformApplied {
iteration: usize,
plugin: &'static str,
before: Vec<AgentMessage>,
after: Vec<AgentMessage>,
},
ToolGateApplied {
iteration: usize,
plugin: &'static str,
allow: Option<Vec<String>>,
},
ToolGateConflictResolved {
iteration: usize,
plugins: Vec<String>,
chosen_plugin: Option<String>,
allow: Vec<String>,
reason: String,
},
ProviderRequestPrepared {
iteration: usize,
model_id: Option<String>,
system_prompt: String,
messages: Vec<AgentMessage>,
tools: Vec<ToolSchema>,
temperature: Option<f32>,
max_output_tokens: Option<u32>,
},
}Expand description
All events the loop emits.
Lifecycle events (AgentStart, AgentEnd, TurnStart, TurnEnd)
bracket the run. Message events (MessageStart, MessageUpdate,
MessageEnd) bracket each individual message. Tool events
(ToolExecutionStart, ToolExecutionUpdate, ToolExecutionEnd)
bracket each tool call.
Variants§
AgentStart
First event in a run. Emitted once.
RunIdentified
Run identity, emitted immediately after AgentEvent::AgentStart
when the context carries a RunIdentity. Trajectory sinks key
every subsequent event of the same run on identity.run_id;
child runs surface their parent_run_id so the spawn tree
rebuilds without external bookkeeping.
Existing observers that don’t care about identity ignore this variant (every match arm in the tree already has a wildcard fallback). Plugins and sinks that want identity pattern-match directly.
Fields
identity: RunIdentityAgentEnd
Last event in a run. Carries the messages produced during this run (not the full transcript). Listeners that want the full transcript should fold prior messages into a state of their own.
Fields
messages: Vec<AgentMessage>TurnStart
Bracket: a new turn begins. A turn is one assistant response plus any tool calls/results it spawned.
TurnEnd
Bracket: a turn ends. Carries the assistant message and the tool results for that turn (empty if the model didn’t call any tools).
MessageStart
A message has been added to the transcript (user, assistant, or
tool result). For assistant messages, this fires before streaming
begins; subsequent MessageUpdate events carry deltas.
Fields
message: AgentMessageMessageUpdate
Streaming delta for the in-progress assistant message.
MessageEnd
The message has been fully assembled (final content, stop reason).
Fields
message: AgentMessageToolExecutionStart
A tool execution has begun.
ToolExecutionUpdate
Partial progress from a long-running tool. The tool calls
update.send(...) to surface intermediate state without ending.
ToolExecutionEnd
A tool execution has finished.
OutputTokensEscalation
The loop discarded a truncated assistant turn and re-streamed
with a higher max_output_tokens cap. Emitted once per
retry attempt; multiple events for the same turn signal the
recovery walked the configured ladder. See
crate::config::MaxTokensRecovery.
Fields
ContextTransformApplied
A ContextTransform plugin ran on this turn’s transcript.
Emitted once per active transform per turn, in registration
order. Carries the full before/after message slices so observers
can reconstruct exactly which messages each transform removed,
added, or rewrote — the canonical answer to “which compaction
stripped that tool result we expected the model to still see?”.
Fields
iteration: usizeZero-indexed turn within the current run. Same semantics as
crate::plugin::TransformContext::iteration.
before: Vec<AgentMessage>Transcript handed to the transform.
after: Vec<AgentMessage>Transcript the transform returned.
ToolGateApplied
A ToolGate plugin contributed to this turn’s allowlist.
Emitted once per gate per turn. Multiple gates compose by
intersection downstream; this event records the gate’s own
decision before composition so observers can attribute the
final allowlist to specific plugins.
Fields
ToolGateConflictResolved
Multiple ToolGate plugins narrowed the same turn to disjoint
non-empty allowlists. The loop repaired the composition to avoid
advertising an empty tool catalog to the model.
Fields
ProviderRequestPrepared
Snapshot of the request the loop is about to send to the
provider on this turn, taken after every ContextTransform
has run and every ToolGate has filtered. This is the typed
view of “what the model sees” — wire-format conversion
(provider-specific shapes) happens downstream inside the
StreamFn. Emitted once per turn, just before the stream call.
Fields
model_id: Option<String>Model identifier the host associated with this loop, when known. Provider transports still own their wire conversion, so this is observability metadata only.
system_prompt: StringSystem prompt for this turn. May include ephemeral system
reminders injected by ContextTransform plugins.
messages: Vec<AgentMessage>Full message history the loop is about to send.
tools: Vec<ToolSchema>Tool schemas advertised this turn, post-ToolGate filtering.
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