高度なプロンプト手法
これらのセクションでは、プロンプトの品質を向上させ、拡張思考などの主要な機能を活用する方法に関する高度なガイダンスを提供します。
Amazon Nova 2 モデルはオプションの推論モードを提供し、応答する前に問題を体系的に処理できるようにすることで、複雑な問題解決へのモデルのアプローチを強化します。モデルの推論モードを活用することは、プロンプトの精度を向上させる強力な方法です。
使用するタイミング: 推論モードは、次のような複雑なタスクに推奨されます。
-
複数の推論ステップ: 数学的証明、アルゴリズム設計、システムアーキテクチャ
-
相互参照情報: ドキュメント分析、オプション比較、トレードオフ評価
-
エラーが発生しやすい計算: 財務モデリング、データ分析、複雑なデバッグ
-
制約のある計画: リソースの最適化、依存関係管理、リスク評価
-
複雑な分類: マルチラベル分類、階層分類、微妙な決定境界
-
ツール呼び出しシナリオ: マルチステップ API ワークフロー、データベースクエリの最適化、調整されたシステム統合
注記
推論モードの詳細については、「推論の使用」を参照してください。
モデルが問題を解決するために複数のアプローチを評価する必要がある場合は、トップダウンアプローチを取るように指示します。
-
Amazon Nova 2 モデルは、モデルが全体像から始まり、それをより小さく、より詳細なサブ問題またはステップに分割すると、パフォーマンスが向上します。
-
各パートの詳細を処理する前に、最初に主要な目標を特定し、管理可能なコンポーネントに分解するようにモデルに明示的に指示します。
-
この構造化されたアプローチは、モデルがその思考を整理し、より一貫した推論チェーンを生成するのに役立ちます。
例:
{{User query}}. Start with the big picture and break it down into progressively smaller, more detailed subproblems or steps.
推論モードでは体系的な問題解決を通じて精度が向上しますが、非推論モードでの思考連鎖 (CoT) プロンプトがニーズにより適している特定のシナリオがあります。
使用するタイミング:
-
透明性と監査可能性: モデルの推論プロセスを表示、検証、または監査する場合、CoT は各ステップを完全に可視化します。これは、規制された業界、重要な意思決定、または回答の背後にあるロジックを文書化したい場合に不可欠です。
-
カスタム推論構造: CoT を使用して、特定の推論パターンまたは方法論を適用します。組織の決定フレームワークに従うようにモデルをガイドしたり、ドメイン固有の問題解決アプローチを使用したり、特定の順序で要因が考慮されるようにしたりできます。
-
プロンプト開発とデバッグ: プロンプトエンジニアリングフェーズでは、CoT はモデルが問題にどのようにアプローチするかを理解し、推論がどこで壊れるかを特定し、プロンプトをより効果的に反復するのに役立ちます。
-
ハイブリッドアプローチ: 開発中に CoT を使用してプロンプトを完成させ、特定のユースケースに対するモデルのアプローチに自信が持てたら、本番デプロイの推論モードに切り替えることを検討します。
注記
すべてのタスクに CoT が必要なわけではありません。よりシンプルなタスクでは、モデルが独自の推論プロセスを使用できるようにします。
モデルの CoT 指示のガイド:
{{User query}} Please follow these steps: 1. {{Step 1}} 2. {{Step 2}} ...
Amazon Nova 2 モデルでは、100 万トークンのコンテキスト長がサポートされており、長いドキュメントでのコードの理解と質問への回答に優れています。そのパフォーマンス (システムプロンプトの準拠やツールの使用を含む) は、コンテキストサイズが大きくなるにつれてわずかに低下する可能性があります。
使用方法:
-
長い形式のデータを先頭に配置する: 長いドキュメントと入力をプロンプトの最初の方に配置します。クエリ、手順、例の前にそれらを配置します。
-
最後に指示を配置する: プロンプトの最後に指示を配置します。モデルは、コンテキストが最初に示され、最後に手順が指定されたときに最適に動作します。
-
ドキュメントコンテンツの構造の開始マーカーと終了マーカー:
DOCUMENT {idx} STARTやDOCUMENT {idx} ENDなどの開始マーカーと終了マーカーを使用して、長い文書の先頭と末尾を示します。{idx} は特定のドキュメントのインデックスを表します。
テンプレートの例:
// Provide your long inputs at the top of your prompt BEGIN INPUT DOCUMENTS DOCUMENT 1 START {{Your document}} DOCUMENT 1 END END INPUT DOCUMENTS // Then specify your query and instructions BEGIN QUESTION {{User query}} END QUESTION BEGIN INSTRUCTIONS {{Instructions}} END INSTRUCTIONS
入力クエリに関連する信頼できる情報をモデルに提供することをお勧めします。この情報は、入力クエリとともに、検索拡張生成 (RAG) と呼ばれるシステムの一部にしばしばなります。
-
このプロセスでは、関連するコンテキストドキュメントまたは情報が実際のユーザープロンプトに拡張され、モデルが信頼できるコンテンツを取得して、関連性のある正確なレスポンスを生成します。
-
信頼できるソースからのリファレンステキストを使用して回答するように Amazon Nova 2 に指示すると、提供されたマテリアルに基づいてレスポンスを構成し、そのレスポンスが正確で関連性のある情報に基づいていることを確認し、生成されたコンテンツの信頼性を高めることができます。
-
参照テキストを使用すると、ハルシネーションを回避し、レスポンスの全体的な品質と信用性を向上させることができます。ハルシネーションを最小限に抑えるために、モデルの指示に明示的に
DO NOT USE INFORMATION THAT IS NOT IN REFERENCE TEXTS!を含めることをお勧めします。
プロンプトテンプレート
System: In this session, the model has access to search results and a user's question, your job is to answer the user's question using only information from the search results. Model Instructions: - DO NOT USE INFORMATION THAT IS NOT IN SEARCH RESULTS! User: {Query} Resource: Search Results: {Reference texts}
この例では、グラウンディングコンテキストでモデルのハルシネーションを防ぐ方法を示しています。
システム:
In this session, the model has access to search results and a user's question, your job is to answer the user's question using only information from the search results. Model Instructions:- DO NOT USE INFORMATION THAT IS NOT IN SEARCH RESULTS!
ユーザー:
What were the economic impacts of the COVID-19 pandemic on the United States in 2020? Resource: Search Results: In 2020, the United States experienced significant economic impacts due to the COVID-19 pandemic. The U.S. economy contracted by 3.5% in 2020, according to the Bureau of Economic Analysis. Unemployment rates surged to 14.7% in April 2020, the highest since the Great Depression, before gradually declining. Small businesses faced severe challenges, with millions of firms closing permanently. Additionally, consumer spending dropped sharply as people reduced non-essential expenditures and saved more. Government intervention played a critical role in mitigating these impacts through stimulus packages and support programs, such as the Paycheck Protection Program (PPP) for small businesses and direct payments to individuals. Despite these measures, the economic recovery remained uneven across different sectors and regions.
引用マーカーを使用したグラウンド
長いドキュメントタスクの場合、タスクを進める前に、ドキュメントの関連セクションからの引用を使用してレスポンスをグラウンディングするように Amazon Nova 2 モデルに指示することをお勧めします。
このアプローチは、モデルが最も関連性の高い情報に注目するようにし、無関係なコンテンツによって精度を落とさないようにするのに役立ちます。モデルがその回答をグラウンディングするようリクエストする場合、引用できるセクションに番号を付ける必要があります。例えば、Passage
%[1]%、Passage %[2]% などです。
例引用マーカープロンプト
You are an AI financial assistant. Your task is to find patterns and insights from multi-year financial documents Passage %[1]% {{Your document}} Passage %[2]% {{Your document}} ## Task: Analyze my LLC's reports across multiple years to identify significant performance trends, segment growth patterns and strategic shifts. ## Context information: - You have access to my LLC's annual financial reports (10-K) for multiple fiscal years in PDF format - These reports contain comprehensive financial data including income statements, balance sheets, cash flow statements and management discussions - The analysis should focus on year-over-year comparisons to identify meaningful trends - I operate two business segments, one in Massachusetts and one in New York Based on the provided Context, extract key financial metrics from each year's reports phrases from the documents. Place citations as inline markers (e.g., %[1]%, %[2]%, etc.) directly within the relevant parts of the response text. Do not include a separate citation section after the response. ## Response Schema: %% (Extracted Financial Metrics) %% (Extracted Financial Metrics) %% (Extracted Financial Metrics) ...
ユーザーのタスクに基づいて重要な情報を抽出したら、抽出された財務メトリクスを使用して、次に示すように関連する質問に回答できます。
例抽出されたメトリクスによるフォローアップ分析
## Task Analyze my LLC's financial reports across multiple years to identify significant performance trends, segment growth patterns and strategic shifts. {{extracted financial metrics}} ## Model Instructions: - Organize data chronologically to identify meaningful trends - DO compare segment performance across the five-year period - DO identify significant strategic shifts or investments mentioned in management discussions - DO NOT make speculative predictions beyond what is supported by the data - ALWAYS note any changes in accounting practices or reporting methodologies that might affect year-over-year comparisons ## Response style and format requirements: - Respond in markdown - Structure the analysis with clear headings and subheadings - Present key financial metrics in tabular format showing all five years side-by-side - Include percentage changes year-over-year for all major metrics - Create a section dedicated to visualizing the most significant trends (with descriptions of what would be shown in charts) - Limit the executive summary to 250 words maximum - Format segment analysis as separate sections with consistent metrics across all segments - MUST include a Key Insights bullet-pointed list at the end of each major section
Nova Web Grounding を使用する
Amazon Nova 2 モデルは、サポートテキストでモデルをグラウンディングするための引用を直接プロンプトする代わりに、使用できる内部ウェブグラウンディングツールを提供します。有効にすると、Amazon Nova 2 モデルはウェブと Amazon のナレッジグラフを直接クエリし、引用を用いて最終的なレスポンスをグラウンディングします。
Amazon Nova Web Grounding の活用方法の詳細については、Amazon Nova Web Grounding ユーザーガイドを参照してください。
一貫性のある構造化された出力形式を確保するために、XML、JSON、Markdown などの形式を含む構造化された出力、またはツール使用の機能を使用できます。
-
このアプローチにより、ダウンストリームシステムは、モデルによって生成された出力をより効果的に理解して解析できます。
-
モデルに明示的な指示を提供することで、事前定義されたスキーマに準拠する方法でレスポンスが生成されます。
例えば、ダウンストリームパーサーが JSON オブジェクトのキーに特定の命名規則を想定している場合は、プロンプトの最後にレスポンススキーマを指定する必要があります。さらに、レスポンスを前書きなしで JSON 形式にしたい場合は、そのようにモデルに指示します。つまり、「JSON 出力のみを生成してください」と明示的に述べてください。クリーンな出力を確保するために、プリアンブルを提供しないでください。
ヒント
-
例 (YYYY/MM/DD 形式で日付を指定するなど) を使用するのではなく、スキーマ自体で定義されている場合、データ形式の要件に最もよく準拠していることが分かります。
-
最大 10 個のキーを持つシンプルな JSON 出力については、以下のスキーマを参照してください。より複雑なスキーマの場合は、ツールを使用してスキーマを定義することをお勧めします。ツールの使用は、制約付きデコードと呼ばれる手法を活用して、これらの複雑なスキーマに対するモデルの準拠性を高めます。
一般的な書式設定スキーマ
一般的な形式の例をいくつか次に示します。
アシスタントコンテンツの事前入力
非推論モードで構造化出力を生成している場合は、アシスタントコンテンツを事前に入力することでモデルのレスポンスを促すことができます。
事前入力により、推論を行わないモードでの出力形式の一貫性が向上します。これにより、モデルのアクションを指示し、プリアンブルを省き、JSON や XML などの特定の出力形式を適用できます。例えば、アシスタントコンテンツを { または ```json で事前入力した場合、その入力は、追加情報なしに JSON オブジェクトを生成するようにモデルをガイドします。
ヒント
JSON の抽出を明示的に求めている場合、一般的なパターンの 1 つは、JSON を ```json で事前入力し、``` に停止シーケンスを追加することです。これにより、モデルはプログラムで解析できる JSON オブジェクトを出力します。
例アシスタントコンテンツの事前入力
次のコード例では、API を使用して事前入力する方法を示しています。
import boto3 import json # Create a Bedrock Runtime client. client = boto3.client( "bedrock-runtime", region_name="us-east-1" ) request_body = { "system": [ {"text": "You write JSON objects based on the given instructions"} ], "messages": [ { "role": "user", "content": [{"text": "Provide details about the best selling full-frame cameras in past three years. Answer in JSON format with keys like name, brand, price and a summary."}] }, { "role": "assistant", "content": [{"text": " Here is the JSON response: ```json"}] } ], "inferenceConfig": { "maxTokens": 1000, } } # Invoke the model and extract the response body. response = client.invoke_model( modelId="amazon.nova-2-lite-v1:0", body=json.dumps(request_body) ) model_response = json.loads(response["body"].read())
複雑なスキーマに使用するツールを指定する
他の方法は、ツール使用スキーマセクションに Pydantic JSON スキーマを含めることで、ツールを用いてモデルのレスポンスに特定のスキーマを強制することです。提供されたスキーマにツールの選択を指定できます。Amazon Nova のレスポンスは、選択したツールに基づいて構造化されます。ツール使用の活用方法の詳細については、「ツール使用」を参照してください。
例
適切なスキーマで出力スキーマセクションを追加すると、モデルはそのスキーマに合わせようとします。ただし、モデル出力は決定的ではなく、出力スキーマとは異なる場合があります。
もう 1 つの方法は、アシスタントのメッセージに望ましい最初のテキストを含めることで、モデルのレスポンスを事前入力することです。この場合、Amazon Nova モデルの応答は、アシスタントのメッセージが終わる場所から続行されます。
ヒント: 事前入力は、推論が有効になっていない場合にのみ有効です。
ユーザー:
Provide details about the best selling full-frame cameras in past three years. Your response should be in JSON format, with the following keys: name, brand, year, price, summary.
アシスタント (事前入力):
```json
アシスタント:
{ "cameras": [ { "name": "Sony Alpha A7 III", "brand": "Sony", "year": 2018, "price": "$1999", "summary": "The Sony Alpha A7 III is a highly acclaimed full-frame mirrorless camera known for its excellent image quality, advanced autofocus system, and 4K video capabilities." }, { "name": "Canon EOS R5", "brand": "Canon", "year": 2020, "price": "$3899", "summary": "The Canon EOS R5 is a top-tier full-frame mirrorless camera that offers stunning 45MP images, 8K video recording, and exceptional performance in various lighting conditions." }, { "name": "Nikon Z7 II", "brand": "Nikon", "year": 2020, "price": "$2999", "summary": "The Nikon Z7 II is a flagship full-frame mirrorless camera with a 45.7MP sensor, superb image quality, and advanced video recording features." }, { "name": "Fujifilm GFX 100S", "brand": "Fujifilm", "year": 2020, "price": "$7999", "summary": "The Fujifilm GFX 100S is a medium format mirrorless camera known for its impressive 102MP sensor, beautiful film simulations, and versatile lens options." }, { "name": "Sony Alpha A7R IV", "brand": "Sony", "year": 2019, "price": "$3499", "summary": "The Sony Alpha A7R IV features a 61MP sensor, excellent low-light performance, and advanced video capabilities, making it a favorite among professional photographers." } ] } ```
構造化された出力に事前入力手法を使用する代わりに、Nova のツール機能と toolChoice を組み合わせることができます。この例では、モデルは提供された JSON スキーマに準拠するツール呼び出しを生成し、定義された完全な JSON 形式に指定された特定のツールを呼び出します。その他のガイダンスについては、「アドバンストシステム」を参照してください。
ユーザー:
From the below provided Query, extract the relevent entities Query: John works in BUILDING-0987 and have been incharge of product id 23564#. His performance have been excellent in past year and is up for a raise. Use the extract_ner tool.
ToolConfig:
{ "tools": [ { "toolSpec": { "name": "extract_ner", "description": "Extract all the named entities. based on provided input", "inputSchema": { "json": { "type": "object", "properties": { "entities": { "type": "array", "items": { "type": "object", "properties": { "name": { "type": "string", "description": "The extracted entity name. This should be a name of a person, place, animal or thing" }, "location": { "type": "string", "description": "The extracted location name. This is a site name or a building name like SITE-001 or BUILDING-003" }, "product": { "type": "string", "description": "The extrcted product code, this is generally a 6 digit alphanumeric code such as 45623#, 234567" } }, "required": [ "name", "location", "product" ] } } }, "required": [ "entities" ] } } } }], "toolChoice": { "tool": { "name": "extract_ner" } } }
Amazon Nova 2 モデルは 200 を超える言語でトレーニングされ、15 の言語で最適化されています。
正確な翻訳を求めるプロンプト
ショートフォーム翻訳 (いくつかの文) でこの機能を活用するには、テキストを指定されたターゲット言語に変換するようにモデルに指示できます。
例翻訳プロンプト
Translate the following text into {target language}. Please output only the translated text with no prefix or introduction: {text}
Translate the following sentence from {source_language} to {target language}: {text}
{text} How do you say this sentence in {target_language}
一貫した書き込み規則を適用する
文字ベースの言語では、Amazon Nova 2 モデルはソース言語の文字セットを使用する場合があります。次のプロンプトを使用して、一貫した出力を適用できます。
例書き込み規則を適用する
When translating, ensure to use the correct orthography / script / writing convention of the target language, not the source language's characters
エージェントシステム
トピック
適切な推論パラメータを設定する
ツール呼び出しにはモデルからの非常に具体的な構造化された出力が必要であり、次の推論パラメータを使用することで改善されています。
-
推論なしモード: 温度: 0.7、トップ P: 0.9
-
推論モード: 温度: 1、トップ P: 0.9
レイテンシー要件を考慮する
ヒント
Amazon Nova 2 モデルは、推論をオンまたはオフにしてツールを呼び出すことができます。ただし、推論モードはレイテンシーに大きな影響を与えます。
レイテンシーの影響を受けやすいアプリケーションでは、推論オフモードを最適化し、可能な限り必要なツール呼び出しを簡素化する必要があります。マルチステップワークフローを個別のステップに分割して、モデルの不要なパラメータの再利用への依存を軽減します。
ツール呼び出し手順に意図的な文言を使用する
ツール名: システムプロンプトでツールを参照することは、ツールを呼び出すときにモデルに指示するツール呼び出しシステムで一般的です。プロンプトでツールを参照する場合は、xml または Python のリファレンスや例の代わりにツール名を使用することをお勧めします。
Use the 'run_shell_command' tool for running shell commands
Call run_shell_command() to run shell commands
「思考」コマンドを活用する
思考がツール呼び出しに有益であるすべてのユースケースでは、モデルに「タグを考える」や「思考」ツールを使用するように促すのではなく、推論モードを活用することをお勧めします。
Amazon Nova 2 モデルは推論モード用に広範囲にトレーニングされており、思考の連鎖の推論モードで使用すると最適な結果が得られます。
ツール呼び出しの順序付け
組み込みツールとネイティブツールを同時に呼び出す必要があるユースケースでは、モデルは最初に組み込みツールを呼び出すことに偏ります。
プロンプトで異なる動作をするようにモデルに指示しないでください。代わりに、この点を考慮してワークフローを設計します。
例えば、モデルに組み込みツールを使用しない場合は、モデルにバイアスがかからないようにワークフローに含めないでください。
高品質なツールスキーマを作成する
ツールスキーマは、効果的なツール呼び出しシステムをプロンプトエンジニアリングする上で重要な要素の 1 つです。ただし、ツールスキーマ自体でキャプチャされる内容、各スキーマ要素を意味的に記述する方法、システムプロンプトがシステム指示内でツールとスキーマ要素を参照する方法を考慮することが重要です。
Amazon Nova 2 モデルは、ツールスキーマの簡潔な説明用に最適化されています。簡潔にまとめるようにしましょう。
ツールスキーマとシステムプロンプトのガイドライン:
ツールスキーマに以下が含まれます。
-
主要機能: ツールの動作 (20~50 単語を推奨)
-
パラメータ仕様: 各パラメータの明確な説明 (パラメータあたり約 10 語)
-
想定される形式: データ型 (enum、int、float など)、必須フィールド、有効な値の範囲
システムプロンプトに以下が含まれます。
-
オーケストレーションロジック (特定のツールをいつ、なぜ使用するか) とビジネスルール (条件付きロジック、シーケンス要件、依存関係) を使用して
#Tool Usageセクションを作成します。 -
エラー処理戦略: 障害や予期しない出力に対応する方法の手順を含む
#Error Handling and Troubleshootingセクションを追加します -
出力形式: ユーザーへの提示方法の詳細を追加します
You are a software engineering issue root cause analysis agent. You are tasked with reviewing a customer issue and examining the repository to identify a plan to resolve the issue. # Core Mandates - **DO NOT** update the original issue that was posted by the user. You only add *additional* comments to the reported issue if necessary # Primary Workflows 1. **Understand:** Analyze the user's request and explore the codebase thoroughly using **get_file_contents** to grasp file structures and conventions. 2. **Plan:** Create a coherent, evidence-based plan for resolving the task and share it with the user following the format below # Tool Usage - **Read the Issue:** Always start by using the **read_issue** tool to get the details about the requested issue - **File Paths:** Always end the file path with "/" if you are searching a directory using the **get_file_contents** tools - **Parallelism:** Execute multiple independent tool calls in parallel when feasible # Error Handling and Troubleshooting - **File Exploration:** If you get an error that a file doesn't exist, try searching at the directory level first to validate the file path # Output Formatting Return your plan in markdown in the following format ## Issue <Your root cause analysis of the issue> ## Resolution Plan <your step by step plan of how to solve the issue>
サブエージェントを作成する
次のような問題が発生した場合は、多くのツールを備えた単一のエージェントではなく、特殊なサブエージェントを作成することを検討してください。
-
ツール数が 20 を超える: 大きなツールセットは、管理が困難になり、選択エラーが増加します
-
異なる機能ドメイン: ツールは自然に別々のカテゴリにクラスター化されます (データの取得と処理とレポートなど)
-
複雑なスキーマ: パラメータの深さが 3~4 レベルを超える場合、またはツールに複雑な相互依存関係がある場合
-
会話の長さ: ワークフローが定期的に 15~20 ターンを超えると、特殊なサブエージェントのメリットが得られる可能性があります
-
パフォーマンスの低下: ツールの選択の精度が低下したり、レイテンシーが増加したりした場合
ヒント
MCP サーバーには、制御できないツールとスキーマが付属しています。必要なタスクを完了するため、ワークフローに必要なツールのみを含めてください。
マルチモーダル入力にツールを使用する
マルチモーダルタスクでは、構造化タスク (抽出やタイムスタンプ生成など) のツールを活用して精度が向上したことは確認されていません。
代わりに、「マルチモーダル入力のプロンプト」セクションの関連するセクションで、提供されたテンプレートを使用してモデルに正常にプロンプトを表示する方法を確認することをお勧めします。
次のステップ
-
マルチモーダルプロンプトについては、「マルチモーダル入力のプロンプト」を参照してください。