ContentBlock
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") @JsonSubTypes({ @JsonSubTypes.Type(value = TextBlock.class, name = "text"), @JsonSubTypes.Type(value = ThinkingBlock.class, name = "thinking"), @JsonSubTypes.Type(value = ImageBlock.class, name = "image"), @JsonSubTypes.Type(value = AudioBlock.class, name = "audio"), @JsonSubTypes.Type(value = VideoBlock.class, name = "video"), @JsonSubTypes.Type(value = ToolUseBlock.class, name = "tool_use"), @JsonSubTypes.Type(value = ToolResultBlock.class, name = "tool_result"), @JsonSubTypes.Type(value = HintBlock.class, name = "hint"), @JsonSubTypes.Type(value = DataBlock.class, name = "data") }) public sealed class ContentBlock implements State permits TextBlock, ImageBlock, AudioBlock, VideoBlock, ThinkingBlock, ToolUseBlock, ToolResultBlock, HintBlock, DataBlock
io/agentscope/core/message/ContentBlock.java:46–67内容块,在智能体、模型与前端之间传递结构化消息和事件。位于 io.agentscope.core.message 包,实现 State。
Base sealed class for all content blocks in messages.
Content blocks represent different types of content that can be included in a message, such as text, images, audio, video, or thinking content. This sealed hierarchy ensures type safety and enables exhaustive pattern matching.
Supported Content Types:
-
TextBlock- Plain text content -
ThinkingBlock- Agent reasoning/thinking content -
ImageBlock- Image content (URL or Base64) -
AudioBlock- Audio content (URL or Base64) -
VideoBlock- Video content (URL or Base64) -
ToolUseBlock- Tool execution requests -
ToolResultBlock- Tool execution results -
HintBlock- Hints for LLM reasoning (e.g., from RAG) -
DataBlock- Generic binary data block unifying image/audio/video
Uses Jackson annotations for polymorphic JSON serialization with the "type" discriminator field. The sealed modifier restricts subclasses to the specified permits list, enabling compile-time exhaustiveness checking in pattern matching.