Class GLMMultiAgentFormatter
java.lang.Object
io.agentscope.core.formatter.AbstractBaseFormatter<OpenAIMessage,OpenAIResponse,OpenAIRequest>
io.agentscope.extensions.model.openai.formatter.OpenAIBaseFormatter
io.agentscope.extensions.model.openai.formatter.OpenAIChatFormatter
io.agentscope.extensions.model.openai.formatter.OpenAIMultiAgentFormatter
io.agentscope.extensions.model.openai.compat.glm.GLMMultiAgentFormatter
- All Implemented Interfaces:
io.agentscope.core.formatter.Formatter<OpenAIMessage,OpenAIResponse, OpenAIRequest>
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
nameparameter in messages tool_choiceonly supports"auto"; forced choices are degraded, whilenoneremoves tools to preserve the no-tool-call contract- Does NOT support the
strictparameter in tool definitions - Unsupported sampling parameters are stripped,
max_completion_tokensis mapped tomax_tokens, andtemperature/top_pare clamped to the GLM ranges (seeGLMFormatterfor details)
Usage:
OpenAIChatModel.builder()
.formatter(new GLMMultiAgentFormatter())
.modelName("glm-5.2")
.baseUrl("https://open.bigmodel.cn/api/paas/v4")
.apiKey(apiKey)
.build();
- See Also:
-
Field Summary
Fields inherited from class io.agentscope.extensions.model.openai.formatter.OpenAIBaseFormatter
messageConverter, responseParser -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyOptions(OpenAIRequest request, io.agentscope.core.model.GenerateOptions options, io.agentscope.core.model.GenerateOptions defaultOptions) Apply generation options to the request.voidapplyToolChoice(OpenAIRequest request, io.agentscope.core.model.ToolChoice toolChoice) Apply tool choice configuration to the request.protected OpenAIMessageconvertMessage(io.agentscope.core.message.Msg msg, boolean hasMedia) Convert one AgentScope message to OpenAI message format.protected List<OpenAIMessage>protected booleanReturns whether this formatter's target API supports the strict parameter in tool definitions.Methods inherited from class io.agentscope.extensions.model.openai.formatter.OpenAIMultiAgentFormatter
doFormatMethods inherited from class io.agentscope.extensions.model.openai.formatter.OpenAIChatFormatter
applyAdditionalBodyParams, applyMaxTokens, applyToolsMethods inherited from class io.agentscope.extensions.model.openai.formatter.OpenAIBaseFormatter
applyToolChoice, applyTools, buildRequest, buildRequest, parseResponseMethods inherited from class io.agentscope.core.formatter.AbstractBaseFormatter
convertToolResultToString, extractTextContent, extractTextContent, format, format, formatRoleLabel, getOptionOrDefault, hasMediaContent, saveBase64DataToTempFile, shouldBypassHistory
-
Constructor Details
-
GLMMultiAgentFormatter
public GLMMultiAgentFormatter() -
GLMMultiAgentFormatter
-
-
Method Details
-
doFormat
- Overrides:
doFormatin classOpenAIMultiAgentFormatter
-
convertMessage
Description copied from class:OpenAIChatFormatterConvert one AgentScope message to OpenAI message format.Provider-specific subclasses may override this when the target API supports a slightly different message shape.
- Overrides:
convertMessagein classOpenAIChatFormatter- Parameters:
msg- the message to converthasMedia- whether the message contains media content- Returns:
- converted OpenAI message
-
supportsStrict
protected boolean supportsStrict()Description copied from class:OpenAIChatFormatterReturns 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:
supportsStrictin classOpenAIChatFormatter- 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:OpenAIBaseFormatterApply generation options to the request. Subclasses implement provider-specific option handling.- Specified by:
applyOptionsin interfaceio.agentscope.core.formatter.Formatter<OpenAIMessage,OpenAIResponse, OpenAIRequest> - Overrides:
applyOptionsin classOpenAIChatFormatter- Parameters:
request- OpenAI request DTOoptions- Generation options to applydefaultOptions- Default options to use if options parameter is null
-
applyToolChoice
Description copied from class:OpenAIBaseFormatterApply tool choice configuration to the request. Subclasses implement provider-specific tool choice handling.- Specified by:
applyToolChoicein interfaceio.agentscope.core.formatter.Formatter<OpenAIMessage,OpenAIResponse, OpenAIRequest> - Overrides:
applyToolChoicein classOpenAIChatFormatter- Parameters:
request- OpenAI request DTOtoolChoice- Tool choice configuration (null means auto)
-