pub struct Message {
pub role: Role,
pub content: String,
pub tool_calls: Vec<ToolCall>,
pub tool_call_id: Option<String>,
pub images: Vec<Image>,
pub audio: Vec<Audio>,
pub is_error: bool,
pub origin: Option<MessageOrigin>,
pub reasoning: Option<String>,
pub sender: Option<String>,
}Expand description
A provider-neutral transcript entry.
The transcript stored in crate::RunState never contains the agent’s
instructions; they are prepended on every request so they survive any
future compaction and keep the cacheable prefix stable.
Fields§
§role: Role§content: String§tool_calls: Vec<ToolCall>§tool_call_id: Option<String>Set on Role::Tool messages: the call this result answers.
images: Vec<Image>Images on Role::User and Role::Tool messages, in order after the
text. Providers ignore them on other roles.
audio: Vec<Audio>Audio on Role::User messages. Providers ignore it on other roles.
is_error: boolSet on Role::Tool messages whose receipt is not a success, so
providers can flag the result (for example Anthropic’s is_error).
origin: Option<MessageOrigin>Who injected a Role::User message, or MessageOrigin::HookNote
on a hook’s system note. None otherwise.
reasoning: Option<String>The model’s visible reasoning for this Role::Assistant turn, kept
for the transcript. Providers do not send it back: what a provider
must replay (Anthropic’s signed thinking) rides on
ToolCall::provider_data.
sender: Option<String>Who typed a Role::User message, when the application tells people
apart (a group chat’s participants). None when it does not: a
one-person conversation, or history stored before senders were
recorded. The untrusted-content rule counts a string as the user’s
only when the run’s latest request and the message naming it share a
sender (see crate::UntrustedHook).
Implementations§
Source§impl Message
impl Message
pub fn system(content: impl Into<String>) -> Message
pub fn user(content: impl Into<String>) -> Message
Sourcepub fn from_origin(origin: MessageOrigin, content: impl Into<String>) -> Message
pub fn from_origin(origin: MessageOrigin, content: impl Into<String>) -> Message
A user-role message injected by the harness or a hook.
Sourcepub fn hook_note(content: impl Into<String>) -> Message
pub fn hook_note(content: impl Into<String>) -> Message
A system note a before_model hook adds to one request. Providers
that place notes apart from the transcript find them by this origin.
Sourcepub fn is_hook_note(&self) -> bool
pub fn is_hook_note(&self) -> bool
True for a Message::hook_note.
Sourcepub fn is_injected(&self) -> bool
pub fn is_injected(&self) -> bool
True for user-role messages the harness or a hook injected.
pub fn assistant( content: impl Into<String>, tool_calls: Vec<ToolCall>, ) -> Message
pub fn tool_result( call_id: impl Into<String>, content: impl Into<String>, ) -> Message
Sourcepub fn with_images(self, images: impl IntoIterator<Item = Image>) -> Message
pub fn with_images(self, images: impl IntoIterator<Item = Image>) -> Message
Attach images (see Image).
Sourcepub fn with_audio(self, audio: impl IntoIterator<Item = Audio>) -> Message
pub fn with_audio(self, audio: impl IntoIterator<Item = Audio>) -> Message
Attach audio (see Audio).
Sourcepub fn with_reasoning(self, reasoning: Option<String>) -> Message
pub fn with_reasoning(self, reasoning: Option<String>) -> Message
Mark a tool result as an error.
Sourcepub fn with_sender(self, sender: impl Into<String>) -> Message
pub fn with_sender(self, sender: impl Into<String>) -> Message
Attribute a user message to the person who typed it (see
Message::sender).
pub fn with_error(self, is_error: bool) -> Message
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>,
Source§impl From<&str> for Message
Plain text becomes a user message, so Agent::run and
RunState::with_user_message take either text or a built Message
(for example one with images).
impl From<&str> for Message
Plain text becomes a user message, so Agent::run and
RunState::with_user_message take either text or a built Message
(for example one with images).
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,
impl StructuralPartialEq for Message
Auto Trait Implementations§
impl Forget for Message
impl Freeze for Messagewhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
PhantomData<ToolCall>: Freeze,
PhantomData<Image>: Freeze,
PhantomData<Audio>: Freeze,
impl Move for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnsafeUnpin for Messagewhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<ToolCall>: UnsafeUnpin,
PhantomData<Image>: UnsafeUnpin,
PhantomData<Audio>: UnsafeUnpin,
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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 more