← Back to PRs

#15327: feat:(models): discover ZAI models dynamically for GLM-5 support [AI-assisted]

by vincentkoc open 2026-02-13 08:57 View on GitHub →
agents stale size: S
#### Summary Add implicit `zai` provider support that discovers model IDs from Z.AI `/models`, so `zai/glm-5` and newer GLM variants work without waiting for static catalog updates. #### Repro Steps 1. Set `ZAI_API_KEY` and configure default model to `zai/glm-5`. 2. Run an agent session where no explicit `models.providers.zai` entry is present. 3. Observe `Unknown model: zai/glm-5` when upstream built-in catalogs lag. #### Root Cause `resolveImplicitProviders` did not register a `zai` provider, so runtime model resolution depended on external built-in catalogs that can lag new Z.AI model IDs. #### Behavior Changes - Adds implicit `zai` provider injection when Z.AI auth is available. - Adds `/models` discovery at `https://api.z.ai/api/paas/v4/models`. - Filters discovered IDs to `glm-*` and maps them into OpenClaw model definitions. - Falls back to a static GLM catalog (`glm-5`, `glm-4.7`, `glm-4.7-flash`, `glm-4.7-flashx`) when discovery fails or returns no GLM IDs. - Preserves current config behavior by storing env auth as env var labels (for `models.providers.*.apiKey`) while using resolved secret values for discovery requests. #### Codebase and GitHub Search - [x] Searched codebase for model discovery and implicit provider patterns (`venice`, `ollama`, `qianfan`, `resolveImplicitProviders`). - [x] Aligned implementation with existing discovery/fallback conventions. - [x] Linked to issue: Fixes #14352. Fixes #15318. #### Tests - `pnpm test src/agents/models-config.providers.zai.test.ts src/agents/models-config.providers.qianfan.test.ts src/agents/models-config.providers.ollama.test.ts` - `pnpm tsgo` #### Manual Testing (omit if N/A) N/A #### Evidence (omit if N/A) - Added `src/agents/models-config.providers.zai.test.ts` covering: - implicit provider injection from `ZAI_API_KEY` - dynamic `/models` discovery and non-GLM filtering **Sign-Off** - Models used: GPT-5 Codex - Submitter effort: implemented + tested locally (targeted tests + typecheck) - Agent notes: lobster-biscuit <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR adds an implicit `zai` provider that is injected when Z.AI authentication is available, and populates its model list via a `/models` discovery call (filtering to `glm-*` IDs) with a static GLM fallback catalog when discovery is unavailable/empty. It also adds a Vitest suite to validate implicit provider injection and the discovery/filtering behavior. In the broader codebase, `resolveImplicitProviders()` feeds into model config generation (`src/agents/models-config.ts`) and ultimately pi-coding-agent model discovery. This change keeps provider configuration using env-var labels for `apiKey` while using the resolved secret value for the discovery request. <h3>Confidence Score: 4/5</h3> - This PR looks safe to merge once existing reviewer comments are addressed. - The ZAI implicit provider injection and discovery logic is self-contained, uses timeouts, and falls back to a static catalog. I did not find additional concrete merge-blocking bugs beyond the two issues already raised in prior threads (vision/reasoning heuristic mismatch and the test’s env mutation flakiness). - src/agents/models-config.providers.ts, src/agents/models-config.providers.zai.test.ts <sub>Last reviewed commit: ab6656f</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs