Class GLMMultiAgentFormatter

All Implemented Interfaces:
io.agentscope.core.formatter.Formatter<OpenAIMessage,OpenAIResponse,OpenAIRequest>

public class GLMMultiAgentFormatter extends OpenAIMultiAgentFormatter
Multi-agent formatter for Zhipu AI (Z.ai) GLM models.

This formatter extends OpenAIMultiAgentFormatter with the same GLM-specific handling as GLMFormatter:

  • At least one user message is required (error 1214 otherwise)
  • Does NOT support the name parameter in messages
  • tool_choice only supports "auto"; forced choices are degraded, while none removes tools to preserve the no-tool-call contract
  • Does NOT support the strict parameter in tool definitions
  • Unsupported sampling parameters are stripped, max_completion_tokens is mapped to max_tokens, and temperature / top_p are clamped to the GLM ranges (see GLMFormatter for details)

Usage:


 OpenAIChatModel.builder()
     .formatter(new GLMMultiAgentFormatter())
     .modelName("glm-5.2")
     .baseUrl("https://open.bigmodel.cn/api/paas/v4")
     .apiKey(apiKey)
     .build();
 
See Also:
  • Constructor Details

    • GLMMultiAgentFormatter

      public GLMMultiAgentFormatter()
    • GLMMultiAgentFormatter

      public GLMMultiAgentFormatter(String conversationHistoryPrompt)
  • Method Details

    • doFormat

      protected List<OpenAIMessage> doFormat(List<io.agentscope.core.message.Msg> msgs)
      Overrides:
      doFormat in class OpenAIMultiAgentFormatter
    • convertMessage

      protected OpenAIMessage convertMessage(io.agentscope.core.message.Msg msg, boolean hasMedia)
      Description copied from class: OpenAIChatFormatter
      Convert one AgentScope message to OpenAI message format.

      Provider-specific subclasses may override this when the target API supports a slightly different message shape.

      Overrides:
      convertMessage in class OpenAIChatFormatter
      Parameters:
      msg - the message to convert
      hasMedia - whether the message contains media content
      Returns:
      converted OpenAI message
    • supportsStrict

      protected boolean supportsStrict()
      Description copied from class: OpenAIChatFormatter
      Returns whether this formatter's target API supports the strict parameter in tool definitions.

      Subclasses can override this method to disable strict parameter for providers that don't support it (e.g., DeepSeek).

      Overrides:
      supportsStrict in class OpenAIChatFormatter
      Returns:
      true if strict parameter is supported, false otherwise
    • applyOptions

      public void applyOptions(OpenAIRequest request, io.agentscope.core.model.GenerateOptions options, io.agentscope.core.model.GenerateOptions defaultOptions)
      Description copied from class: OpenAIBaseFormatter
      Apply generation options to the request. Subclasses implement provider-specific option handling.
      Specified by:
      applyOptions in interface io.agentscope.core.formatter.Formatter<OpenAIMessage,OpenAIResponse,OpenAIRequest>
      Overrides:
      applyOptions in class OpenAIChatFormatter
      Parameters:
      request - OpenAI request DTO
      options - Generation options to apply
      defaultOptions - Default options to use if options parameter is null
    • applyToolChoice

      public void applyToolChoice(OpenAIRequest request, io.agentscope.core.model.ToolChoice toolChoice)
      Description copied from class: OpenAIBaseFormatter
      Apply tool choice configuration to the request. Subclasses implement provider-specific tool choice handling.
      Specified by:
      applyToolChoice in interface io.agentscope.core.formatter.Formatter<OpenAIMessage,OpenAIResponse,OpenAIRequest>
      Overrides:
      applyToolChoice in class OpenAIChatFormatter
      Parameters:
      request - OpenAI request DTO
      toolChoice - Tool choice configuration (null means auto)