pub struct Message {
pub role: Role,
pub content: Option<Content>,
pub tool_calls: Option<Vec<ToolCall>>,
pub tool_call_id: Option<String>,
pub name: Option<String>,
pub reasoning: Option<String>,
pub finish_reason: Option<String>,
}Expand description
Conversation message — the fundamental unit of LLM interaction.
Fields§
§role: Role§content: Option<Content>§tool_calls: Option<Vec<ToolCall>>§tool_call_id: Option<String>§name: Option<String>Tool name — present on tool result messages
reasoning: Option<String>Extracted reasoning/thinking content (e.g. from <think> blocks)
finish_reason: Option<String>Implementations§
Source§impl Message
impl Message
pub fn user(text: &str) -> Self
pub fn assistant(text: &str) -> Self
pub fn system(text: &str) -> Self
pub fn tool_result(tool_call_id: &str, name: &str, content: &str) -> Self
Sourcepub fn assistant_with_tool_calls(text: &str, tool_calls: Vec<ToolCall>) -> Self
pub fn assistant_with_tool_calls(text: &str, tool_calls: Vec<ToolCall>) -> Self
Assistant message that requested tool calls.
WHY store tool_calls on assistant messages: When rebuilding the chat history for the LLM API, we need to pair each tool result with the assistant message that requested it. Without storing the original tool_calls, we lose the correlation and the LLM can’t understand the conversation flow.
Sourcepub fn system_summary(text: String) -> Self
pub fn system_summary(text: String) -> Self
Summary message injected by context compression.
Sourcepub fn text_content(&self) -> String
pub fn text_content(&self) -> String
Extract plaintext from content, joining multimodal parts.
Sourcepub fn has_tool_calls(&self) -> bool
pub fn has_tool_calls(&self) -> bool
True if this message has tool call requests from the assistant.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Message
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnsafeUnpin for Message
impl UnwindSafe for Message
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
Mutably borrows from an owned value. Read more