pub struct Message {
pub role: Role,
pub content: String,
pub reasoning_content: String,
pub tool_call_id: CompactString,
pub tool_calls: SmallVec<[ToolCall; 4]>,
pub sender: CompactString,
}Expand description
A message in the chat
Fields§
§role: RoleThe role of the message
content: StringThe content of the message
reasoning_content: StringThe reasoning content
tool_call_id: CompactStringThe tool call id
tool_calls: SmallVec<[ToolCall; 4]>The tool calls
sender: CompactStringThe sender identity (runtime-only, never serialized to providers).
Convention: empty = local/owner, "tg:12345" = Telegram user,
"dc:67890" = Discord user.
Implementations§
Source§impl Message
impl Message
Sourcepub fn user_with_sender(
content: impl Into<String>,
sender: impl Into<CompactString>,
) -> Self
pub fn user_with_sender( content: impl Into<String>, sender: impl Into<CompactString>, ) -> Self
Create a new user message with sender identity.
Sourcepub fn assistant(
content: impl Into<String>,
reasoning: Option<String>,
tool_calls: Option<&[ToolCall]>,
) -> Self
pub fn assistant( content: impl Into<String>, reasoning: Option<String>, tool_calls: Option<&[ToolCall]>, ) -> Self
Create a new assistant message
Sourcepub fn tool(content: impl Into<String>, call: impl Into<CompactString>) -> Self
pub fn tool(content: impl Into<String>, call: impl Into<CompactString>) -> Self
Create a new tool message
Sourcepub fn builder(role: Role) -> MessageBuilder
pub fn builder(role: Role) -> MessageBuilder
Create a new message builder
Sourcepub fn estimate_tokens(&self) -> usize
pub fn estimate_tokens(&self) -> usize
Estimate the number of tokens in this message.
Uses a simple heuristic: ~4 characters per token.
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