pub struct Message {
pub role: Role,
pub parts: Vec<Part>,
}Expand description
A message in the internal conversation model.
Fields§
§role: RoleWho produced this message.
parts: Vec<Part>The message content as an ordered list of parts.
Implementations§
Source§impl Message
impl Message
Sourcepub fn new(role: Role, parts: Vec<Part>) -> Self
pub fn new(role: Role, parts: Vec<Part>) -> Self
Creates a message from a role and an ordered list of parts.
Sourcepub fn system(text: impl Into<String>) -> Self
pub fn system(text: impl Into<String>) -> Self
Creates a single-text Role::System message.
Sourcepub fn developer(text: impl Into<String>) -> Self
pub fn developer(text: impl Into<String>) -> Self
Creates a single-text Role::Developer message.
Sourcepub fn user(text: impl Into<String>) -> Self
pub fn user(text: impl Into<String>) -> Self
Creates a single-text Role::User message.
Sourcepub fn assistant(text: impl Into<String>) -> Self
pub fn assistant(text: impl Into<String>) -> Self
Creates a single-text Role::Assistant message.
Sourcepub fn custom(role: impl Into<String>, text: impl Into<String>) -> Self
pub fn custom(role: impl Into<String>, text: impl Into<String>) -> Self
Creates a single-text Role::Custom message.
Sourcepub fn text(role: Role, text: impl Into<String>) -> Self
pub fn text(role: Role, text: impl Into<String>) -> Self
Creates a message with a single text part of the given role.
Sourcepub fn assistant_with_tools(
text: impl Into<String>,
tool_calls: impl IntoIterator<Item = ToolCall>,
) -> Self
pub fn assistant_with_tools( text: impl Into<String>, tool_calls: impl IntoIterator<Item = ToolCall>, ) -> Self
Creates an assistant message with optional text followed by tool-call parts. Empty text is skipped.
Sourcepub fn assistant_reasoning(reasoning: Reasoning) -> Self
pub fn assistant_reasoning(reasoning: Reasoning) -> Self
Creates an assistant message holding a single reasoning part.
Sourcepub fn tool_result(result: ToolResult) -> Self
pub fn tool_result(result: ToolResult) -> Self
Creates a Role::Tool message holding one tool result.
Sourcepub fn tool_results(results: impl IntoIterator<Item = ToolResult>) -> Self
pub fn tool_results(results: impl IntoIterator<Item = ToolResult>) -> Self
Creates a Role::Tool message holding multiple tool results.
Sourcepub fn text_content(&self) -> String
pub fn text_content(&self) -> String
Returns the text parts joined by newlines. Tool-result text content is included; other part kinds are skipped.
Sourcepub fn tool_calls(&self) -> impl Iterator<Item = &ToolCall>
pub fn tool_calls(&self) -> impl Iterator<Item = &ToolCall>
Iterates over the tool calls requested in this message.
Sourcepub fn tool_result_parts(&self) -> impl Iterator<Item = &ToolResult>
pub fn tool_result_parts(&self) -> impl Iterator<Item = &ToolResult>
Iterates over the tool results carried by this message. Iterates over the tool results carried by this message.
Sourcepub fn reasoning(&self) -> impl Iterator<Item = &Reasoning>
pub fn reasoning(&self) -> impl Iterator<Item = &Reasoning>
Iterates over the reasoning parts of this message.
Sourcepub fn reasoning_text(&self) -> String
pub fn reasoning_text(&self) -> String
Returns all reasoning display text joined by newlines.