pub struct Message {
pub role: String,
pub name: Option<String>,
pub content: Option<String>,
pub tool_calls: Option<Vec<ToolCall>>,
pub tool_call_id: Option<String>,
pub image_base64: Option<String>,
}Expand description
One message in an OpenAI Chat Completions conversation. Spec: https://platform.openai.com/docs/api-reference/chat/create#chat/create-messages
One struct, four roles (system / user / assistant / tool); each
role uses a different subset of the optional fields. skip_serializing_if
on every Option prunes irrelevant fields at serialization, so the wire
JSON for each role only carries what OpenAI expects:
system → role + content
user → role + content (+ optional name for multi-user)
assistant → role + content (may be null when only tool_calls are emitted)
+ optional tool_calls[]
tool → role + content + tool_call_id (must match an id in the
preceding assistant.tool_calls)
We use a flat struct with optional fields rather than a tagged enum because
the planner does a lot of generic Vecmatch on every
access. Type-safety for “tool messages must have tool_call_id” is delegated
to runtime checks (history::sanitize_for_vlm) and the OpenAI server’s
own validation.
image_base64 is a robonix-side simplification, NOT part of the OpenAI
wire format. Callers set it on a user message; build_openai_messages
in this file repackages content + image into OpenAI’s multimodal content
array ([{type:"text",...}, {type:"image_url",...}]) at request time.
Fields§
§role: String“system” / “user” / “assistant” / “tool”. Determines which other fields are meaningful; OpenAI rejects mismatched combinations.
name: Option<String>Optional sender name. Used by user/assistant for multi-user
disambiguation; rare in practice. Robonix doesn’t set it today.
content: Option<String>Message text. Always present except on assistant messages whose
only output is tool calls (then None / null on the wire).
tool_calls: Option<Vec<ToolCall>>Tool calls the LLM decided to make. Present only on assistant
messages. Each entry carries id + function.{name, arguments};
the corresponding tool message links back via tool_call_id.
tool_call_id: Option<String>Correlates a tool result back to the assistant.tool_calls[].id
that produced it. Required on tool messages; absent on others.
image_base64: Option<String>Inline image attached to a user message (base64-encoded JPEG
bytes). Robonix-only field; rewritten into OpenAI’s multimodal
content array at serialize time by build_openai_messages.
Implementations§
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>,
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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].