DeepSeek-R1 & DeepSeek-V3.2 · 決定論的エージェント & 評価 Harness

DeepSeek 推論最適化と DeepSeek Harness 構築ガイド

DeepSeek-R1 の <think> 推論トレース誘導、サンドボックス化された DeepSeek Harness ツールループ、コストを最大 90% 削減する KV キャッシュ設計、自動検証ゲートを体系化。

DeepSeek-R1 · 推論制御

ゼロショット <think> 誘導と不変条件の明示

DeepSeek-R1 では冗長な Few-Shot 例を省き、システム不変条件・境界条件・検証チェックリストを明示することで、<think> での自己検証精度が最大化されます。

[DeepSeek-R1 Reasoning Contract]
Goal: Fix the race condition in async connection pool checkout.
Invariants:
1. Never hold the pool mutex across an await boundary.
2. Preserve FIFO fairness for waiting coroutines on timeout cancellation.
3. In <think>, trace 2 concurrent cancellation interleavings first.
Output: Minimal unified diff + 1 deterministic reproduction pytest.
DeepSeek Harness · コア設定

決定論的 Harness 宣言設定 (harness.yaml)

DeepSeek Harness は推論を分離された Git Worktree とコンテナ内に閉じ込め、mypy や pytest のエラー出力を自動で推論ループへフィードバックします。

# deepseek-harness.yaml
model: deepseek-reasoner
max_turns: 8
temperature: 0.0
workspace:
  isolation: git-worktree
  timeout_sec: 120
verification_gates:
  - name: typecheck
    run: "mypy --strict src/"
  - name: unit_tests
    run: "pytest -q --maxfail=3"
on_failure: inject_stderr_and_retry
DeepSeek Harness · ループ制御

サンドボックス実行と重複パッチ防止ガード

生成されたパッチの SHA-256 ハッシュを記録し、同一の失敗パッチが再提案された場合は即座に <think> 仮説の再構築を促します。

# Harness Tool-Loop Guard
def step_guard(history, patch_diff, exit_code):
    digest = sha256(patch_diff.encode()).hexdigest()
    if digest in history.seen_patches:
        return "ABORT_DUPLICATE_PATCH: Revise root-cause hypothesis in <think>."
    history.seen_patches.add(digest)
    return "PASS" if exit_code == 0 else "RETRY_WITH_TRUNCATED_STDERR" 
DeepSeek-V3.2 · KV キャッシュ

プレフィックス固定による 90% コスト削減

リポジトリ構造マップと Harness 仕様を messages[] の先頭に固定し、末尾にのみ差分ログを追加することで $0.028/1M のキャッシュヒットを継続維持できます。

messages = [
  {"role": "system", "content": STATIC_HARNESS_SPEC + FROZEN_REPO_MAP}, # 100% Hit ($0.028/1M)
  *prior_turn_messages,                                                 # Prefix KV-Cache
  {"role": "user", "content": latest_pytest_stderr_diff}                # Dynamic Tail Only
]
DeepSeek-V3.2 · コード編集

アトミックな SEARCH / REPLACE 差分パッチ

200行を超えるファイルの全文再出力を避け、AST 構文検証付きの SEARCH/REPLACE ブロックで安全に適用します。

<<<<<<< SEARCH
async def acquire(self, timeout: float = 5.0) -> Conn:
    return await asyncio.wait_for(self._queue.get(), timeout)
=======
async def acquire(self, timeout: float = 5.0) -> Conn:
    conn = await asyncio.wait_for(self._queue.get(), timeout)
    if conn.is_closed():
        return await self._create_replacement()
    return conn
>>>>>>> REPLACE
DeepSeek Harness · 自動評価

並列トラジェクトリ採点と回帰ゲート

固定されたリポジトリスナップショットに対して pass@1 評価を並列実行し、KV キャッシュヒット率とパッチ品質を自動集計します。

$ deepseek-harness eval \
    --suite benchmarks/swe_verified_subset.jsonl \
    --model deepseek-reasoner \
    --workers 8 \
    --assert-cache-hit-rate 0.75 \
    --report-out reports/r1-eval-summary.json
DeepSeek-V3.2 · DeepSeek-R1 · KV-Cache Hit Optimization

DeepSeek モデル価格 & プレフィックス KV キャッシュ料金一覧

DeepSeek 公式 API モデルの静的料金一覧(キャッシュヒット単価含む)と月間コスト試算ツール。

月間推定消費量と推奨構成 1,200 Credits / mo Pro ($10/mo)
モデル名コンテキスト最大出力 入力 (キャッシュHit)入力 (キャッシュMiss)出力単価推奨 Harness 用途
DeepSeek-V3.2 (deepseek-chat) 128K 8K $0.028 / 1M $0.27 / 1M $1.10 / 1M High-throughput coding, tool calling & prefix-cached harness loops
DeepSeek-R1 (deepseek-reasoner) 128K 32K (64K CoT) $0.14 / 1M $0.55 / 1M $2.19 / 1M Architecture verification, multi-step debugging & SWE-bench repair
DeepSeek-Coder-V2-Instruct 128K 8K $0.014 / 1M $0.14 / 1M $0.28 / 1M Repository FIM completion, AST refactoring & unit test generation
DeepSeek-R1-Distill-Qwen-32B 128K 16K Local / BYOK $0.08 / 1M $0.24 / 1M Low-latency local harness verification & deterministic CI gates