pub enum Message {
System {
content: String,
},
User {
content: Vec<UserContent>,
},
Assistant {
id: Option<String>,
content: Vec<AssistantContent>,
},
}Expand description
A provider-agnostic chat message.
Messages are role-tagged and may contain one or many content items, including text, images, audio, documents, tool calls, and tool results. Provider modules are responsible for translating these generic messages into provider-native request bodies. That conversion may be lossy when a provider does not support a particular content type.
Variants§
System
System message containing instruction text.
User
User message containing one or more content types defined by UserContent.
Fields
content: Vec<UserContent>Assistant
Assistant message containing one or more content types defined by AssistantContent.
Implementations§
Source§impl Message
impl Message
Sourcepub fn rag_text(&self) -> Option<String>
pub fn rag_text(&self) -> Option<String>
This helper method is primarily used to extract the first string prompt from a Message.
Since Message might have more than just text content, we need to find the first text.
Sourcepub fn system(text: impl Into<String>) -> Message
pub fn system(text: impl Into<String>) -> Message
Helper constructor to make creating system messages easier.
Sourcepub fn user(text: impl Into<String>) -> Message
pub fn user(text: impl Into<String>) -> Message
Helper constructor to make creating user messages easier.
Sourcepub fn assistant(text: impl Into<String>) -> Message
pub fn assistant(text: impl Into<String>) -> Message
Helper constructor to make creating assistant messages easier.
Sourcepub fn tool_result(
call: impl Into<String>,
name: impl Into<String>,
content: impl Into<String>,
) -> Message
pub fn tool_result( call: impl Into<String>, name: impl Into<String>, content: impl Into<String>, ) -> Message
Helper constructor to make creating tool result messages easier.
call is the answered call’s correlation handle — echo
ToolCall::id; it is never recorded as a provider-issued
identifier (see UserContent::tool_result). name is the
executed tool’s name.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Message, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Message, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl From<AssistantContent> for Message
impl From<AssistantContent> for Message
Source§fn from(content: AssistantContent) -> Message
fn from(content: AssistantContent) -> Message
Source§impl From<Message> for Message
Conversion from provider Message to a completion message.
This is needed so that responses can be converted back into chat history.
impl From<Message> for Message
Conversion from provider Message to a completion message. This is needed so that responses can be converted back into chat history.
An assistant message with empty content and no thinking or tool calls
converts to empty message content — no fabricated empty-text block.
Such a message cannot be replayed through the request boundary
(validate_message_content rejects a content-less assistant message);
callers ingesting raw Ollama history should filter empty assistant
messages rather than expect rig to invent content for them. The agent
loop never produces this shape: it drops empty turns before history.
Source§impl From<ToolResult> for Message
impl From<ToolResult> for Message
Source§fn from(value: ToolResult) -> Message
fn from(value: ToolResult) -> Message
Source§impl From<ToolResultContent> for Message
impl From<ToolResultContent> for Message
Source§fn from(tool_result_content: ToolResultContent) -> Message
fn from(tool_result_content: ToolResultContent) -> Message
Source§impl From<UserContent> for Message
impl From<UserContent> for Message
Source§fn from(content: UserContent) -> Message
fn from(content: UserContent) -> Message
Source§impl Serialize for Message
impl Serialize for Message
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for Message
Source§impl TryFrom<Message> for Vec<Message>
Conversion from an internal Rig message (crate::message::Message) to a provider Message.
(Only User and Assistant variants are supported.)
impl TryFrom<Message> for Vec<Message>
Conversion from an internal Rig message (crate::message::Message) to a provider Message. (Only User and Assistant variants are supported.)