pub struct Message {
pub id: MessageId,
pub role: MessageRole,
pub content: Vec<ContentPart>,
pub phase: Option<ExecutionPhase>,
pub thinking: Option<String>,
pub thinking_signature: Option<String>,
pub controls: Option<Controls>,
pub metadata: Option<HashMap<String, Value>>,
pub external_actor: Option<ExternalActor>,
pub created_at: DateTime<Utc>,
}Expand description
A message in the conversation
Fields§
§id: MessageIdUnique message ID (format: message_{32-hex})
role: MessageRoleMessage role
content: Vec<ContentPart>Message content as array of content parts (text, images, tool calls, tool results)
phase: Option<ExecutionPhase>Execution phase for this message.
Helps LLMs distinguish between intermediate working commentary and completed answers in multi-step tool-calling flows. Only set on agent (assistant) messages. Providers with native phase support (OpenAI GPT-5.x) send this value in the API request; others derive it from state but don’t send it to the provider.
thinking: Option<String>Thinking content from extended thinking models (Anthropic Claude) This is the model’s chain-of-thought reasoning before producing the response. Must be included in subsequent API calls when thinking is enabled.
thinking_signature: Option<String>Cryptographic signature for thinking content (Anthropic Claude) Required when sending thinking back in subsequent API calls.
controls: Option<Controls>Runtime controls (model, reasoning, etc.)
metadata: Option<HashMap<String, Value>>Message-level metadata
external_actor: Option<ExternalActor>External actor identity (for messages from external channels like Slack)
created_at: DateTime<Utc>Timestamp when the message was created
Implementations§
Source§impl Message
impl Message
Sourcepub fn assistant_with_tools(
content: impl Into<String>,
tool_calls: Vec<ToolCall>,
) -> Self
pub fn assistant_with_tools( content: impl Into<String>, tool_calls: Vec<ToolCall>, ) -> Self
Create a new assistant message with tool calls
Tool calls are stored as ContentPart::ToolCall in the content array alongside the text content. Empty text content is omitted to avoid LLM API errors (e.g., Anthropic requires non-empty text blocks).
Sourcepub fn tool_result(
tool_call_id: impl Into<String>,
result: Option<Value>,
error: Option<String>,
) -> Self
pub fn tool_result( tool_call_id: impl Into<String>, result: Option<Value>, error: Option<String>, ) -> Self
Create a tool result message
Sourcepub fn tool_result_with_images(
tool_call_id: impl Into<String>,
result: Option<Value>,
images: Vec<ToolResultImage>,
) -> Self
pub fn tool_result_with_images( tool_call_id: impl Into<String>, result: Option<Value>, images: Vec<ToolResultImage>, ) -> Self
Create a tool result message with images.
Images are included as ContentPart::Image alongside the ToolResult part.
When converted to LlmMessage, images become native image content blocks
that the LLM can see visually (not just stringified base64).
Sourcepub fn with_phase(self, phase: ExecutionPhase) -> Self
pub fn with_phase(self, phase: ExecutionPhase) -> Self
Set the execution phase on this message and return self.
Sourcepub fn tool_call_id(&self) -> Option<&str>
pub fn tool_call_id(&self) -> Option<&str>
Get the tool_call_id from a tool result message
Returns the tool_call_id from the first ToolResult content part, if any.
Sourcepub fn tool_calls(&self) -> Vec<&ToolCallContentPart>
pub fn tool_calls(&self) -> Vec<&ToolCallContentPart>
Get all tool calls from the message content
Sourcepub fn has_tool_calls(&self) -> bool
pub fn has_tool_calls(&self) -> bool
Check if this message has tool calls
Sourcepub fn tool_result_content(&self) -> Option<&ToolResultContentPart>
pub fn tool_result_content(&self) -> Option<&ToolResultContentPart>
Get the first tool result from the message content
Sourcepub fn content_to_llm_string(&self) -> String
pub fn content_to_llm_string(&self) -> String
Convert content to LLM-compatible string representation
Sourcepub fn to_openai_format(&self) -> Value
pub fn to_openai_format(&self) -> Value
Convert message to OpenAI-compatible format
Transforms internal message format to OpenAI API format:
agentrole →assistanttool_resultrole →tool(with tool_call_id at message level)- Tool calls formatted as
{id, type: "function", function: {name, arguments}}
Used by observability backends (e.g., Braintrust) that expect OpenAI format.
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 LlmMessage
impl From<&Message> for LlmMessage
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> 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> 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::Request