pub struct Message {
pub role: Role,
pub content: String,
pub content_blocks: Vec<ContentBlock>,
pub tool_calls: Vec<ToolCall>,
pub tool_call_id: Option<String>,
pub tool_error: bool,
}Expand description
A single message in a conversation.
Supports text-only and multimodal (text + images) content.
Use the constructors (Message::system, Message::user,
Message::assistant, Message::tool, Message::user_multimodal, …)
rather than building the struct by hand; they keep the role and the
tool-related fields consistent.
§Examples
use rai_sdk::Message;
let system = Message::system("Answer in one sentence.");
let user = Message::user("Why is the sky blue?");
assert_eq!(user.text_content(), "Why is the sky blue?");
assert!(!user.is_multimodal());
// Tool results reference the call they answer.
let result = Message::tool(r#"{"temp_c":21}"#, "call_abc123");
assert_eq!(result.tool_call_id.as_deref(), Some("call_abc123"));Fields§
§role: RoleWho produced this message.
content: StringText content (for simple text-only messages).
content_blocks: Vec<ContentBlock>Multimodal content blocks. When non-empty, content is ignored.
tool_calls: Vec<ToolCall>Tool calls emitted by an assistant message.
tool_call_id: Option<String>The tool call ID this tool result corresponds to.
tool_error: boolWhether a tool result represents an error.
Implementations§
Source§impl Message
impl Message
Sourcepub fn assistant_with_tool_calls(
content: impl Into<String>,
tool_calls: Vec<ToolCall>,
) -> Self
pub fn assistant_with_tool_calls( content: impl Into<String>, tool_calls: Vec<ToolCall>, ) -> Self
Create an assistant message that includes tool calls.
Sourcepub fn tool(content: impl Into<String>, tool_call_id: impl Into<String>) -> Self
pub fn tool(content: impl Into<String>, tool_call_id: impl Into<String>) -> Self
Create a successful tool result message.
Sourcepub fn tool_error(
content: impl Into<String>,
tool_call_id: impl Into<String>,
) -> Self
pub fn tool_error( content: impl Into<String>, tool_call_id: impl Into<String>, ) -> Self
Create a tool result message that represents an error.
Sourcepub fn user_multimodal(content_blocks: Vec<ContentBlock>) -> Self
pub fn user_multimodal(content_blocks: Vec<ContentBlock>) -> Self
Create a user message with multimodal content blocks.
Sourcepub fn is_multimodal(&self) -> bool
pub fn is_multimodal(&self) -> bool
Check if this message has multimodal content.
Sourcepub fn has_tool_calls(&self) -> bool
pub fn has_tool_calls(&self) -> bool
Check whether the assistant message contains tool calls.
Sourcepub fn text_content(&self) -> String
pub fn text_content(&self) -> String
Get the text content of this message.
For multimodal messages, this concatenates all text blocks.