类 AnthropicChatModel

java.lang.Object
io.agentscope.core.model.ChatModelBase
io.agentscope.core.model.AnthropicChatModel
所有已实现的接口:
Model

public class AnthropicChatModel extends ChatModelBase
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.)
  • 构造器详细资料

    • AnthropicChatModel

      public AnthropicChatModel(String baseUrl, String apiKey, String modelName, boolean streamEnabled, GenerateOptions defaultOptions, AnthropicBaseFormatter formatter)
      Creates a new Anthropic chat model instance.
      参数:
      baseUrl - the base URL for Anthropic API (null for default)
      apiKey - the API key for authentication (null to load from ANTHROPIC_API_KEY env var)
      modelName - the model name to use (e.g., "claude-sonnet-4-5-20250929")
      streamEnabled - whether streaming should be enabled
      defaultOptions - default generation options
      formatter - the message formatter to use (null for default Anthropic formatter)
  • 方法详细资料

    • doStream

      protected reactor.core.publisher.Flux<ChatResponse> doStream(List<Msg> messages, List<ToolSchema> tools, GenerateOptions options)
      Stream chat completion responses from Anthropic's API.

      This method internally handles message formatting using the configured formatter. It supports both streaming and non-streaming modes based on the streamEnabled setting.

      Supports timeout and retry configuration through GenerateOptions.

      指定者:
      doStream 在类中 ChatModelBase
      参数:
      messages - AgentScope messages to send to the model
      tools - Optional list of tool schemas (null or empty if no tools)
      options - Optional generation options (null to use defaults)
      返回:
      Flux stream of chat responses
    • getModelName

      public String getModelName()
      Gets the model name for logging and identification.
      返回:
      the model name
    • builder

      public static AnthropicChatModel.Builder builder()
      Creates a builder for constructing AnthropicChatModel instances.
      返回:
      a new builder