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>,
}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.
Implementations§
Source§impl Message
impl Message
pub fn system(content: impl Into<String>) -> Self
pub fn user(content: impl Into<String>) -> Self
Sourcepub fn from_origin(origin: MessageOrigin, content: impl Into<String>) -> Self
pub fn from_origin(origin: MessageOrigin, content: impl Into<String>) -> Self
A user-role message injected by the harness or a hook.
Sourcepub fn hook_note(content: impl Into<String>) -> Self
pub fn hook_note(content: impl Into<String>) -> Self
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>) -> Self
pub fn tool_result( call_id: impl Into<String>, content: impl Into<String>, ) -> Self
Sourcepub fn with_images(self, images: impl IntoIterator<Item = Image>) -> Self
pub fn with_images(self, images: impl IntoIterator<Item = Image>) -> Self
Attach images (see Image).
Sourcepub fn with_audio(self, audio: impl IntoIterator<Item = Audio>) -> Self
pub fn with_audio(self, audio: impl IntoIterator<Item = Audio>) -> Self
Attach audio (see Audio).
Sourcepub fn with_reasoning(self, reasoning: Option<String>) -> Self
pub fn with_reasoning(self, reasoning: Option<String>) -> Self
Mark a tool result as an error.
pub fn with_error(self, is_error: bool) -> Self
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<&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).