AS AgentScopeAPI 手册 / API Reference

AnthropicBaseFormatter

public abstract class AnthropicBaseFormatter extends AbstractBaseFormatter<MessageParam, Object, MessageCreateParams.Builder>
源码Source io/agentscope/extensions/model/anthropic/formatter/AnthropicBaseFormatter.java:41–254

Anthropic 基类格式化器,与模型服务通信并返回生成或向量化结果。位于 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
messageConverter
final
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
final

消息转换器字段。声明为 protected final AnthropicMessageConverter messageConverter。

The message converter field.

源码Source io/agentscope/extensions/model/anthropic/formatter/AnthropicBaseFormatter.java:44

构造器详情Constructor Detail

AnthropicBaseFormatter

protected AnthropicBaseFormatter()

初始化 AnthropicBaseFormatter 实例。

Creates a new instance.

源码Source 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.

参数Parameters
名称Name类型Type说明Description
paramsBuilderMessageCreateParams.Builder参数构建器(类型 `MessageCreateParams.Builder`)。Anthropic request parameters builder
optionsGenerateOptions选项(类型 `GenerateOptions`)。Generation options to apply
defaultOptionsGenerateOptions默认选项(类型 `GenerateOptions`)。Default options to use if options parameter is null
源码Source io/agentscope/extensions/model/anthropic/formatter/AnthropicBaseFormatter.java:60–70

applyTools

public void applyTools(MessageCreateParams.Builder paramsBuilder, List<ToolSchema> tools)

应用工具。

Apply tool schemas to Anthropic request parameters.

参数Parameters
名称Name类型Type说明Description
paramsBuilderMessageCreateParams.Builder参数构建器(类型 `MessageCreateParams.Builder`)。Anthropic request parameters builder
toolsList<ToolSchema>工具列表(类型 `List`)。List of tool schemas to apply (may be null or empty)
源码Source io/agentscope/extensions/model/anthropic/formatter/AnthropicBaseFormatter.java:79–92

applySystemMessage

public void applySystemMessage(MessageCreateParams.Builder paramsBuilder, List<Msg> messages)

应用系统消息。

Extract and apply system message if present.

参数Parameters
名称Name类型Type说明Description
paramsBuilderMessageCreateParams.Builder参数构建器(类型 `MessageCreateParams.Builder`)。Anthropic request parameters builder
messagesList<Msg>消息列表(类型 `List`)。All messages including potential system message
源码Source io/agentscope/extensions/model/anthropic/formatter/AnthropicBaseFormatter.java:104–106

applySystemMessage

public void applySystemMessage(MessageCreateParams.Builder paramsBuilder, List<Msg> messages, boolean cacheControlEnabled)

应用系统消息。

Extract and apply system message if present, optionally marking it for prompt caching.

参数Parameters
名称Name类型Type说明Description
paramsBuilderMessageCreateParams.Builder参数构建器(类型 `MessageCreateParams.Builder`)。Anthropic request parameters builder
messagesList<Msg>消息列表(类型 `List`)。All messages including potential system message
cacheControlEnabledboolean缓存 Control 已启用(类型 `boolean`)。whether prompt caching is enabled
源码Source io/agentscope/extensions/model/anthropic/formatter/AnthropicBaseFormatter.java:119–138

cacheTtl

public void cacheTtl(String cacheTtl)

设置缓存存活时间。

Configure the TTL applied to prompt-caching markers (e.g.

参数Parameters
名称Name类型Type说明Description
cacheTtlString缓存存活时间(类型 `String`)。The cache ttl.
源码Source io/agentscope/extensions/model/anthropic/formatter/AnthropicBaseFormatter.java:148–150

applyCacheControl

public List<MessageParam> applyCacheControl(List<MessageParam> formattedMessages)

应用 applyCacheControl。

Apply the automatic cache control strategy to formatted messages.

参数Parameters
名称Name类型Type说明Description
formattedMessagesList<MessageParam>已格式化消息(类型 `List`)。the formatted Anthropic messages
返回Returns List<MessageParam>
返回列出。the messages with cache control applied
源码Source io/agentscope/extensions/model/anthropic/formatter/AnthropicBaseFormatter.java:173–189
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.