pub enum Message {
System(String),
User(Vec<ContentBlock>),
Assistant {
content: String,
reasoning: Option<String>,
tool_calls: Vec<ToolCall>,
},
ToolResult {
id: String,
content: String,
},
}Expand description
A single message in a conversation.
This type carries context uniformly between Provider / Memory / Agent:
what Memory stores and returns, and what Provider sends and receives,
are all Message sequences; Provider implementations map them to the
vendor’s wire format.
Note: the model may request several tools in one turn, and these requests
must stay in a single Message::Assistant message — splitting them
across messages breaks vendor wire validation (some vendors require tool
results to immediately follow the assistant message carrying them, e.g.
DeepSeek).
§Example
Organize a conversation history with the convenience constructors (in real scenarios the agent loop and Memory do this automatically):
use molo::Message;
let history = vec![
Message::system("You are a helpful assistant"),
Message::user("How is the weather in Beijing today?"),
Message::assistant("Let me check the weather."),
Message::tool_result("call_1", "Sunny, 23°C"),
];
assert_eq!(history.len(), 4);
assert_eq!(history[1], Message::user("How is the weather in Beijing today?"));Variants§
System(String)
System instruction describing the agent’s role and behavior constraints.
User(Vec<ContentBlock>)
User input, made of content blocks (currently text only; multimodal blocks are added as real needs arise).
Assistant
Assistant reply: text + reasoning + requested tool calls (multiple requests in one turn stay together).
Fields
reasoning: Option<String>The model’s reasoning; provided by thinking models (e.g.
DeepSeek / Qwen3), None for other models.
This field is a vendor extension and must be passed back verbatim when sending the conversation history, otherwise the API rejects the request (e.g. DeepSeek reports “The reasoning_content in the thinking mode must be passed back to the API.”).
tool_calls: Vec<ToolCall>Tools requested by the model with this reply; execution results
are passed back right after as Message::ToolResult messages.
ToolResult
Tool execution result, passed back to the model.
Fields
id: StringThe id corresponding to ToolCall::id.
Implementations§
Source§impl Message
impl Message
Sourcepub fn user(content: impl Into<String>) -> Self
pub fn user(content: impl Into<String>) -> Self
A plain-text user message (a single text block, equivalent to
user_blocks(vec![ContentBlock::Text(content)])).
Sourcepub fn user_blocks(blocks: Vec<ContentBlock>) -> Self
pub fn user_blocks(blocks: Vec<ContentBlock>) -> Self
User input made of content blocks (currently text only; multimodal blocks are added as real needs arise).
Sourcepub fn assistant(content: impl Into<String>) -> Self
pub fn assistant(content: impl Into<String>) -> Self
An assistant reply message (no reasoning, no tool requests).
Sourcepub fn assistant_with_reasoning(
content: impl Into<String>,
reasoning: impl Into<String>,
) -> Self
pub fn assistant_with_reasoning( content: impl Into<String>, reasoning: impl Into<String>, ) -> Self
An assistant reply with reasoning (for thinking models; pass
reasoning back verbatim when sending history, otherwise the API
rejects the request).
Sourcepub fn tool_result(id: impl Into<String>, content: impl Into<String>) -> Self
pub fn tool_result(id: impl Into<String>, content: impl Into<String>) -> Self
A tool execution result passed back to the model; id corresponds to
the ToolCall::id in the Message::Assistant message that
carried the request.
§Example
use molo::Message;
let result = Message::tool_result("call_1", "Sunny, 23°C");
assert_eq!(result, Message::ToolResult {
id: "call_1".into(),
content: "Sunny, 23°C".into(),
});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>,
impl Eq for Message
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.