Skip to main content

Message

Enum Message 

Source
pub enum Message {
    Human {
        content: MessageContent,
        id: Option<String>,
    },
    Ai {
        content: MessageContent,
        tool_calls: Vec<ToolCall>,
        id: Option<String>,
        usage: Option<LlmUsage>,
        thinking: Option<String>,
    },
    System {
        content: MessageContent,
        id: Option<String>,
    },
    Tool {
        content: MessageContent,
        tool_call_id: String,
        name: Option<String>,
        id: Option<String>,
        status: String,
    },
    Remove {
        id: String,
    },
}
Expand description

Message types for the agent system.

Mirrors the LangChain message types: HumanMessage, AIMessage, SystemMessage, ToolMessage, and RemoveMessage.

Variants§

§

Human

A message from the human user.

Fields

§

Ai

A message from the AI assistant.

Fields

§tool_calls: Vec<ToolCall>
§usage: Option<LlmUsage>

Token usage from the LLM API response, if available.

§thinking: Option<String>

Thinking/reasoning content from models that support it (e.g., DeepSeek, o1/o3).

§

System

A system message providing instructions.

Fields

§

Tool

A message containing the result of a tool call.

Fields

§tool_call_id: String
§status: String

Status of the tool call: “success” or “error”

§

Remove

A message that removes a previous message by ID.

Fields

Implementations§

Source§

impl Message

Source

pub fn text(&self) -> Option<&str>

Get the text content of the message, if any.

Source

pub fn id(&self) -> Option<&str>

Get the message ID, if any.

Source

pub fn has_tool_calls(&self) -> bool

Check if this message has tool calls.

Source

pub fn tool_calls(&self) -> &[ToolCall]

Get tool calls from the message.

Source

pub fn human(content: impl Into<String>) -> Self

Create a human message.

Source

pub fn ai(content: impl Into<String>) -> Self

Create an AI message.

Source

pub fn ai_with_tool_calls( content: impl Into<String>, tool_calls: Vec<ToolCall>, ) -> Self

Create an AI message with tool calls.

Source

pub fn ai_with_usage(content: impl Into<String>, usage: LlmUsage) -> Self

Create an AI message with token usage information.

Source

pub fn ai_with_tool_calls_and_usage( content: impl Into<String>, tool_calls: Vec<ToolCall>, usage: LlmUsage, ) -> Self

Create an AI message with tool calls and token usage.

Source

pub fn usage(&self) -> Option<&LlmUsage>

Get token usage from the message, if available.

Source

pub fn thinking(&self) -> Option<&str>

Get the thinking/reasoning content, if available.

Source

pub fn ai_with_thinking( content: impl Into<String>, thinking: impl Into<String>, ) -> Self

Create an AI message with thinking/reasoning content.

Source

pub fn system(content: impl Into<String>) -> Self

Create a system message.

Source

pub fn tool_result( tool_call_id: impl Into<String>, content: impl Into<String>, ) -> Self

Create a tool result message with success status.

Source

pub fn tool_error( tool_call_id: impl Into<String>, content: impl Into<String>, ) -> Self

Create a tool error message.

Trait Implementations§

Source§

impl Clone for Message

Source§

fn clone(&self) -> Message

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 Message

Source§

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

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

impl<'de> Deserialize<'de> for Message

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 Display for Message

Source§

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

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

impl Serialize for Message

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

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.