pub struct Message {
pub role: Role,
pub content: String,
pub parts: Vec<MessagePart>,
pub metadata: MessageMetadata,
}Expand description
A single message in a conversation.
Each message has a Role, a flat content string (used when sending to providers
that do not support structured parts), and an optional list of MessageParts for
providers that accept heterogeneous content blocks (e.g. Claude).
The content field is kept in sync with parts via Message::rebuild_content.
When building messages from structured parts, always use Message::from_parts —
it populates both parts and content.
§Examples
use zeph_llm::provider::{Message, MessagePart, Role};
// Simple text-only message
let msg = Message::from_legacy(Role::User, "What is Rust?");
assert_eq!(msg.to_llm_content(), "What is Rust?");
// Structured message with parts
let parts = vec![
MessagePart::Text { text: "Explain this code.".into() },
];
let msg = Message::from_parts(Role::User, parts);
assert!(!msg.parts.is_empty());Fields§
§role: Role§content: StringFlat text representation of this message, derived from parts when structured.
parts: Vec<MessagePart>§metadata: MessageMetadataImplementations§
Source§impl Message
impl Message
Sourcepub fn from_legacy(role: Role, content: impl Into<String>) -> Self
pub fn from_legacy(role: Role, content: impl Into<String>) -> Self
Create a simple text-only message without structured parts.
Use this constructor for system prompts, plain user turns, and assistant messages produced by providers that return a raw string.
Sourcepub fn from_parts(role: Role, parts: Vec<MessagePart>) -> Self
pub fn from_parts(role: Role, parts: Vec<MessagePart>) -> Self
Create a message from structured parts, deriving the flat content automatically.
Prefer this constructor when the message contains tool invocations, images, or other non-text content that providers need to render as separate content blocks.
Sourcepub fn to_llm_content(&self) -> &str
pub fn to_llm_content(&self) -> &str
Return the flat text content of this message, suitable for providers that do not support structured content blocks.
Sourcepub fn rebuild_content(&mut self)
pub fn rebuild_content(&mut self)
Re-synchronize content from parts after in-place mutation.