pub struct Message {
pub role: Role,
pub content: Vec<ContentPart>,
pub tool_calls: Option<Vec<ToolCall>>,
pub tool_call_id: Option<String>,
pub name: Option<String>,
}Expand description
A single message in the LLM conversation history.
content is now Vec<ContentPart> to support multimodal messages
(text + images) and Anthropic-style tool content blocks.
For the common single-text-message case the API still sees a plain string
thanks to the custom serialize_content_parts serializer.
Fields§
§role: Role§content: Vec<ContentPart>Message body — one or more content parts.
Use text_content() to extract plain text.
NOTE: serialization is handled by a custom serializer below.
tool_calls: Option<Vec<ToolCall>>§tool_call_id: Option<String>§name: Option<String>Implementations§
Source§impl Message
impl Message
Sourcepub fn system(content: impl Into<String>) -> Self
pub fn system(content: impl Into<String>) -> Self
Create a system message with plain text content.
Sourcepub fn assistant(
content: Option<String>,
tool_calls: Option<Vec<ToolCall>>,
) -> Self
pub fn assistant( content: Option<String>, tool_calls: Option<Vec<ToolCall>>, ) -> Self
Create an assistant message.
content is Option<String> here for backwards compatibility with
callers that had content: Option<String>. Pass None when the
response contains only tool calls.
Sourcepub fn tool(tool_call_id: impl Into<String>, content: impl Into<String>) -> Self
pub fn tool(tool_call_id: impl Into<String>, content: impl Into<String>) -> Self
Create a tool-result message.
Sourcepub fn text_content(&self) -> Option<String>
pub fn text_content(&self) -> Option<String>
Extract all plain text from this message’s content parts.
Concatenates every ContentPart::Text in order, joining with \n
when there are multiple text parts. Returns None if there are no
text parts (e.g. a message containing only images or tool results).