#[non_exhaustive]pub enum MessagePart {
Text {
text: String,
},
ToolOutput {
tool_name: ToolName,
body: String,
compacted_at: Option<i64>,
},
Recall {
text: String,
},
CodeContext {
text: String,
},
Summary {
text: String,
},
CrossSession {
text: String,
},
ToolUse {
id: String,
name: String,
input: Value,
},
ToolResult {
tool_use_id: String,
content: String,
is_error: bool,
},
Image(Box<ImageData>),
ThinkingBlock {
thinking: String,
signature: String,
},
RedactedThinkingBlock {
data: String,
},
Compaction {
summary: String,
},
}Expand description
A typed content part within a Message.
Messages may contain zero or more parts that represent heterogeneous content: plain text, tool invocations, memory recall fragments, images, and internal protocol blocks (thinking, compaction). Most providers flatten these into a single string before sending; Claude encodes them as structured content blocks.
§Ordering invariants
ToolUseparts must precede their correspondingToolResultparts.ThinkingBlock/RedactedThinkingBlockparts must be preserved verbatim in multi-turn requests so the API can correctly attribute reasoning.Compactionparts must be preserved verbatim; the API uses them to prune prior history on subsequent turns (Claude compact-2026-01-12 beta).
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Text
Plain assistant or user text.
ToolOutput
Output from a tool execution, optionally compacted.
Recall
Memory recall fragment injected by the agent’s semantic memory layer.
CodeContext
Repository or file code context injected by the code indexing layer.
Summary
Compaction summary replacing pruned conversation history.
CrossSession
Cross-session memory fragment carried over from a previous conversation.
ToolUse
Model-initiated tool invocation. Pairs with a subsequent MessagePart::ToolResult.
ToolResult
Tool execution result returned to the model after a MessagePart::ToolUse.
Image(Box<ImageData>)
Inline image payload (vision input).
ThinkingBlock
Claude thinking block — must be preserved verbatim in multi-turn requests.
RedactedThinkingBlock
Claude redacted thinking block — preserved as-is in multi-turn requests.
Compaction
Claude server-side compaction block — must be preserved verbatim in multi-turn requests so the API can correctly prune prior history on the next turn.
Implementations§
Source§impl MessagePart
impl MessagePart
Sourcepub fn as_plain_text(&self) -> Option<&str>
pub fn as_plain_text(&self) -> Option<&str>
Return the plain text content if this part is a text-like variant (Text, Recall,
CodeContext, Summary, CrossSession), None otherwise.
Trait Implementations§
Source§impl Clone for MessagePart
impl Clone for MessagePart
Source§fn clone(&self) -> MessagePart
fn clone(&self) -> MessagePart
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more