pub struct Message {
pub role: Role,
pub content: Option<String>,
pub tool_calls: Option<Vec<ToolCall>>,
pub tool_call_id: Option<String>,
}Expand description
A single message in a conversation.
Messages are the fundamental unit of communication with LLM providers. Each message has a role (who sent it), content (the text), and optionally tool calls (for function calling).
§Examples
§User Message
use limit_llm::{Message, Role};
let msg = Message {
role: Role::User,
content: Some("What is the capital of France?".to_string()),
tool_calls: None,
tool_call_id: None,
};§Assistant Message with Tool Call
use limit_llm::{Message, Role, ToolCall, FunctionCall};
let msg = Message {
role: Role::Assistant,
content: None,
tool_calls: Some(vec![ToolCall {
id: "call_123".to_string(),
tool_type: "function".to_string(),
function: FunctionCall {
name: "get_weather".to_string(),
arguments: r#"{"location": "Paris"}"#.to_string(),
},
}]),
tool_call_id: None,
};§Tool Result Message
use limit_llm::{Message, Role};
let msg = Message {
role: Role::Tool,
content: Some(r#"{"temp": 22, "condition": "sunny"}"#.to_string()),
tool_calls: None,
tool_call_id: Some("call_123".to_string()),
};Fields§
§role: RoleThe role of the message sender.
content: Option<String>The text content of the message.
Can be None for assistant messages that only contain tool calls.
tool_calls: Option<Vec<ToolCall>>Tool calls made by the assistant.
Only present in assistant messages when the LLM decides to call tools.
tool_call_id: Option<String>ID of the tool call this message is responding to.
Only present in tool result messages.
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>,
Deserialize this value from the given Serde deserializer. Read more
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
Mutably borrows from an owned value. Read more