#[non_exhaustive]pub enum UserBlock {
Text {
text: String,
cache_control: Option<CacheControl>,
},
ToolResult {
call_id: String,
content: ToolResultContent,
cache_control: Option<CacheControl>,
},
Image {
source: Source,
cache_control: Option<CacheControl>,
},
Document {
source: Source,
cache_control: Option<CacheControl>,
},
}Expand description
One block inside a Message::User turn.
Free user text, tool results, and inline media (images, documents) all live here because providers route tool results — and the rest of the multimodal surface — back through the user role on the wire.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Text
Free user text.
Fields
cache_control: Option<CacheControl>Per-request cache hint. #[serde(skip)] — the cache
breakpoint is a per-call directive to the provider, not
part of the persisted conversation state, so it is dropped
on snapshot round-trip and restored as None.
ToolResult
Result of a tool invocation paired with the assistant
AssistantBlock::ToolCall of the previous turn (matched by
id).
Fields
call_id: StringMatches the id on the originating AssistantBlock::ToolCall.
content: ToolResultContentThe tool’s reply. content.is_error flags tool-reported
failures separately from the block list, so an error reply
can still carry images.
cache_control: Option<CacheControl>Image
Image content rendered inline. Adapters map this to the
provider’s image content type (Anthropic image, Chat
Completions image_url). Adapters that cannot represent the
chosen Source (e.g. a Chat Completions deployment with no
vision support) surface a typed error.
Fields
cache_control: Option<CacheControl>Document
Document content rendered inline (PDF and similar). Anthropic
has a dedicated document content type; Chat Completions does
not, so the Azure adapter surfaces a typed
UnsupportedContent error and callers downgrade via
ChatMiddleware::on_chat_request if they want a text
substitute.
Fields
cache_control: Option<CacheControl>Implementations§
Source§impl UserBlock
impl UserBlock
Sourcepub fn text(text: impl Into<String>) -> Self
pub fn text(text: impl Into<String>) -> Self
Build a UserBlock::Text with no cache breakpoint.
Sourcepub fn tool_result(
call_id: impl Into<String>,
content: impl Into<ToolResultContent>,
) -> Self
pub fn tool_result( call_id: impl Into<String>, content: impl Into<ToolResultContent>, ) -> Self
Build a UserBlock::ToolResult with no cache breakpoint. The
content argument is anything that converts into
ToolResultContent — String and &str produce a single
text block with is_error = false. Use
ToolResultContent::error to flag a tool-reported failure or
ToolResultContent::from_blocks to build a multi-block reply.
Sourcepub fn image(source: Source) -> Self
pub fn image(source: Source) -> Self
Build a UserBlock::Image with no cache breakpoint.
Sourcepub fn document(source: Source) -> Self
pub fn document(source: Source) -> Self
Build a UserBlock::Document with no cache breakpoint.
Sourcepub fn with_cache_control(self, cache_control: Option<CacheControl>) -> Self
pub fn with_cache_control(self, cache_control: Option<CacheControl>) -> Self
Builder-style helper: set or replace the cache breakpoint on this
block. Use None to clear.
Sourcepub fn cache_control(&self) -> Option<&CacheControl>
pub fn cache_control(&self) -> Option<&CacheControl>
Read the current cache breakpoint, if any.