Skip to content

feat(guardrails): multi-model delegation gates — OpenCode competitive advantage #124

@terisuke

Description

@terisuke

概要

OpenCode が Claude Code に対して持つ最大の競争優位性はマルチモデル・マルチプロバイダー対応
Claude Code は Codex delegation gates (7本のhook) で Codex CLI にタスクをルーティングするが、OpenCode はそれを超えて、異なるプロバイダー(Anthropic, OpenAI, Google, ZAI, OpenRouter)の異なるモデルをエージェントごとに最適配置できる。

技術的背景

  • packages/opencode/src/agent/agent.ts:39-43 — Agent.Info に model: { modelID, providerID } フィールド
  • packages/opencode/src/tool/task.ts:108 — タスク委任時に agent.model ?? parent.model で解決
  • packages/opencode/src/config/config.ts:894small_model で軽量タスク用モデル分離
  • @opencode-ai/pluginchat.params, permission.ask, tool.execute.before hookが利用可能

実装する delegation gates (guardrail.ts に追加)

1. agent-model-mapping (chat.params)

エージェントタイプに基づく最適モデル推奨・強制

  • review/explore → 安価モデルOK
  • implement/security → 高性能モデル推奨
  • 設定: opencode.json の agent 設定から読み取り

2. delegation-budget-gate (tool.execute.before for task)

タスク委任の予算管理

  • セッション内の累計コスト追跡
  • 並列タスク数の上限制御(provider別)
  • 高コストモデルの使用回数制限

3. provider-routing-advisory (chat.params)

プロバイダー特性に基づくルーティング助言

  • コードタスクに特化したモデル検出
  • コスト効率の良い代替モデル提案

4. parallel-execution-gate (tool.execute.before for task)

並列実行の安全制御

  • 同時タスク数をプロバイダー/モデル別に制限
  • rate limit 超過の事前検出

5. cost-tracking (tool.execute.after for task)

コスト追跡と可視化

  • プロバイダー別・エージェント別のコスト記録
  • セッション終了時のコストサマリー

Claude Code の Codex delegation gates との対応

Claude Code hook OpenCode 対応 進化点
codex-task-gate delegation-budget-gate 単一Codex → 任意プロバイダー
codex-model-gate agent-model-mapping Codex固定 → エージェント別モデル
codex-parallel-gate parallel-execution-gate 同等 + プロバイダー別制限
codex-cost-gate cost-tracking Codex API → 全プロバイダーコスト
codex-timeout-gate (not needed) OpenCode のタスクには組み込みタイムアウトあり
codex-output-gate verify-agent-output (Issue別) 同等
codex-error-gate tool-failure-recovery (Issue別) 同等

受入基準

  • guardrail.ts に 5 つの delegation gate を追加
  • opencode.json に delegation 設定セクション追加
  • state.json に delegation 追跡フィールド追加
  • 各 gate が正しいフック型で発火することを確認
  • ADR 作成: 007-multi-model-delegation-gates.md

関連

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions