AS AgentScopeAPI 手册 / API Reference

AnthropicMessageConverter

public class AnthropicMessageConverter
源码Source io/agentscope/extensions/model/anthropic/formatter/AnthropicMessageConverter.java:53–427

Anthropic 消息转换器,与模型服务通信并返回生成或向量化结果。位于 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.

参数Parameters
名称Name类型Type说明Description
toolResultConverterFunction<List<ContentBlock>, String>工具结果转换器(类型 `Function , String>`)。Function to convert tool result blocks to strings
源码Source 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.

参数Parameters
名称Name类型Type说明Description
messagesList<Msg>消息到转换。The messages to convert
返回Returns List<MessageParam>
返回列出。List of MessageParam for Anthropic API
源码Source io/agentscope/extensions/model/anthropic/formatter/AnthropicMessageConverter.java:77–129

extractSystemMessage

public String extractSystemMessage(List<Msg> messages)

设置该参数。

Extract system message content if present in the first message.

参数Parameters
名称Name类型Type说明Description
messagesList<Msg>消息列表(类型 `List`)。The messages.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/extensions/model/anthropic/formatter/AnthropicMessageConverter.java:406–426
基于官方固定版本源码静态生成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.