feat(models): add GLM (Zhipu AI) adaptation with dedicated provider and formatters#2316
Open
Leeaoyin wants to merge 3 commits into
Hidden character warning
The head ref may contain hidden characters: "feat(models)\uff1aGLM_Model_Adaptation"
Open
feat(models): add GLM (Zhipu AI) adaptation with dedicated provider and formatters#2316Leeaoyin wants to merge 3 commits into
Leeaoyin wants to merge 3 commits into
Conversation
…compat.glm package - Updated imports in GLMProvider and OpenAIChatModel to use the new GLMFormatter and GLMMultiAgentFormatter from the compat.glm package. - Deprecated old GLMFormatter and GLMMultiAgentFormatter, retaining them for backward compatibility. - Enhanced GLMFormatter with detailed API compatibility handling for Zhipu AI models. - Updated documentation to reflect changes in environment variable usage and model configuration for GLM. - Added tests to ensure backward compatibility for deprecated formatters.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds first-class support for Zhipu AI GLM via an OpenAI-compatible adapter layer, including glm:<model> ModelRegistry IDs, a dedicated GLMModelProvider, updated GLM-specific formatters, plus documentation and unit tests (fixes #2212).
Changes:
- Introduces
io.agentscope.extensions.model.openai.compat.glmwithGLMFormatter,GLMMultiAgentFormatter, andGLMModelProvider(SPI-registered) to supportglm:<model>ids with GLM defaults. - Deprecates the legacy
openai.formatter.GLMFormatter/GLMMultiAgentFormatterby making them extend the new compat implementations; updates references (Javadoc + e2e provider). - Adds/updates docs (EN/ZH) and adds focused unit tests for provider behavior and GLM request sanitization/adaptation.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/v2/zh/integration/model/openai.md | Adds ZH usage docs for glm:<model> and GLM-specific request adaptations. |
| docs/v2/zh/docs/building-blocks/model.md | Mentions GLM_API_KEY discovery and glm:<model> behavior in ZH docs. |
| docs/v2/en/integration/model/openai.md | Adds EN usage docs for glm:<model> and GLM-specific request adaptations. |
| docs/v2/en/docs/building-blocks/model.md | Mentions GLM_API_KEY discovery and glm:<model> behavior in EN docs. |
| agentscope-extensions/.../formatter/GLMFormatterTest.java | Refocuses legacy-package tests to validate deprecated-class backward compatibility. |
| agentscope-extensions/.../compat/glm/GLMMultiAgentFormatterTest.java | Adds unit tests for compat GLM multi-agent formatter behavior/sanitization. |
| agentscope-extensions/.../compat/glm/GLMModelProviderTest.java | Adds unit tests for provider id/supports/create defaults and ServiceLoader discovery. |
| agentscope-extensions/.../compat/glm/GLMFormatterTest.java | Adds unit tests for GLM formatter request adaptations (tool_choice, strict, clamping, mapping). |
| agentscope-extensions/.../resources/META-INF/services/io.agentscope.core.model.spi.ModelProvider | Registers GLMModelProvider for ModelRegistry resolution via SPI. |
| agentscope-extensions/.../openai/OpenAIChatModel.java | Updates Javadoc links to point to the new compat GLM formatter package. |
| agentscope-extensions/.../openai/formatter/GLMMultiAgentFormatter.java | Deprecates legacy formatter and makes it extend the compat implementation. |
| agentscope-extensions/.../openai/formatter/GLMFormatter.java | Deprecates legacy formatter and makes it extend the compat implementation + delegates helper statics. |
| agentscope-extensions/.../openai/compat/glm/GLMMultiAgentFormatter.java | Implements GLM-specific multi-agent formatting and option sanitization. |
| agentscope-extensions/.../openai/compat/glm/GLMModelProvider.java | Adds a GLM provider that creates OpenAIChatModel with GLM defaults and context options. |
| agentscope-extensions/.../openai/compat/glm/GLMFormatter.java | Implements GLM request adaptations (tool_choice degradation, param stripping, mapping, clamping). |
| agentscope-extensions/.../e2e/providers/GLMProvider.java | Updates e2e provider to import compat GLM formatters. |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
…ure clamping - Reject whitespace-only model names in GLMModelProvider.supports and trim the extracted model name so ids like "glm: glm-4.6" resolve correctly - Mention ModelCreationContext#apiKey alongside the environment variables in the missing-API-key error message - Clamp negative temperature to 0.0 before the do_sample=false translation, matching the documented [0.0, 1.0] range Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AgentScope-Java Version
2.0.1-SNAPSHOT
Description
Fixes #2212
Background
GLM (Zhipu AI) exposes an OpenAI-compatible Chat Completions endpoint, but previously users had to manually configure
baseUrl, pick the right formatter from theformatterpackage, and there was noModelRegistrysupport (noglm:<model>string id). The existingGLMFormatteralso lagged behind the current Zhipu API (glm-5.2 / glm-4.7 era): several OpenAI-style parameters are rejected or silently ignored by the GLM endpoint.Changes
New package
io.agentscope.extensions.model.openai.compat.glm:GLMFormatter— adapted to the latest official API reference (https://docs.bigmodel.cn/cn/api/introduction):tool_choiceonly supportsauto; other values are degraded with a logstrictparameter in tool definitionsfrequency_penalty/presence_penalty/thinking_budgetmax_completion_tokenstomax_tokens(GLM only supports the latter)temperatureto [0.0, 1.0] andtop_pto [0.01, 1.0]; translatestemperature = 0todo_sample = falseper the official OpenAI compatibility guide (https://docs.bigmodel.cn/cn/guide/develop/openai/introduction)thinking), GLM-5.2reasoning_effort, andtool_streampass through viaGenerateOptionsGLMMultiAgentFormatter— same GLM adaptations on top ofOpenAIMultiAgentFormatterGLMModelProvider— modeled afterOpenAIModelProvider; createsOpenAIChatModelinstances preconfigured for GLM:glm:<model>ids (e.g.glm:glm-5.2) viaModelRegistryhttps://open.bigmodel.cn/api/paas/v4, default formatterGLMFormatterGLM_API_KEY, thenZHIPUAI_API_KEYresponse_formatonly supportsjson_object); can be re-enabled via thenativeStructuredOutputoptionSPI registration: appended
GLMModelProvidertoMETA-INF/services/io.agentscope.core.model.spi.ModelProvider.Deprecation: the old
formatter.GLMFormatter/formatter.GLMMultiAgentFormatterare marked@Deprecatedand now extend the newcompat.glmimplementations, so existing code keeps working unchanged. References inOpenAIChatModelJavadoc and the e2eGLMProviderwere migrated to the new package.Docs: added a GLM section to
docs/v2/{zh,en}/integration/model/openai.md(registry id, explicit builder, adaptation list, thinking/reasoning_effort/tool_stream usage) and mentionedGLM_API_KEYindocs/v2/{zh,en}/docs/building-blocks/model.md.How to test
mvn test -pl agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-openai -am -Dtest="GLM*Test"compat/glm/GLMFormatterTest,GLMMultiAgentFormatterTest— formatter adaptations (user message, tool_choice, strict, parameter sanitizing/clamping)compat/glm/GLMModelProviderTest— provider id/supports/create, defaults, ServiceLoader discoveryformatter/GLMFormatterTest— backward compatibility of the deprecated classesGLM_API_KEY): build an agent with.model("glm:glm-5.2")and verify chat + tool calling against the Zhipu endpoint.