pub struct Message {
pub id: MessageId,
pub role: Role,
pub content: Vec<ContentPart>,
pub created_at: SystemTime,
}Expand description
A message in a conversation
Messages are the fundamental unit of conversation. Each message has:
- An ID for tracking and referencing
- A role (who sent it)
- Content (what was said/done)
- Timestamps for ordering and history
§Content Model
Messages contain a vector of ContentParts, allowing for:
- Simple text-only messages
- Messages with multiple tool calls
- Mixed content (text + tool calls)
Fields§
§id: MessageIdUnique identifier for this message
role: RoleWho sent this message
content: Vec<ContentPart>The message content (can have multiple parts)
created_at: SystemTimeWhen the message was created
Implementations§
Source§impl Message
impl Message
Sourcepub fn new(role: Role, content: Vec<ContentPart>) -> Self
pub fn new(role: Role, content: Vec<ContentPart>) -> Self
Create a new message with the given role and content
Sourcepub fn assistant(content: Vec<ContentPart>) -> Self
pub fn assistant(content: Vec<ContentPart>) -> Self
Create an assistant message with the given content parts
Sourcepub fn assistant_text(text: impl Into<String>) -> Self
pub fn assistant_text(text: impl Into<String>) -> Self
Create an assistant message with just text
Sourcepub fn tool_results(results: Vec<ToolResult>) -> Self
pub fn tool_results(results: Vec<ToolResult>) -> Self
Create a user message containing tool results
Sourcepub fn text_content(&self) -> String
pub fn text_content(&self) -> String
Get all text content concatenated
Useful for simple display or when you only care about text.
Sourcepub fn tool_calls(&self) -> Vec<&ToolCall>
pub fn tool_calls(&self) -> Vec<&ToolCall>
Get all tool calls in this message
Sourcepub fn has_tool_calls(&self) -> bool
pub fn has_tool_calls(&self) -> bool
Returns true if this message contains any tool calls
Sourcepub fn is_assistant(&self) -> bool
pub fn is_assistant(&self) -> bool
Returns true if this message is from the assistant
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
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
Mutably borrows from an owned value. Read more