pub struct Message {
pub role: Role,
pub content: String,
pub name: Option<String>,
pub tool_call_id: Option<String>,
pub tool_calls: Option<Vec<ToolCall>>,
}Expand description
A message in a conversation.
Fields§
§role: RoleRole of the message sender
content: StringContent of the message
name: Option<String>Optional name (for multi-user conversations or tool calls)
tool_call_id: Option<String>Tool call ID (for tool role messages)
tool_calls: Option<Vec<ToolCall>>Tool calls emitted by the assistant.
Implementations§
Source§impl Message
impl Message
Sourcepub fn user(content: impl Into<String>) -> Message
pub fn user(content: impl Into<String>) -> Message
Create a user message.
§Example
use simple_agent_type::message::{Message, Role};
let msg = Message::user("Hello!");
assert_eq!(msg.role, Role::User);
assert_eq!(msg.content, "Hello!");Sourcepub fn assistant(content: impl Into<String>) -> Message
pub fn assistant(content: impl Into<String>) -> Message
Create an assistant message.
§Example
use simple_agent_type::message::{Message, Role};
let msg = Message::assistant("Hi there!");
assert_eq!(msg.role, Role::Assistant);Sourcepub fn system(content: impl Into<String>) -> Message
pub fn system(content: impl Into<String>) -> Message
Create a system message.
§Example
use simple_agent_type::message::{Message, Role};
let msg = Message::system("You are a helpful assistant.");
assert_eq!(msg.role, Role::System);Sourcepub fn tool(
content: impl Into<String>,
tool_call_id: impl Into<String>,
) -> Message
pub fn tool( content: impl Into<String>, tool_call_id: impl Into<String>, ) -> Message
Create a tool message.
§Example
use simple_agent_type::message::{Message, Role};
let msg = Message::tool("result", "call_123");
assert_eq!(msg.role, Role::Tool);
assert_eq!(msg.tool_call_id, Some("call_123".to_string()));Sourcepub fn with_name(self, name: impl Into<String>) -> Message
pub fn with_name(self, name: impl Into<String>) -> Message
Set the name field (builder pattern).
§Example
use simple_agent_type::message::Message;
let msg = Message::user("Hello").with_name("Alice");
assert_eq!(msg.name, Some("Alice".to_string()));Sourcepub fn with_tool_calls(self, tool_calls: Vec<ToolCall>) -> Message
pub fn with_tool_calls(self, tool_calls: Vec<ToolCall>) -> Message
Set tool calls for assistant messages.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Message, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Message, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for Message
impl Serialize for Message
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. 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