pub struct Message {
pub id: Option<String>,
pub role: String,
pub content: String,
pub tokens: Option<usize>,
pub thinking: Option<String>,
pub streaming: bool,
pub tool_calls: Option<Vector<ToolCall>>,
pub tool_name: Option<String>,
pub image: Option<Arc<PhotonImage>>,
}Expand description
A chat message in an LLM conversation.
Represents messages exchanged between users, assistants, and tools in a conversation. Supports various roles (user, assistant, system, tool) and optional features like streaming, thinking traces, and attached images.
§Fields
id- Optional unique identifier for the messagerole- The role of the message sender (“user”, “assistant”, “system”, “tool”)content- The text content of the messagetokens- Optional token count for the messagethinking- Optional reasoning/thinking trace (for extended thinking models)streaming- Whether this is a partial streaming responsetool_calls- Tool invocations requested by the assistanttool_name- Name of the tool (for tool role messages)image- Optional attached image (requires “image” feature)
§Example
use modular_agent_core::Message;
let user_msg = Message::user("What is the weather?".to_string());
let assistant_msg = Message::assistant("The weather is sunny.".to_string());
let system_msg = Message::system("You are a helpful assistant.".to_string());Fields§
§id: Option<String>Unique identifier for this message.
role: StringRole of the message sender: “user”, “assistant”, “system”, or “tool”.
content: StringText content of the message.
tokens: Option<usize>Token count for this message (if available).
thinking: Option<String>Reasoning/thinking trace for extended thinking models.
streaming: boolWhether this is a partial streaming response.
tool_calls: Option<Vector<ToolCall>>Tool calls requested by the assistant in this message.
tool_name: Option<String>Name of the tool (for tool role messages containing tool results).
image: Option<Arc<PhotonImage>>Attached image for multimodal messages (requires “image” feature).
Implementations§
Source§impl Message
impl Message
Sourcepub fn new(role: String, content: String) -> Self
pub fn new(role: String, content: String) -> Self
Creates a new message with the specified role and content.
§Arguments
role- The role of the message sendercontent- The text content of the message
Sourcepub fn system(content: String) -> Self
pub fn system(content: String) -> Self
Creates a system message with the given content.
System messages typically set the behavior or context for the assistant.
Sourcepub fn tool(tool_name: String, content: String) -> Self
pub fn tool(tool_name: String, content: String) -> Self
Creates a tool response message.
Tool messages contain the result of a tool call and are associated with a specific tool by name.
§Arguments
tool_name- The name of the tool that produced this resultcontent- The tool’s output/result as a string
Sourcepub fn with_image(self, image: Arc<PhotonImage>) -> Self
pub fn with_image(self, image: Arc<PhotonImage>) -> Self
Attaches an image to this message (builder pattern).
Only available when the “image” feature is enabled.
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>,
Source§impl From<Message> for AgentValue
impl From<Message> for AgentValue
Source§impl TryFrom<AgentValue> for Message
impl TryFrom<AgentValue> for Message
Source§type Error = AgentError
type Error = AgentError
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<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Source§impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
Source§fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
Source§impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
Source§type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
Source§fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, Dst> ConvAsUtil<Dst> for T
impl<T, Dst> ConvAsUtil<Dst> for T
Source§impl<T> ConvUtil for T
impl<T> ConvUtil for T
Source§fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
Source§fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more