pub enum Message {
Developer {
id: MessageId,
content: String,
name: Option<String>,
},
System {
id: MessageId,
content: String,
name: Option<String>,
},
Assistant {
id: MessageId,
content: Option<String>,
name: Option<String>,
tool_calls: Option<Vec<ToolCall>>,
},
User {
id: MessageId,
content: String,
name: Option<String>,
},
Tool {
id: MessageId,
content: String,
tool_call_id: ToolCallId,
error: Option<String>,
},
Activity {
id: MessageId,
activity_type: String,
content: Value,
},
}Expand description
Represents the different types of messages in a conversation.
This enum provides a unified type for all message variants, using the role field as the discriminant for JSON serialization.
Variants§
Developer
A developer message for debugging.
System
A system message (usually the system prompt).
Assistant
An assistant message from the AI model.
User
A user message from the human user.
Tool
A tool message containing tool call results.
Activity
An activity message for tracking agent activities.
Implementations§
Source§impl Message
impl Message
Sourcepub fn new<S>(role: Role, id: impl Into<MessageId>, content: S) -> Message
pub fn new<S>(role: Role, id: impl Into<MessageId>, content: S) -> Message
Creates a new message with the given role, ID, and content.
Sourcepub fn new_system<S>(content: S) -> Message
pub fn new_system<S>(content: S) -> Message
Creates a new system message with a random ID.
Sourcepub fn new_assistant<S>(content: S) -> Message
pub fn new_assistant<S>(content: S) -> Message
Creates a new assistant message with a random ID.
Sourcepub fn new_developer<S>(content: S) -> Message
pub fn new_developer<S>(content: S) -> Message
Creates a new developer message with a random ID.
Sourcepub fn new_activity(activity_type: impl Into<String>, content: Value) -> Message
pub fn new_activity(activity_type: impl Into<String>, content: Value) -> Message
Creates a new activity message with a random ID.
Sourcepub fn content(&self) -> Option<&str>
pub fn content(&self) -> Option<&str>
Returns the content of this message, if any.
Note: Activity messages have JSON content, not string content.
Use activity_content() to access their content.
Sourcepub fn content_mut(&mut self) -> Option<&mut String>
pub fn content_mut(&mut self) -> Option<&mut String>
Returns a mutable reference to the content of this message.
Note: Activity messages have JSON content, not string content.
Use activity_content_mut() to modify their content.
Sourcepub fn activity_content(&self) -> Option<&Value>
pub fn activity_content(&self) -> Option<&Value>
Returns the activity content of this message, if it’s an activity message.
Sourcepub fn activity_content_mut(&mut self) -> Option<&mut Value>
pub fn activity_content_mut(&mut self) -> Option<&mut Value>
Returns a mutable reference to the activity content, if it’s an activity message.
Sourcepub fn activity_type(&self) -> Option<&str>
pub fn activity_type(&self) -> Option<&str>
Returns the activity type, if this is an activity message.
Sourcepub fn tool_calls(&self) -> Option<&[ToolCall]>
pub fn tool_calls(&self) -> Option<&[ToolCall]>
Returns the tool calls for this message, if any.
Sourcepub fn tool_calls_mut(&mut self) -> Option<&mut Vec<ToolCall>>
pub fn tool_calls_mut(&mut self) -> Option<&mut Vec<ToolCall>>
Returns a mutable reference to the tool calls for this message.