#15327: feat:(models): discover ZAI models dynamically for GLM-5 support [AI-assisted]
agents
stale
size: S
Cluster:
Model Management Enhancements
#### 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
#19326: Agents: improve z.ai GLM-5 integration and failover
by gabrielespinheira · 2026-02-17
78.2%
#15991: feat: add Novita AI provider support with dynamic model discovery
by Alex-wuhu · 2026-02-14
78.0%
#16766: fix(model): apply provider baseUrl/headers override to registry-fou...
by dzianisv · 2026-02-15
77.6%
#9822: fix: allow local/custom model providers for sub-agent inference
by stammtobias91 · 2026-02-05
77.4%
#20965: feat: Add comprehensive model configuration and discovery for various…
by rodeok · 2026-02-19
77.3%
#9583: fix(models): allow models in agents.defaults.models even if not in ...
by hotzen100 · 2026-02-05
77.2%
#7570: fix: allow models from providers with auth profiles configured
by DonSqualo · 2026-02-03
77.1%
#12020: feat: add AIsa provider, production-grade Chinese AI models
by renning22 · 2026-02-08
77.0%
#9739: #9291 fix(models): preserve existing models in models.json when mer...
by ximzzzzz · 2026-02-05
76.6%
#14508: fix(models): allow forward-compat models in allowlist check
by jonisjongithub · 2026-02-12
76.1%