pub struct Message {
pub id: Option<String>,
pub role: Role,
pub created: i64,
pub content: Vec<MessageContent>,
pub metadata: MessageMetadata,
}Expand description
A message to or from an LLM
Fields§
§id: Option<String>§role: Role§created: i64§content: Vec<MessageContent>§metadata: MessageMetadataImplementations§
Source§impl Message
impl Message
pub fn new(role: Role, created: i64, content: Vec<MessageContent>) -> Self
pub fn debug(&self) -> String
pub fn with_id<S: Into<String>>(self, id: S) -> Self
Sourcepub fn with_content(self, content: MessageContent) -> Self
pub fn with_content(self, content: MessageContent) -> Self
Add any MessageContent to the message
Sourcepub fn with_image<S: Into<String>, T: Into<String>>(
self,
data: S,
mime_type: T,
) -> Self
pub fn with_image<S: Into<String>, T: Into<String>>( self, data: S, mime_type: T, ) -> Self
Add image content to the message
Sourcepub fn with_tool_request<S: Into<String>>(
self,
id: S,
tool_call: ToolResult<CallToolRequestParam>,
) -> Self
pub fn with_tool_request<S: Into<String>>( self, id: S, tool_call: ToolResult<CallToolRequestParam>, ) -> Self
Add a tool request to the message
pub fn with_tool_request_with_metadata<S: Into<String>>( self, id: S, tool_call: ToolResult<CallToolRequestParam>, metadata: Option<&ProviderMetadata>, tool_meta: Option<Value>, ) -> Self
Sourcepub fn with_tool_response<S: Into<String>>(
self,
id: S,
result: ToolResult<CallToolResult>,
) -> Self
pub fn with_tool_response<S: Into<String>>( self, id: S, result: ToolResult<CallToolResult>, ) -> Self
Add a tool response to the message
pub fn with_tool_response_with_metadata<S: Into<String>>( self, id: S, result: ToolResult<CallToolResult>, metadata: Option<&ProviderMetadata>, ) -> Self
Sourcepub fn with_action_required<S: Into<String>>(
self,
id: S,
tool_name: String,
arguments: JsonObject,
prompt: Option<String>,
) -> Self
pub fn with_action_required<S: Into<String>>( self, id: S, tool_name: String, arguments: JsonObject, prompt: Option<String>, ) -> Self
Add an action required message for tool confirmation
pub fn with_frontend_tool_request<S: Into<String>>( self, id: S, tool_call: ToolResult<CallToolRequestParam>, ) -> Self
Sourcepub fn with_thinking<S1: Into<String>, S2: Into<String>>(
self,
thinking: S1,
signature: S2,
) -> Self
pub fn with_thinking<S1: Into<String>, S2: Into<String>>( self, thinking: S1, signature: S2, ) -> Self
Add thinking content to the message
Sourcepub fn with_redacted_thinking<S: Into<String>>(self, data: S) -> Self
pub fn with_redacted_thinking<S: Into<String>>(self, data: S) -> Self
Add redacted thinking content to the message
Sourcepub fn as_concat_text(&self) -> String
pub fn as_concat_text(&self) -> String
Get the concatenated text content of the message, separated by newlines
Sourcepub fn is_tool_call(&self) -> bool
pub fn is_tool_call(&self) -> bool
Check if the message is a tool call
Sourcepub fn is_tool_response(&self) -> bool
pub fn is_tool_response(&self) -> bool
Check if the message is a tool response
Sourcepub fn get_tool_ids(&self) -> HashSet<&str>
pub fn get_tool_ids(&self) -> HashSet<&str>
Retrieves all tool id from the message
Sourcepub fn get_tool_request_ids(&self) -> HashSet<&str>
pub fn get_tool_request_ids(&self) -> HashSet<&str>
Retrieves all tool id from ToolRequest messages
Sourcepub fn get_tool_response_ids(&self) -> HashSet<&str>
pub fn get_tool_response_ids(&self) -> HashSet<&str>
Retrieves all tool id from ToolResponse messages
Sourcepub fn has_only_text_content(&self) -> bool
pub fn has_only_text_content(&self) -> bool
Check if the message has only TextContent
pub fn with_system_notification<S: Into<String>>( self, notification_type: SystemNotificationType, msg: S, ) -> Self
Sourcepub fn with_visibility(self, user_visible: bool, agent_visible: bool) -> Self
pub fn with_visibility(self, user_visible: bool, agent_visible: bool) -> Self
Set the visibility metadata for the message
Sourcepub fn with_metadata(self, metadata: MessageMetadata) -> Self
pub fn with_metadata(self, metadata: MessageMetadata) -> Self
Set the entire metadata for the message
Sourcepub fn agent_only(self) -> Self
pub fn agent_only(self) -> Self
Mark the message as only visible to the agent (not the user)
Sourcepub fn is_user_visible(&self) -> bool
pub fn is_user_visible(&self) -> bool
Check if the message is visible to the user
Sourcepub fn is_agent_visible(&self) -> bool
pub fn is_agent_visible(&self) -> bool
Check if the message is visible to the agent
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<PromptMessage> for Message
impl From<PromptMessage> for Message
Source§fn from(prompt_message: PromptMessage) -> Self
fn from(prompt_message: PromptMessage) -> Self
Source§impl<'__s> ToSchema<'__s> for Message
impl<'__s> ToSchema<'__s> for Message
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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> 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<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.