AS AgentScopeAPI 手册 / API Reference

ChatMessageConverter

public class ChatMessageConverter
源码Source io/agentscope/core/chat/completions/converter/ChatMessageConverter.java:51–212

聊天消息转换器,为框架提供通用类型与基础能力。位于 io.agentscope.core.chat.completions.converter 包。核心成员包括 convertMessages。

Service for converting ChatMessage DTOs to framework internal Msg objects.

This converter handles the transformation from HTTP request DTOs (with String roles) to framework internal message objects (with MsgRole enum). Supported roles: user, assistant, system, tool.

Extended support for:

  • Tool calls in assistant messages (tool_calls field)

  • Tool results in tool messages (tool_call_id field)

方法摘要Method Summary

方法Method说明Description
public List<Msg> convertMessages(List<ChatMessage> chatMessages)
转换消息。
Converts a list of `ChatMessage` DTOs to framework internal `Msg` objects, supporting full conversation history including tool calls.

方法详情Method Detail

convertMessages

public List<Msg> convertMessages(List<ChatMessage> chatMessages)

转换消息。

Converts a list of ChatMessage DTOs to framework internal Msg objects, supporting full conversation history including tool calls.

参数Parameters
名称Name类型Type说明Description
chatMessagesList<ChatMessage>聊天消息来自 HTTP 请求到转换。The chat messages from the HTTP request to convert
返回Returns List<Msg>
返回列出。A list of converted `Msg` objects; returns an empty list if input is null or empty
抛出Throws
  • IllegalArgumentException 可能抛出 `IllegalArgumentException`。if an unsupported role is encountered in any message
源码Source io/agentscope/core/chat/completions/converter/ChatMessageConverter.java:68–77
基于官方固定版本源码静态生成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.