動かざることバグの如し

近づきたいよ 君の理想に

GLMモデルがclineでちゃんと動くのは特殊対応があるから

環境

  • Cline v3.50.0

GLMモデルすごい

GLM-4.7は、Z.aiが開発した最新の大規模言語モデル(LLM)。2025年12月に公開されたばかりのこのモデルは、特にコーディング能力、複雑な推論、そしてエージェント機能に長けている。

所詮オープンウェイトがクローズドモデルに勝てるかよwとか思っていたのだが、cline経由で使ってみるとめちゃくちゃすごい。Claude Sonnet 4までとはいかないが、確実に3.5以上はあると思っている。

clineでたまーにファイル操作コケることもあるが、割とうまく動作するので特殊な対応しているんじゃないかと思って調査してみた。

GLMモデルの特殊な挙動

Cline側でGLMを触ると「なんか妙に安定して賢い」ように見える理由の一部は、GLMに対して明示的な特別扱いが入っているからだ。ポイントは大きく2つで、推論(thinking)を避ける回避策と、GLM専用のシステムプロンプト最適化である。

GLMファミリーとして判定する(= GLM向けの分岐に入れる)

GLMを「単体のモデル」ではなく「モデルファミリー」として扱っており、IDが特定パターンに一致したらGLM扱いにしている。ここに引っかかると、後述のGLM専用プロンプト・テンプレートが適用される。

cline/src/utils/model-utils.ts

export function isGLMModelFamily(id: string): boolean {
    const modelId = normalize(id)
    return (
        modelId.includes("glm-4.6") ||
        modelId.includes("glm-4.5") ||
        modelId.includes("z-ai/glm") ||
        modelId.includes("zai-org/glm")
    )
}

推論(thinking)をスキップする

GLMはthinkingタグ周りで文字化けする問題があったらしく、Cline側で「推論を使わない」判定が入っている。

cline/src/utils/model-utils.ts

export function shouldSkipReasoningForModel(modelId?: string): boolean {
    if (!modelId) {
        return false
    }
    return modelId.includes("grok-4") || modelId.includes("devstral") || modelId.includes("glm")
}

GLM専用のシステムプロンプトがある

GLM向けに最適化したvariantが定義されていて、モデル判定がGLMならこのテンプレートに切り替わる。

cline/src/core/prompts/system-prompt/variants/glm/config.ts

export const config = createVariant(ModelFamily.GLM)
    .description("Prompt optimized for GLM-4.6 model with advanced agentic capabilities.")
    .version(1)
    .tags("glm", "stable")
    .labels({
        stable: 1,
        production: 1,
    })
    .matcher((context) => {
        return isGLMModelFamily(context.providerInfo.model.id)
    })
    .template(baseTemplate)

ツール呼び出し周りの指示が強めに上書きされている

GLM用のテンプレートでは、最初にコードベース探索→計画→実装の順で進めることを強制しつつ、「ツール呼び出しはassistantメッセージでやれ。推論ブロック内に置くな」と明確に釘を刺している。ここが効くと、Clineのエージェント動作が崩れにくくなるんだと思う。

cline/src/core/prompts/system-prompt/variants/glm/overrides.ts

const GLM_TOOL_USE_TEMPLATE = (context: SystemPromptContext) => {
    const hasMcpServers = hasEnabledMcpServers(context)

    return `Begin every task by exploring the codebase (e.g., list_files, search_files, read_file) and outlining the required changes. Do not implement until exploration yields enough context to state objectives, approach, affected files, and risks. Briefly summarize the plan, then proceed with implementation.

Tool invocation policy: Invoke tools only in assistant messages; they will not execute if placed inside reasoning blocks. Use reasoning blocks solely for analysis/option-weighing; place all tool XML blocks in assistant messages to execute them.

`

なお。この特別扱いはCHANGELOGにも載っている GLMのthinkingタグ文字化けに対して「reasoningをproperly disabled」と明言しているので、体感の安定性アップは気のせいではない。

CHANGELOG.md

- Fixed GLM models outputting garbled text in thinking tags—reasoning is now properly disabled for these models

まとめ

GLM特殊対応受けているから精度が上がってclineから使うときに(LLM本来の性能以上に)良く見えているというのはありそう。やはりメジャーなLLMを使うっていうのは大事なのかもしれない。