Skip to main content

AgentEvent

Enum AgentEvent 

Source
#[non_exhaustive]
pub enum AgentEvent { TextDelta(String), TurnCompleted, ToolCallStarted { id: String, name: String, arguments: String, }, ToolCallCompleted { id: String, name: String, output: String, is_error: bool, }, CacheWarning { message: String, }, Usage(Usage), BackgroundOutput { job_id: String, chunk: String, truncated: bool, }, }
Expand description

Streaming events emitted by a native runtime agent as a turn unfolds.

Attach an EventSink to a runtime configuration to observe these live — for example to render tokens to a terminal as they arrive, or to surface tool activity in a UI.

#[non_exhaustive] because new event kinds will be added over time; match with a _ arm so a new variant is not a breaking change.

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

TextDelta(String)

A chunk of assistant text was produced.

§

TurnCompleted

The assistant finished a text/tool turn (one round-trip to the model).

§

ToolCallStarted

The model requested a tool call (fired before the tool runs).

Fields

§id: String

Provider-assigned call id.

§name: String

Tool name.

§arguments: String

Raw JSON argument string as sent by the model.

§

ToolCallCompleted

A tool finished running.

Fields

§id: String

Provider-assigned call id.

§name: String

Tool name.

§output: String

The tool’s textual output (truncated for display upstream if needed).

§is_error: bool

Whether the tool reported an error.

§

CacheWarning

UX-26 (B7-warn): the turn that just completed likely paid a full-price prompt-cache miss despite reuse being expected under an imported-prefix cache plan. Emitted at most once per turn, only when cache warnings are enabled (default on) and reuse was genuinely expected (never on a first/establishing request, a same-turn tool-schema-tier bust, or under a disabled cache plan — so this never fires as a false positive on a cold-by-design request).

Fields

§message: String

Ready-to-print, human-readable warning line (no trailing newline).

§

Usage(Usage)

UX-23: token accounting for the request that just completed (one per model round-trip — a multi-tool-call turn emits one of these per round-trip, same cadence as AgentEvent::TurnCompleted, which this is always emitted immediately before). Reuses the provider completion’s usage return rather than introducing a second accounting path, so --trace/stream-json consumers see exactly the numbers the provider reported — never a derived estimate.

§

BackgroundOutput

P5-6 (COMPOSABLE-HARNESS-DESIGN.md §2 module 4 tools.background, D1 “monitor/event feed”): new output a background job (spawned via the background_exec intrinsic) has produced since the last background_status poll — the “event feed” capabilities. tools_background promises. Emitted from the runtime agent’s background-status operation, at most once per poll, only when there IS new output (an idle poll of a still-running job with nothing new to report emits nothing).

Fields

§job_id: String

The job id background_exec returned.

§chunk: String

The newly captured text since the previous poll (never a repeat of already-emitted output).

§truncated: bool

Whether this job’s RETAINED capture has hit capabilities.tools_background.max_output_byteschunk itself is never truncated mid-character, but once this is true no further output from this job will ever be retained or emitted, even though the process may still be producing it.

Implementations§

Source§

impl AgentEvent

Source

pub fn tool_started(call: &ToolCall) -> AgentEvent

Build the event emitted immediately before a tool call executes.

Source

pub fn to_json(&self) -> Value

P5-8 (§2 module 31 server, completing Obligation 9’s “partial” core commitment): the canonical {"type": ..., ...} JSONL projection of this event — field names mirror the enum’s own (id/name/arguments/output/is_error/prompt_tokens/…) rather than a hand-maintained parallel vocabulary, so the wire shape can never silently drift from the enum it projects.

Shared by the CLI’s --output-format stream-json sink (UX-23) and the server module’s RPC/SSE event-notification channel, so both out-of-process surfaces stay byte-identical for the same event instead of maintaining two hand-written projections that could silently diverge.

Match is exhaustive with NO wildcard arm on purpose: #[non_exhaustive] only affects callers OUTSIDE this crate (it forced the CLI’s old, external copy of this projection to carry a {"type":"unknown"} fallback arm) — from INSIDE the crate that defines the enum, adding a future AgentEvent variant makes this fail to COMPILE until it’s given a real projection here, which is strictly safer than silently falling back to an opaque "unknown" line for a new event kind.

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<(), 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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: Sized + 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: Sized + 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

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