AnthropicMessageConverter
public class AnthropicMessageConverter
io/agentscope/extensions/model/anthropic/formatter/AnthropicMessageConverter.java:53–427Anthropic 消息转换器,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.extensions.model.anthropic.formatter 包。核心成员包括 convert、extractSystemMessage、AnthropicMessageConverter。
Converts AgentScope Msg objects to Anthropic SDK MessageParam types.
This class handles all message role conversions including system, user, assistant, and tool messages. It supports multimodal content (text, images) and tool calling functionality.
Important: In Anthropic API, only the first message can be a system message. Non-first system messages are converted to user messages.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public AnthropicMessageConverter(Function<List<ContentBlock>, String> toolResultConverter) | 初始化 `AnthropicMessageConverter` 实例。 Create an AnthropicMessageConverter with required dependency functions. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public List<MessageParam> convert(List<Msg> messages) | 设置转换。 Convert list of Msg to list of Anthropic MessageParam. |
public String extractSystemMessage(List<Msg> messages) | 设置该参数。 Extract system message content if present in the first message. |
构造器详情Constructor Detail
AnthropicMessageConverter
public AnthropicMessageConverter(Function<List<ContentBlock>, String> toolResultConverter)
初始化 AnthropicMessageConverter 实例。
Create an AnthropicMessageConverter with required dependency functions.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
toolResultConverter | Function<List<ContentBlock>, String> | 工具结果转换器(类型 `Function , String>`)。Function to convert tool result blocks to strings |
io/agentscope/extensions/model/anthropic/formatter/AnthropicMessageConverter.java:65–68方法详情Method Detail
convert
public List<MessageParam> convert(List<Msg> messages)
设置转换。
Convert list of Msg to list of Anthropic MessageParam.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
messages | List<Msg> | 消息到转换。The messages to convert |
List<MessageParam>io/agentscope/extensions/model/anthropic/formatter/AnthropicMessageConverter.java:77–129extractSystemMessage
public String extractSystemMessage(List<Msg> messages)
设置该参数。
Extract system message content if present in the first message.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
messages | List<Msg> | 消息列表(类型 `List`)。The messages. |
Stringio/agentscope/extensions/model/anthropic/formatter/AnthropicMessageConverter.java:406–426