AS AgentScopeAPI 手册 / API Reference

AnthropicChatModel

public class AnthropicChatModel extends ChatModelBase
源码Source io/agentscope/extensions/model/anthropic/AnthropicChatModel.java:63–460

Anthropic 聊天模型,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.extensions.model.anthropic 包,继承自 ChatModelBase。核心成员包括 doStream、getModelName、builder、AnthropicChatModel。

Anthropic Chat Model implementation using the official Anthropic Java SDK.

This implementation provides complete integration with Anthropic's Messages API, including tool calling, streaming support, and extended thinking features.

Important notes:

  • System messages are handled via the system parameter, not as messages

  • Tool results must be in separate user messages

  • Supports Claude models (claude-3-, claude-sonnet-, etc.)

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
Builder类class
AnthropicChatModel的构建器。
Builder for AnthropicChatModel.

构造器摘要Constructor Summary

构造器Constructor说明Description
public AnthropicChatModel(String baseUrl, String apiKey, String modelName, boolean streamEnabled, GenerateOptions defaultOptions, AnthropicBaseFormatter formatter, ProxyConfig proxyConfig, String cacheTtl)
初始化 `AnthropicChatModel` 实例。
Creates a new instance.
public AnthropicChatModel(String baseUrl, String apiKey, String authToken, String modelName, boolean streamEnabled, GenerateOptions defaultOptions, AnthropicBaseFormatter formatter, ProxyConfig proxyConfig, String cacheTtl)
初始化 `AnthropicChatModel` 实例。
Creates an Anthropic chat model with optional bearer token authentication.

方法摘要Method Summary

方法Method说明Description
protected Flux<ChatResponse> doStream(List<Msg> messages, List<ToolSchema> tools, GenerateOptions options)
以流式方式执行并返回结果。
Stream chat completion responses from Anthropic's API.
public String getModelName()
获取模型名称。
Gets the model name for logging and identification.
public static Builder builder()
static
返回构建器实例。
Creates a builder for constructing AnthropicChatModel instances.

构造器详情Constructor Detail

AnthropicChatModel

public AnthropicChatModel(String baseUrl, String apiKey, String modelName, boolean streamEnabled, GenerateOptions defaultOptions, AnthropicBaseFormatter formatter, ProxyConfig proxyConfig, String cacheTtl)

初始化 AnthropicChatModel 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
baseUrlString基类 URL(类型 `String`)。The base url.
apiKeyStringAPI 键(类型 `String`)。The api key.
modelNameString模型名称(类型 `String`)。The model name.
streamEnabledboolean流已启用(类型 `boolean`)。The stream enabled.
defaultOptionsGenerateOptions默认选项(类型 `GenerateOptions`)。The default options.
formatterAnthropicBaseFormatter格式化器(类型 `AnthropicBaseFormatter`)。The formatter.
proxyConfigProxyConfig代理配置(类型 `ProxyConfig`)。The proxy config.
cacheTtlString缓存存活时间(类型 `String`)。The cache ttl.
源码Source io/agentscope/extensions/model/anthropic/AnthropicChatModel.java:75–94

AnthropicChatModel

public AnthropicChatModel(String baseUrl, String apiKey, String authToken, String modelName, boolean streamEnabled, GenerateOptions defaultOptions, AnthropicBaseFormatter formatter, ProxyConfig proxyConfig, String cacheTtl)

初始化 AnthropicChatModel 实例。

Creates an Anthropic chat model with optional bearer token authentication.

参数Parameters
名称Name类型Type说明Description
baseUrlString基类 URL(类型 `String`)。the base URL for the Anthropic API (null for default)
apiKeyStringAPI 键(类型 `String`)。the API key for authentication (null to omit)
authTokenString认证令牌(类型 `String`)。the bearer token without the `Bearer ` prefix (null to omit)
modelNameString模型名称到使用。the model name to use
streamEnabledboolean流已启用(类型 `boolean`)。whether streaming should be enabled
defaultOptionsGenerateOptions默认选项(类型 `GenerateOptions`)。default generation options
formatterAnthropicBaseFormatter格式化器(类型 `AnthropicBaseFormatter`)。the message formatter to use (null for the default formatter)
proxyConfigProxyConfig代理配置(类型 `ProxyConfig`)。the proxy configuration (null for no proxy)
cacheTtlString缓存存活时间(类型 `String`)。the TTL for prompt-caching markers (null for default 5m)
抛出Throws
  • IllegalArgumentException 可能抛出 `IllegalArgumentException`。if both API key and bearer token are configured
源码Source io/agentscope/extensions/model/anthropic/AnthropicChatModel.java:112–157

方法详情Method Detail

doStream

protected Flux<ChatResponse> doStream(List<Msg> messages, List<ToolSchema> tools, GenerateOptions options)

以流式方式执行并返回结果。

Stream chat completion responses from Anthropic's API.

参数Parameters
名称Name类型Type说明Description
messagesList<Msg>消息列表(类型 `List`)。AgentScope messages to send to the model
toolsList<ToolSchema>工具列表(类型 `List`)。Optional list of tool schemas (null or empty if no tools)
optionsGenerateOptions选项(类型 `GenerateOptions`)。Optional generation options (null to use defaults)
返回Returns Flux<ChatResponse>
返回Flux。Flux stream of chat responses
源码Source io/agentscope/extensions/model/anthropic/AnthropicChatModel.java:176–291

getModelName

public String getModelName()

获取模型名称。

Gets the model name for logging and identification.

返回Returns String
模型名称。the model name
源码Source io/agentscope/extensions/model/anthropic/AnthropicChatModel.java:298–301

builder

public static Builder builder()
static

返回构建器实例。

Creates a builder for constructing AnthropicChatModel instances.

返回Returns Builder
一种新的构建器。a new builder
源码Source io/agentscope/extensions/model/anthropic/AnthropicChatModel.java:308–310

嵌套类详情Nested Class Detail

Builder

public static class Builder

AnthropicChatModel的构建器。位于 io.agentscope.extensions.model.anthropic 包。核心成员包括 baseUrl、apiKey、authToken、modelName、stream、defaultOptions。

Builder for AnthropicChatModel.

继承成员Inherited Members

基于官方固定版本源码静态生成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.