#[non_exhaustive]pub enum MessageContent {
Text(String),
Json(Value),
ToolCall {
id: String,
name: String,
arguments: Value,
},
ToolResult {
tool_call_id: String,
content: String,
is_error: bool,
},
}Expand description
Content of a message, supporting text, JSON, and tool interactions.
Most messages use MessageContent::Text, but tool calling workflows
require MessageContent::ToolCall and MessageContent::ToolResult.
§Examples
use multi_llm::MessageContent;
// Plain text (most common)
let text = MessageContent::Text("Hello, world!".to_string());
// Structured JSON content
let json = MessageContent::Json(serde_json::json!({
"intent": "greeting",
"confidence": 0.95
}));
// Tool call from assistant
let tool_call = MessageContent::ToolCall {
id: "call_123".to_string(),
name: "get_weather".to_string(),
arguments: serde_json::json!({"city": "London"}),
};
// Tool result to send back
let tool_result = MessageContent::ToolResult {
tool_call_id: "call_123".to_string(),
content: "Sunny, 22°C".to_string(),
is_error: false,
};Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Text(String)
Plain text content.
This is the most common content type, used for regular conversation.
Json(Value)
Structured JSON content.
Useful for passing structured data that doesn’t fit the tool calling model, or for internal processing of parsed LLM outputs.
ToolCall
Tool/function call request from the assistant.
When the LLM decides to call a tool, it returns this content type.
Your application should execute the tool and return a MessageContent::ToolResult.
Fields
ToolResult
Result from executing a tool.
After executing a tool call, send the result back using this content type.
The tool_call_id must match the id from the corresponding ToolCall.
Trait Implementations§
Source§impl Clone for MessageContent
impl Clone for MessageContent
Source§fn clone(&self) -> MessageContent
fn clone(&self) -> MessageContent
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MessageContent
impl Debug for MessageContent
Source§impl<'de> Deserialize<'de> for MessageContent
impl<'de> Deserialize<'de> for MessageContent
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>,
Source§impl Display for MessageContent
impl Display for MessageContent
Source§impl PartialEq for MessageContent
impl PartialEq for MessageContent
Source§impl Serialize for MessageContent
impl Serialize for MessageContent
impl StructuralPartialEq for MessageContent
Auto Trait Implementations§
impl Freeze for MessageContent
impl RefUnwindSafe for MessageContent
impl Send for MessageContent
impl Sync for MessageContent
impl Unpin for MessageContent
impl UnwindSafe for MessageContent
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.