AbstractBaseFormatter
public abstract class AbstractBaseFormatter<TReq, TResp, TParams> implements Formatter<TReq, TResp, TParams>
io/agentscope/core/formatter/AbstractBaseFormatter.java:62–339抽象基类格式化器,在智能体、模型与前端之间传递结构化消息和事件。位于 io.agentscope.core.formatter 包,实现 Formatter<TReq, TResp, TParams>。核心成员包括 format、doFormat、extractTextContent、hasMediaContent、formatRoleLabel、shouldBypassHistory。
Abstract base formatter providing common functionality for all formatter implementations.
This class contains shared logic across all formatters including:
-
Text content extraction (with ThinkingBlock filtering)
-
Media content detection
-
Role label formatting
-
Shared ObjectMapper instance
方法摘要Method Summary
方法详情Method Detail
format
public List<TReq> format(List<Msg> msgs)
设置格式。
Format AgentScope messages to provider-specific request format.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | AgentScope 消息的列出。List of AgentScope messages |
List<TReq>io/agentscope/core/formatter/AbstractBaseFormatter.java:73–76format
public List<TReq> format(List<Msg> msgs, GenerateOptions options)
执行格式相关操作。
Format AgentScope messages using request-scoped generation options.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | AgentScope 消息的列出。list of AgentScope messages |
options | GenerateOptions | 选项(类型 `GenerateOptions`)。request-scoped generation options; may be `null` |
List<TReq>io/agentscope/core/formatter/AbstractBaseFormatter.java:85–88doFormat
protected abstract List<TReq> doFormat(List<Msg> msgs)
执行格式操作。
Performs the do format operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 消息列表(类型 `List`)。The msgs. |
List<TReq>io/agentscope/core/formatter/AbstractBaseFormatter.java:90doFormat
protected List<TReq> doFormat(List<Msg> msgs, GenerateOptions options)
执行格式操作。
Format AgentScope messages using request-scoped generation options.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | AgentScope 消息的列出。list of AgentScope messages |
options | GenerateOptions | 选项(类型 `GenerateOptions`)。request-scoped generation options; may be `null` |
List<TReq>io/agentscope/core/formatter/AbstractBaseFormatter.java:102–104extractTextContent
protected String extractTextContent(Msg msg)
设置该参数。
Extract text content from a message, filtering out ThinkingBlock.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msg | Msg | 消息(类型 `Msg`)。The message to extract text from |
Stringio/agentscope/core/formatter/AbstractBaseFormatter.java:112–137extractTextContent
protected String extractTextContent(ContentBlock block)
设置该参数。
Extract text content from a single ContentBlock.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
block | ContentBlock | 内容块。The content block |
Stringio/agentscope/core/formatter/AbstractBaseFormatter.java:145–152hasMediaContent
protected boolean hasMediaContent(Msg msg)
判断是否具有 hasMediaContent。
Check if a message contains multimodal content (images, audio, video).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msg | Msg | 消息到检查。The message to check |
booleanio/agentscope/core/formatter/AbstractBaseFormatter.java:160–170formatRoleLabel
protected String formatRoleLabel(MsgRole role)
用于会话历史的格式角色标签。
Format role label for conversation history.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
role | MsgRole | 消息角色。The message role |
Stringio/agentscope/core/formatter/AbstractBaseFormatter.java:178–185shouldBypassHistory
protected boolean shouldBypassHistory(Msg msg)
设置该参数。
Check if a message should bypass history merging in multiagent formatters.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msg | Msg | 消息到检查。The message to check |
booleanio/agentscope/core/formatter/AbstractBaseFormatter.java:195–202getOptionOrDefault
protected T T getOptionOrDefault(GenerateOptions options, GenerateOptions defaultOptions, Function<GenerateOptions, T> getter)
获取选项或默认。
Get an option value from options or fall back to defaultOptions.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
options | GenerateOptions | 选项(类型 `GenerateOptions`)。The primary options object |
defaultOptions | GenerateOptions | 回退选项对象。The fallback options object |
getter | Function<GenerateOptions, T> | getter(类型 `Function`)。Function to extract the value from GenerateOptions |
Tio/agentscope/core/formatter/AbstractBaseFormatter.java:213–221convertToolResultToString
protected String convertToolResultToString(List<ContentBlock> output)
转换 convertToolResultToString。
Convert tool result output to string representation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
output | List<ContentBlock> | 输出(类型 `List`)。The tool result output blocks (can be null or empty) |
Stringio/agentscope/core/formatter/AbstractBaseFormatter.java:230–262saveBase64DataToTempFile
protected String saveBase64DataToTempFile(String mediaType, String base64Data) throws IOException
保存 saveBase64DataToTempFile。
Save base64 data to a temporary file.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
mediaType | String | media 类型(类型 `String`)。The MIME type (e.g., "image/png", "audio/wav") |
base64Data | String | 基类 64 数据(类型 `String`)。The base64-encoded data (without prefix) |
StringIOException可能抛出 `IOException`。Thrown when the operation cannot be completed.
io/agentscope/core/formatter/AbstractBaseFormatter.java:320–338