AnthropicBaseFormatter
public abstract class AnthropicBaseFormatter extends AbstractBaseFormatter<MessageParam, Object, MessageCreateParams.Builder>
io/agentscope/extensions/model/anthropic/formatter/AnthropicBaseFormatter.java:41–254Anthropic 基类格式化器,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.extensions.model.anthropic.formatter 包,继承自 AbstractBaseFormatter<MessageParam, Object, MessageCreateParams.Builder>。核心成员包括 applyOptions、applyTools、applySystemMessage、cacheTtl、applyCacheControl、AnthropicBaseFormatter。
Abstract base formatter for Anthropic API with shared logic for handling Anthropic-specific requirements.
This class handles:
-
System message extraction and application (Anthropic requires system via system parameter)
-
Tool choice configuration with GenerateOptions
字段摘要Field Summary
| 字段Field | 类型Type | 说明Description |
|---|---|---|
messageConverterfinal | AnthropicMessageConverter | 消息转换器字段。 The message converter field. |
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
protected AnthropicBaseFormatter() | 初始化 `AnthropicBaseFormatter` 实例。 Creates a new instance. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public void applyOptions(MessageCreateParams.Builder paramsBuilder, GenerateOptions options, GenerateOptions defaultOptions) | 应用选项。 Apply generation options to Anthropic request parameters. |
public void applyTools(MessageCreateParams.Builder paramsBuilder, List<ToolSchema> tools) | 应用工具。 Apply tool schemas to Anthropic request parameters. |
public void applySystemMessage(MessageCreateParams.Builder paramsBuilder, List<Msg> messages) | 应用系统消息。 Extract and apply system message if present. |
public void applySystemMessage(MessageCreateParams.Builder paramsBuilder, List<Msg> messages, boolean cacheControlEnabled) | 应用系统消息。 Extract and apply system message if present, optionally marking it for prompt caching. |
public void cacheTtl(String cacheTtl) | 设置缓存存活时间。 Configure the TTL applied to prompt-caching markers (e.g. |
public List<MessageParam> applyCacheControl(List<MessageParam> formattedMessages) | 应用 `applyCacheControl`。 Apply the automatic cache control strategy to formatted messages. |
字段详情Field Detail
messageConverter
protected final AnthropicMessageConverter messageConverter
消息转换器字段。声明为 protected final AnthropicMessageConverter messageConverter。
The message converter field.
io/agentscope/extensions/model/anthropic/formatter/AnthropicBaseFormatter.java:44构造器详情Constructor Detail
AnthropicBaseFormatter
protected AnthropicBaseFormatter()
初始化 AnthropicBaseFormatter 实例。
Creates a new instance.
io/agentscope/extensions/model/anthropic/formatter/AnthropicBaseFormatter.java:49–51方法详情Method Detail
applyOptions
public void applyOptions(MessageCreateParams.Builder paramsBuilder, GenerateOptions options, GenerateOptions defaultOptions)
应用选项。
Apply generation options to Anthropic request parameters.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
paramsBuilder | MessageCreateParams.Builder | 参数构建器(类型 `MessageCreateParams.Builder`)。Anthropic request parameters builder |
options | GenerateOptions | 选项(类型 `GenerateOptions`)。Generation options to apply |
defaultOptions | GenerateOptions | 默认选项(类型 `GenerateOptions`)。Default options to use if options parameter is null |
io/agentscope/extensions/model/anthropic/formatter/AnthropicBaseFormatter.java:60–70applyTools
public void applyTools(MessageCreateParams.Builder paramsBuilder, List<ToolSchema> tools)
应用工具。
Apply tool schemas to Anthropic request parameters.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
paramsBuilder | MessageCreateParams.Builder | 参数构建器(类型 `MessageCreateParams.Builder`)。Anthropic request parameters builder |
tools | List<ToolSchema> | 工具列表(类型 `List`)。List of tool schemas to apply (may be null or empty) |
io/agentscope/extensions/model/anthropic/formatter/AnthropicBaseFormatter.java:79–92applySystemMessage
public void applySystemMessage(MessageCreateParams.Builder paramsBuilder, List<Msg> messages)
应用系统消息。
Extract and apply system message if present.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
paramsBuilder | MessageCreateParams.Builder | 参数构建器(类型 `MessageCreateParams.Builder`)。Anthropic request parameters builder |
messages | List<Msg> | 消息列表(类型 `List`)。All messages including potential system message |
io/agentscope/extensions/model/anthropic/formatter/AnthropicBaseFormatter.java:104–106applySystemMessage
public void applySystemMessage(MessageCreateParams.Builder paramsBuilder, List<Msg> messages, boolean cacheControlEnabled)
应用系统消息。
Extract and apply system message if present, optionally marking it for prompt caching.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
paramsBuilder | MessageCreateParams.Builder | 参数构建器(类型 `MessageCreateParams.Builder`)。Anthropic request parameters builder |
messages | List<Msg> | 消息列表(类型 `List`)。All messages including potential system message |
cacheControlEnabled | boolean | 缓存 Control 已启用(类型 `boolean`)。whether prompt caching is enabled |
io/agentscope/extensions/model/anthropic/formatter/AnthropicBaseFormatter.java:119–138cacheTtl
public void cacheTtl(String cacheTtl)
设置缓存存活时间。
Configure the TTL applied to prompt-caching markers (e.g.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
cacheTtl | String | 缓存存活时间(类型 `String`)。The cache ttl. |
io/agentscope/extensions/model/anthropic/formatter/AnthropicBaseFormatter.java:148–150applyCacheControl
public List<MessageParam> applyCacheControl(List<MessageParam> formattedMessages)
应用 applyCacheControl。
Apply the automatic cache control strategy to formatted messages.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
formattedMessages | List<MessageParam> | 已格式化消息(类型 `List`)。the formatted Anthropic messages |
List<MessageParam>io/agentscope/extensions/model/anthropic/formatter/AnthropicBaseFormatter.java:173–189