Class ChatMessage

java.lang.Object
io.agentscope.core.chat.completions.model.ChatMessage

public class ChatMessage extends Object
Chat message representation for the Chat Completions API.

This DTO is compatible with OpenAI's chat message format and supports:

  • Basic text messages (user, assistant, system)
  • Tool call requests (assistant messages with tool_calls)
  • Tool results (tool messages with tool_call_id)

Example formats:


 // User message
 {"role": "user", "content": "Hello"}

 // Assistant message with tool call
 {
   "role": "assistant",
   "content": "Let me check the weather",
   "tool_calls": [{
     "id": "call_abc",
     "type": "function",
     "function": {"name": "get_weather", "arguments": "{\"city\":\"Hangzhou\"}"}
   }]
 }

 // Tool result message
 {"role": "tool", "tool_call_id": "call_abc", "content": "{\"temp\": 25}"}
 
  • Constructor Details

    • ChatMessage

      public ChatMessage()
      Default constructor for deserialization.
    • ChatMessage

      public ChatMessage(String role, String content)
      Creates a simple text message.
      Parameters:
      role - Message role (user, assistant, system, tool)
      content - Message content
  • Method Details

    • assistantWithToolCalls

      public static ChatMessage assistantWithToolCalls(String content, List<ToolCall> toolCalls)
      Creates an assistant message with tool calls.
      Parameters:
      content - Optional text content
      toolCalls - List of tool calls
      Returns:
      New ChatMessage instance
    • toolResult

      public static ChatMessage toolResult(String toolCallId, String name, String content)
      Creates a tool result message.
      Parameters:
      toolCallId - ID of the tool call being responded to
      name - Name of the tool
      content - Tool execution result
      Returns:
      New ChatMessage instance
    • getRole

      public String getRole()
    • setRole

      public void setRole(String role)
    • getContent

      public String getContent()
    • setContent

      public void setContent(String content)
    • getToolCalls

      public List<ToolCall> getToolCalls()
    • setToolCalls

      public void setToolCalls(List<ToolCall> toolCalls)
    • getToolCallId

      public String getToolCallId()
    • setToolCallId

      public void setToolCallId(String toolCallId)
    • getName

      public String getName()
    • setName

      public void setName(String name)