Anthropic 模型

agentscope-extensions-model-anthropic 接入 Anthropic Claude Model,并提供 Anthropic 专属 formatter 和请求 DTO 支持。

添加依赖

<dependency>
    <groupId>io.agentscope</groupId>
    <artifactId>agentscope-extensions-model-anthropic</artifactId>
    <version>${agentscope.version}</version>
</dependency>

ModelRegistry

设置 ANTHROPIC_API_KEY 后,使用 anthropic:<model> 字符串 id:

ReActAgent agent = ReActAgent.builder()
    .name("assistant")
    .model("anthropic:claude-sonnet-4.5") // 底层由 ModelRegistry.resolve(modelId) 解析
    .build();

显式 builder

需要自定义 endpoint、formatter、transport、prompt caching、thinking 或生成参数时,使用 builder:

import io.agentscope.extensions.model.anthropic.AnthropicChatModel;

AnthropicChatModel model = AnthropicChatModel.builder()
    .apiKey(System.getenv("ANTHROPIC_API_KEY"))
    .modelName("claude-sonnet-4.5")
    .stream(true)
    .build();

Spring Boot

Spring Boot 应用可以使用 Anthropic starter:

<dependency>
    <groupId>io.agentscope</groupId>
    <artifactId>agentscope-anthropic-spring-boot-starter</artifactId>
    <version>${agentscope.version}</version>
</dependency>

完整 builder 选项、formatter、credential 和 registry context 细节见 模型