ContentPart

Content part of a ModelMessage. Sealed so consumers exhaust over variants — adding a new content type forces a compile error at every dispatch site.

Approval-related parts:

  • ToolApprovalRequest appears on assistant messages when a tool called by the model needs approval before execution. Per v6 semantics, generation completes after emitting these parts; the host inspects them and calls Agent.generate again with…

  • ToolApprovalResponse on a tool message — one per pending approval — to resume the loop.

Inheritors

Types

Link copied to clipboard
@SerialName(value = "file")
class File(val mediaType: String, val base64: String = "", val filename: String? = null, val providerMetadata: ProviderMetadata = ProviderMetadata.None, val url: String? = null) : ContentPart

File content — payload data the model produced or that's attached to a turn. Per historical parity gap #38, mirrors v6's richer FilePart.data. Currently base64 is the only data shape; a URL-shaped variant lives in Source. filename is the user-facing label (Anthropic models produce it for artifact-like outputs; v6 has a dedicated slot for it).

Link copied to clipboard
@SerialName(value = "image")
class Image(val mediaType: String, val base64: String = "", val providerMetadata: ProviderMetadata = ProviderMetadata.None, val url: String? = null) : ContentPart

Image content — distinct from generic File so multimodal models (vision providers, image-generation tools) get a typed variant. Per historical parity gap #39, mirrors v6's ImagePart. mediaType is the MIME type (e.g. image/png); base64 is the raw image bytes encoded.

Link copied to clipboard
@SerialName(value = "raw")
class Raw(val rawValue: JsonElement) : ContentPart

Forward-compatible escape hatch for content parts a gateway or provider knows about before this SDK does. The raw JSON is preserved so callers can inspect or round-trip it instead of silently losing content.

Link copied to clipboard
@SerialName(value = "reasoning")
class Reasoning(val text: String, val providerMetadata: ProviderMetadata = ProviderMetadata.None) : ContentPart
Link copied to clipboard
@SerialName(value = "source")
class Source(val sourceType: StreamEvent.SourcePart.SourceType, val sourceId: String? = null, val url: String? = null, val title: String? = null, val providerMetadata: ProviderMetadata = ProviderMetadata.None, val mediaType: String? = null, val filename: String? = null) : ContentPart
Link copied to clipboard
@SerialName(value = "text")
class Text(val text: String, val providerMetadata: ProviderMetadata = ProviderMetadata.None) : ContentPart
Link copied to clipboard
@SerialName(value = "tool-approval-request")
data class ToolApprovalRequest(val toolCallId: String, val toolName: String, val input: JsonElement, val approvalId: String? = null, val signature: String? = null, val providerMetadata: ProviderMetadata = ProviderMetadata.None) : ContentPart

Assistant content: the LLM called a tool that requires approval.

Link copied to clipboard
@SerialName(value = "tool-approval-response")
class ToolApprovalResponse(val toolCallId: String, val approved: Boolean, val reason: String? = null, val approvalId: String? = null) : ContentPart

Tool content: the host's decision on a previously requested approval.

Link copied to clipboard
@SerialName(value = "tool-call")
class ToolCall(val toolCallId: String, val toolName: String, val input: JsonElement, val providerExecuted: Boolean = false, val dynamic: Boolean = false, val providerMetadata: ProviderMetadata = ProviderMetadata.None) : ContentPart
Link copied to clipboard
@SerialName(value = "tool-result")
class ToolResult(val toolCallId: String, val toolName: String, val output: JsonElement, val isError: Boolean = false, val modelVisible: JsonElement = output, val dynamic: Boolean = false, val providerExecuted: Boolean = false, val providerMetadata: ProviderMetadata = ProviderMetadata.None) : ContentPart

Tool execution result. output is the canonical FULL payload — persisted, dispatched to UI converters, rendered as the rich card. modelVisible is what the LLM provider includes in the prompt on subsequent turns — defaults to output, but tools with a toModelOutput callback (see Tool.toModelOutput) supply a short summary so multi-turn conversations don't keep re-feeding 10k+ tokens of structured payload into the model's KV cache. The two are intentionally separate: rehydrating the UI card needs the full schema; the model only needs enough context to compose a follow-up response.

Properties

Link copied to clipboard