0Pricing
AI Prompt Engineering · レッスン

Extended Thinkingに効果的なプロンプト

プロンプトはシンプルにし、手順を逐一指示せず、モデルの推論を信頼します。

「Extended Thinkingに効果的なプロンプト」はCoddyKit上の無料AI Prompt Engineeringレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはAI Prompt Engineering学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 AI Prompt Engineeringコースには全4レッスンが含まれています。

推論モデルへのプロンプト作成は異なります

標準モデル向けに身につけたプロンプト作成の直感、つまりchain-of-thought、段階的な指示、few-shot例は、推論モデルでは逆効果になることがあります。

推論モデルは、すでに高度な内部推論を行っています。どのように考えるかを細かく指示すると、そのプロセスを妨げる可能性があります。推論モデルに最適なプロンプトは、標準モデル向けのプロンプトよりもシンプルで直接的です。

段階的に指示しない

標準モデルでは、次のように記述します。「段階的に考えてください。まずXを検討し、次にYを検討して、最後にZと結論づけてください。」この足場かけが役立つのは、標準モデルがこれを自動的には行わないためです。

推論モデルでは、この足場かけによって内部推論が最適ではない経路に制約される可能性があります。代わりに、問題を明確に示し、どのように推論するかはモデルに判断させてください。

# Standard model: needs scaffolding
STANDARD_PROMPT = (
    'Let us think step by step.\n'
    'First, identify the variables.\n'
    'Then, set up the equation.\n'
    'Then, solve for x.\n'
    'Finally, verify your answer.\n\n'
    'Problem: If 3x + 7 = 22, what is x?'
)

# Reasoning model: just state the problem clearly
REASONING_PROMPT = (
    'Solve: If 3x + 7 = 22, what is x?'
    # The model handles the step-by-step internally
)

# Both produce correct answers; the reasoning model prompt is simpler
print('Reasoning model prefers the cleaner prompt')

問題を明確かつ完全に示す

推論モデルへの指示の方法は簡潔にする一方で、何を求めているかについては十分に説明してください。コンテキスト、制約、要件をすべて最初に提示します。モデルはそれらを内部推論で使用します。

import anthropic

client = anthropic.Anthropic(api_key='sk-ant-...')

# Poor: vague problem statement
BAD_PROMPT = 'Write me a good sorting algorithm.'

# Good: clear, complete problem specification
GOOD_PROMPT = (
    'Write a Python sorting algorithm with these requirements:\n'
    '- Must sort a list of integers in ascending order\n'
    '- Must work correctly on empty lists, single-element lists, and lists with duplicates\n'
    '- Target time complexity: O(n log n) average case\n'
    '- Must not use Python built-in sort() or sorted()\n'
    '- Include a brief docstring and 3 test cases\n\n'
    'Return only the code, no explanation.'
)

response = client.messages.create(
    model='claude-opus-4-5',
    max_tokens=8000,
    thinking={'type': 'enabled', 'budget_tokens': 5000},
    messages=[{'role': 'user', 'content': GOOD_PROMPT}]
)
print(next(b.text for b in response.content if b.type == 'text')[:300])

budget_tokensを適切に設定する

budget_tokensは、思考トークンの最大数を制御します。適切に設定することが、推論モデルに対する主な調整手段です。

  • 1,000~2,000: 単純な問題、簡単な計算
  • 5,000~10,000: 中程度の複雑さのコーディング、分析
  • 16,000以上: 最も難しい数学、複雑なシステム設計、研究レベルの問題
import anthropic

client = anthropic.Anthropic(api_key='sk-ant-...')

def reasoning_call(prompt, budget_tokens=5000):
    response = client.messages.create(
        model='claude-opus-4-5',
        max_tokens=budget_tokens + 2048,  # max_tokens must exceed budget_tokens
        thinking={
            'type': 'enabled',
            'budget_tokens': budget_tokens
        },
        messages=[{'role': 'user', 'content': prompt}]
    )
    answer = next((b.text for b in response.content if b.type == 'text'), '')
    thinking_blocks = [b for b in response.content if b.type == 'thinking']
    print(f'Thinking blocks: {len(thinking_blocks)}')
    return answer

# Simple problem: small budget
reasoning_call('What is 17 * 23?', budget_tokens=1000)

# Complex problem: larger budget
reasoning_call(
    'Design a distributed rate limiter that handles 100k requests/second.',
    budget_tokens=10000
)

最小限のシステムプロンプト

推論モデルでは、システムプロンプトを最小限に保ってください。モデルの内部推論が主な能力であるため、長い行動指示で過度に制約しないでください。

推論モデルに適したシステムプロンプトでは、役割を設定し、出力形式を定義し、制約を指定します。それだけで十分です。

# Over-engineered system prompt (hurts reasoning models)
BAD_SYSTEM = (
    'You are an expert Python developer. '
    'Always think step by step. '
    'First understand the problem. '
    'Then plan your approach. '
    'Then implement step by step. '
    'Check each step before proceeding. '
    'Finally review your solution. '
    'Format all code with comments. '
    'Add error handling to every function. '
    '...'
)

# Minimal system prompt (helps reasoning models)
GOOD_SYSTEM = (
    'You are an expert Python developer. '
    'Return only code unless explanation is explicitly requested. '
    'Use type hints and docstrings.'
)
# The model's internal reasoning handles the rest

出力形式の指示は依然として重要

どのように推論するかを指示するべきではありませんが、希望する出力形式は明確に指定してください。これは推論の指示とは異なります。モデルに考え方ではなく、何を返すかを伝えるものです。

import anthropic

client = anthropic.Anthropic(api_key='sk-ant-...')

# Clear output format instructions are still important
prompt = (
    'Analyze the time and space complexity of this Python function:\n\n'
    'def bubble_sort(arr):\n'
    '    n = len(arr)\n'
    '    for i in range(n):\n'
    '        for j in range(0, n-i-1):\n'
    '            if arr[j] > arr[j+1]:\n'
    '                arr[j], arr[j+1] = arr[j+1], arr[j]\n\n'
    'Return your answer as JSON with keys: '
    'time_complexity, space_complexity, explanation (2 sentences max).'
)

response = client.messages.create(
    model='claude-opus-4-5',
    max_tokens=5000,
    thinking={'type': 'enabled', 'budget_tokens': 3000},
    messages=[{'role': 'user', 'content': prompt}]
)
print(next(b.text for b in response.content if b.type == 'text'))

Few-shot例を減らす

標準モデルは、3~5個のfew-shot例から大きな恩恵を受けます。推論モデルではその効果が小さく、例が多すぎると、内部推論を妨げる内容でコンテキストウィンドウを埋めてしまい、かえって悪影響を及ぼす可能性があります。

推論モデルでは、例は0~1個が最適なことが多くなります。出力形式が特殊または曖昧な場合にのみ、例を使用してください。

# Standard model: 3 few-shot examples improve performance significantly
STANDARD_FEW_SHOT = (
    'Q: 2 + 2 = ?\nA: 4\n\n'
    'Q: 5 * 6 = ?\nA: 30\n\n'
    'Q: 100 / 4 = ?\nA: 25\n\n'
    'Q: 17 + 38 = ?\nA:'
)

# Reasoning model: 0 examples is fine; 1 is enough if format is unclear
REASONING_DIRECT = 'What is 17 + 38?'

# The reasoning model already knows math — examples are overhead, not signal
# Only use 1 example when the output format needs clarification:
REASONING_FORMAT_EXAMPLE = (
    'Answer math questions returning only the number.\n'
    'Example: Q: 2 + 2  A: 4\n\n'
    'Q: 17 + 38'
)

推論モデルの出力における不確実性への対処

推論モデルは、標準モデルよりも本当の不確実性を表現する可能性が高くなります(実際に考えた結果であるためです)。控えめな表現を含む応答にも適切に対処できるよう、アプリケーションを設計してください。

import anthropic
import re

client = anthropic.Anthropic(api_key='sk-ant-...')

def reasoning_with_confidence(question):
    prompt = (
        f'{question}\n\n'
        f'At the end of your answer, include a confidence statement: '
        f'Confidence: [HIGH/MEDIUM/LOW] — [one sentence why]'
    )
    response = client.messages.create(
        model='claude-opus-4-5',
        max_tokens=8000,
        thinking={'type': 'enabled', 'budget_tokens': 5000},
        messages=[{'role': 'user', 'content': prompt}]
    )
    text = next(b.text for b in response.content if b.type == 'text')

    # Parse confidence
    match = re.search(r'Confidence: (HIGH|MEDIUM|LOW)', text)
    confidence = match.group(1) if match else 'UNKNOWN'
    print(f'Confidence: {confidence}')
    return text, confidence

answer, conf = reasoning_with_confidence(
    'What will AI capabilities look like in 2030?'
)

推論モデルの出力をキャッシュする

推論モデルの呼び出しには高いコストと時間がかかります。繰り返し実行されるクエリや予測可能なクエリの結果をキャッシュしてください。思考トークンは非常に長くなることがあるため、キャッシュによって、繰り返しの呼び出しでレイテンシーとコストを再び支払う必要がなくなります。

import hashlib
import json
import os

cache_dir = '/tmp/reasoning_cache'
os.makedirs(cache_dir, exist_ok=True)

def cached_reasoning_call(prompt, budget_tokens=5000):
    # Create cache key from prompt
    key = hashlib.sha256(f'{prompt}:{budget_tokens}'.encode()).hexdigest()
    cache_file = os.path.join(cache_dir, f'{key}.json')

    if os.path.exists(cache_file):
        with open(cache_file) as f:
            cached = json.load(f)
        print('Cache hit!')
        return cached['answer']

    # Cache miss: call the model
    answer = reasoning_call(prompt, budget_tokens)

    with open(cache_file, 'w') as f:
        json.dump({'prompt': prompt, 'answer': answer}, f)

    return answer

推論モデルの出力を検証する

推論モデルはエラーが少ないものの、特に分野固有の事実や最先端のトピックについては、完全に誤りがないわけではありません。重大な結果につながる状況で使用する出力は、必ず検証してください。

import anthropic

client = anthropic.Anthropic(api_key='sk-ant-...')

def reasoning_with_verification(question):
    # Step 1: Get reasoning model answer
    r1 = client.messages.create(
        model='claude-opus-4-5',
        max_tokens=10000,
        thinking={'type': 'enabled', 'budget_tokens': 8000},
        messages=[{'role': 'user', 'content': question}]
    )
    answer = next(b.text for b in r1.content if b.type == 'text')

    # Step 2: Independent verification call
    verify_prompt = (
        f'Question: {question}\n\n'
        f'Proposed answer: {answer}\n\n'
        f'Is this answer correct? Respond with CORRECT, INCORRECT, or UNCERTAIN, '
        f'followed by a brief explanation.'
    )
    r2 = client.messages.create(
        model='claude-opus-4-5',
        max_tokens=256,
        messages=[{'role': 'user', 'content': verify_prompt}]
    )
    verification = r2.content[0].text
    print(f'Verification: {verification[:100]}')
    return answer, verification

推論モデルのプロンプトに関する実践チェックリスト

推論モデルのプロンプトを作成するときは、次のチェックリストに従ってください。

  • 問題を明確かつ完全に示す
  • 段階的な推論の指示を含めない
  • システムプロンプトを短く保つ(役割、形式、制約のみ)
  • few-shot例は最大でも0~1個にする
  • 出力形式を明示的に指定する
  • 問題の複雑さに比例して budget_tokens を設定する
  • 10~60秒の応答レイテンシーを想定する

理解度チェック: 推論モデルへのプロンプト作成

標準モデルと比べて、推論モデルにはよりシンプルなプロンプトを使用することが推奨されるのはなぜですか。

まとめ: 拡張思考に効果的なプロンプト

推論モデルには、標準モデルよりもシンプルで直接的なプロンプトが必要です。どのように推論するかを指示せず、問題を明確かつ完全に示したうえで、方針はモデルの内部推論に任せてください。システムプロンプトは、役割、出力形式、制約だけに絞って最小限に保ちます。few-shot例は0~1個にしてください。budget_tokensは問題の複雑さに合わせて設定します(単純な問題には1K、難しい問題には10K以上)。大幅なレイテンシーを見込み、可能な場合は結果をキャッシュしてください。出力形式は明示的に指定してください。詳細な指示が依然として役立つのは、この部分です。

よくある質問

「Extended Thinkingに効果的なプロンプト」レッスンは無料ですか?

はい。「Extended Thinkingに効果的なプロンプト」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、AI Prompt Engineeringコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 AI Prompt Engineeringコースには全4レッスンが含まれています。

「Extended Thinkingに効果的なプロンプト」で何を学びますか?

プロンプトはシンプルにし、手順を逐一指示せず、モデルの推論を信頼します。 ブラウザで直接実行するハンズオンコードでAI Prompt Engineeringを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

AI Prompt Engineeringを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのAI Prompt Engineeringは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。

「Extended Thinkingに効果的なプロンプト」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このAI Prompt Engineeringレッスンでコードを書いて実行できますか?

はい。すべてのAI Prompt Engineeringレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. 推論モデルの違い
  2. Extended Thinkingに効果的なプロンプト
  3. 推論モデルと標準モデルの使い分け
  4. コストとレイテンシのトレードオフ
← AI Prompt Engineeringに戻る