Skip to content

Commit 58c4fc4

Browse files
committed
Fix: use reasoningEffort instead of variant for GLM reasoning control
Z.AI's GLM-5.2 API uses reasoning_effort as a top-level parameter (values: max, high, low), NOT OpenCode's variant field. OpenCode passes unrecognized agent frontmatter fields through to the provider as model options. Setting reasoningEffort: 'max' on an agent gets sent to Z.AI as reasoning_effort='max' — the correct parameter. Changes: - models.sh: inject reasoningEffort instead of variant - models.sh: strip function cleans model, variant, AND reasoningEffort - install.sh: updated warning text to explain the mapping Source repo agents are unaffected (template has no model/effort fields). Deployed targets need re-install to get the corrected field.
1 parent c75c9fb commit 58c4fc4

2 files changed

Lines changed: 16 additions & 18 deletions

File tree

.opencode/install.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,10 @@ fi
133133
# ── Validate models ──────────────────────────────────────────────
134134
printf '\n── Validating models ──────────────────────────────────────\n'
135135

136-
# Warn about variants if provided
136+
# Warn about reasoning effort if provided
137137
if [ -n "$opus_variant$sonnet_variant$haiku_variant" ]; then
138-
printf ' ⚠ Variants are provider-specific. If your provider does not support\n' >&2
139-
printf ' the variant parameter, subagent tasks will fail with "Invalid API\n' >&2
140-
printf ' parameter". If this happens, re-run without --variant-* flags.\n\n' >&2
138+
printf ' Note: reasoning effort maps to the provider'\''s reasoning_effort API parameter.\n'
139+
printf ' Z.AI/GLM accepts: max, high, low. Other providers may differ.\n\n'
141140
fi
142141

143142
validation_failed=0

.opencode/lib/models.sh

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ else:
6060
" 2>/dev/null
6161
}
6262

63-
# Inject or replace model: in an agent file's frontmatter
64-
# Usage: ccgs_inject_model <agent_file> <model_id> [variant]
65-
# Note: variant is provider-specific and may cause "Invalid API parameter"
66-
# errors if the provider doesn't support it. Leave empty to omit.
63+
# Inject or replace model: and reasoningEffort: in an agent file's frontmatter
64+
# Usage: ccgs_inject_model <agent_file> <model_id> [effort]
65+
# Note: reasoningEffort maps to the provider's reasoning_effort API parameter.
66+
# Z.AI/GLM accepts: "max", "high", "low". Other providers may differ.
6767
ccgs_inject_model() {
68-
local file="$1" model_id="$2" variant="${3:-}"
68+
local file="$1" model_id="$2" effort="${3:-}"
6969
python3 -c "
7070
import sys, re, yaml
7171
@@ -74,14 +74,15 @@ with open('$file') as f:
7474
7575
m = re.match(r'^(---\n)(.*?)(\n---)', txt, re.S)
7676
if not m:
77-
print(f'ERROR: no frontmatter in $file', file=sys.stderr)
77+
print(f'ERROR: no frontmatter in {file}', file=sys.stderr)
7878
sys.exit(1)
7979
8080
fm = yaml.safe_load(m.group(2))
8181
fm['model'] = '$model_id'
82-
if '$variant':
83-
fm['variant'] = '$variant'
82+
if '$effort':
83+
fm['reasoningEffort'] = '$effort'
8484
else:
85+
fm.pop('reasoningEffort', None)
8586
fm.pop('variant', None)
8687
8788
# Re-dump frontmatter preserving key order
@@ -109,12 +110,10 @@ if not m:
109110
110111
fm = yaml.safe_load(m.group(2))
111112
changed = False
112-
if 'model' in fm:
113-
del fm['model']
114-
changed = True
115-
if 'variant' in fm:
116-
del fm['variant']
117-
changed = True
113+
for key in ('model', 'variant', 'reasoningEffort'):
114+
if key in fm:
115+
del fm[key]
116+
changed = True
118117
if not changed:
119118
sys.exit(0)
120119

0 commit comments

Comments
 (0)