Skip to main content

AgentMessage

Enum AgentMessage 

Source
pub enum AgentMessage {
    System {
        content: String,
        timestamp: Option<u64>,
    },
    User {
        content: UserContent,
        timestamp: Option<u64>,
    },
    Assistant {
        content: AssistantContent,
        stop_reason: StopReason,
        error_message: Option<String>,
        timestamp: Option<u64>,
        usage: Option<Usage>,
    },
    ToolResult {
        tool_call_id: String,
        tool_name: String,
        content: ToolResultContent,
        is_error: bool,
        narration: Option<String>,
        details: Option<Value>,
        timestamp: Option<u64>,
    },
    Custom {
        kind: String,
        payload: Value,
        timestamp: Option<u64>,
    },
}
Expand description

One message in the conversation transcript.

Discriminated by role. Each variant carries its own payload shape; the loop pattern-matches, never field-walks.

Variants§

§

System

System prompt. Typically only one, at the head of the transcript.

Fields

§content: String
§timestamp: Option<u64>
§

User

User input. May be a single text block or rich blocks (text + images).

Fields

§content: UserContent
§timestamp: Option<u64>
§

Assistant

Model output. Carries text, thinking blocks, and tool calls.

Fields

§stop_reason: StopReason
§error_message: Option<String>
§timestamp: Option<u64>
§usage: Option<Usage>

Provider-reported token accounting for the call that produced this message. Populated by streaming transports that request stream_options.include_usage; consumed by cost/billing observers (e.g. eval matrix). None when the transport didn’t surface usage data.

§

ToolResult

Output of a tool call. Always paired with a prior assistant message that contains the corresponding ToolCall block.

Fields

§tool_call_id: String
§tool_name: String
§is_error: bool
§narration: Option<String>

Tool-side prose summary — the row-caption sentence the UI renders (“Ran ls -la.”, “Wrote index.html (4 KB).”, “Searched: rust async — 8 results.”). The loop fills this from ToolResult::narration when the typed result is appended to history; tools may set it deterministically from their own structured signals. Optional for backward-compatibility with persisted histories that pre-date this field.

working_memory_anchor and other history-aware plugins consume this in preference to walking the content blocks for a preview; the model’s first-line peek of a densified shell result is opaque metadata, while narration carries the actual prose every other surface already shows.

§details: Option<Value>

Host-side structured payload carried from the tool’s ToolResult::details. Stripped from provider wire formats (the model sees content only) but preserved into history so host-side plugins — delivery gates, artifact dispatchers, UI projectors — can read structured fields without text-grepping. Typed producers (create_slides, create_website, publish) put canonical artifact metadata here (html_url, artifacts: [...], …). None when the tool returned no structured payload, or for messages deserialized from histories persisted before this field existed.

§timestamp: Option<u64>
§

Custom

Escape hatch for app-specific message types (UI notifications, hidden runtime feedback, replay markers). The loop ignores these for tool dispatch but apps can route them through plugins or the event sink.

Fields

§kind: String
§payload: Value
§timestamp: Option<u64>

Trait Implementations§

Source§

impl Clone for AgentMessage

Source§

fn clone(&self) -> AgentMessage

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 AgentMessage

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for AgentMessage

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for AgentMessage

Source§

fn eq(&self, other: &AgentMessage) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for AgentMessage

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for AgentMessage

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> 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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,