

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 進階提示技巧
<a name="advanced-prompting-techniques"></a>

這些章節提供進階指引，說明如何改善提示的品質，並利用延伸思考等重要功能。

## 使用原因模式
<a name="use-reasoning-mode"></a>

Amazon Nova 2 模型提供選用的推理模式，透過讓模型在回應之前有系統地處理問題，增強模型解決複雜問題的方法。利用模型的推理模式是改善提示準確性的強大方式。

**使用時機：**建議將合理模式用於複雜任務，例如具有下列項目的使用案例：
+ **多個推理步驟：**數學驗證、演算法設計、系統架構
+ **交互參考資訊：**文件分析、選項比較、權衡評估
+ **容易出錯的計算：**財務建模、資料分析、複雜偵錯
+ **使用限制進行規劃：**資源最佳化、相依性管理、風險評估
+ **複雜分類：**多標籤分類、階層式分類法、細微決策界限
+ **工具呼叫案例：**多步驟 API 工作流程、資料庫查詢最佳化、協調系統整合

**注意**  
如需推理模式的詳細資訊，請參閱 [使用推理](using-converse-api.md#converse-api-reasoning)。

## 採取由上而下的方法
<a name="top-down-approach"></a>

對於模型需要評估多種方法來解決問題的情況，請指示它採取**由上而下**的方法。
+ 當模型從大局開始，然後分解為更小、更詳細的子問題或步驟時，Amazon Nova 2 模型的效能更好。
+ 明確指示模型先識別主要目標，然後將其分解為可管理的元件，然後再處理每個部分的詳細資訊。
+ 這種結構化方法有助於模型組織其思維，並產生更一致的推理鏈。

**範例**：

```
{{User query}}. Start with the big picture and break it down into progressively smaller, more detailed subproblems or steps.
```

## 行進思維鏈
<a name="steer-chain-of-thought"></a>

雖然推理模式透過系統化問題解決來提高準確性，但在某些情況下，以非合理模式發出 Chain of Thought (CoT) 提示可能會更好地滿足您的需求。

**使用時機：**
+ **透明度和可稽核性：**當您想要查看、驗證或稽核模型的推理程序時，CoT 會提供每個步驟的完整可見性。這對於受管制產業、高風險決策，或您想要記錄答案背後的邏輯時至關重要。
+ **自訂推理結構：**使用 CoT 強制執行特定推理模式或方法。您可以引導模型遵循組織的決策架構、使用特定領域的問題解決方法，或確保依特定順序考慮因素。
+ **提示詞開發和偵錯：**在提示詞工程階段期間，CoT 可協助您了解模型如何處理問題，找出原因分解的位置，並更有效地重複提示詞。
+ **混合方法：**考慮在開發期間使用 CoT 來完善您的提示，然後在您對模型對特定使用案例的方法有信心之後，切換至生產部署的推理模式。

**注意**  
並非所有任務都需要 CoT。對於更簡單的任務，允許模型使用自己的推理程序。

**引導模型的 CoT 方向：**

```
{{User query}} Please follow these steps:

1. {{Step 1}}
2. {{Step 2}}
...
```

## 使用長上下文視窗
<a name="utilizing-long-context"></a>

Amazon Nova 2 模型支援的內容長度為 100 萬個字符，並擅長理解程式碼和回答長文件的問題。其效能 （包括系統提示遵循和工具使用） 可能會隨著內容大小的增加而稍微下降。

**如何使用它：**
+ **將長格式資料放在開頭**：將長文件和輸入放在提示詞的開頭附近。將它們放在查詢、指示和範例之前。
+ **將指示放在末尾**：將指示放在提示詞的末尾。當先提供上下文，並在末尾提供指示時，模型會發揮最佳效能。
+ **結構文件內容開始和結束標記：**使用開始和結束標記，例如 `DOCUMENT {idx} START`和 `DOCUMENT {idx} END`來表示長文件的開始和結束，其中 \$1idx\$1 代表特定文件的索引。

**範本範例：**

```
// 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
```

## 支援文字中的基本答案
<a name="ground-answers-supporting-text"></a>

我們建議您為模型提供與輸入查詢相關的可信資訊。此資訊與輸入查詢通常是系統的一部分，稱為擷取擴增產生 (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}
```

### 範例：提供接地內容有助於防止模型幻覺
<a name="grounding-example"></a>

此範例顯示接地內容如何防止模型幻覺。

系統：

```
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.
```

### 使用引文標記的 Ground
<a name="grounding-citations"></a>

對於長文件任務，我們建議您指示 Amazon Nova 2 模型在繼續任務之前，使用文件相關區段的引文來建立回應。

這種方法有助於模型專注於最相關的資訊，避免因不必要的內容而分心。當您請求模型以其回應為基礎時，應該對可引用的區段進行編號。例如， `Passage %[1]%``Passage %[2]%`等。

#### 範例：使用引文標記
<a name="citations-example"></a>

**Example 引文標記提示**  

```
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)
...
```

根據使用者的任務擷取金鑰資訊後，您可以使用擷取的財務指標來回答相關問題，如下所示：

**Example 使用擷取的指標進行後續分析**  

```
## 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
<a name="prompting-web-grounding"></a>

Amazon Nova 2 模型提供可使用的內部 Web 基礎工具，而不是直接提示引文將模型置於支援文字中。啟用時，Amazon Nova 2 模型會直接查詢 Web 和 Amazon 的知識圖表，並以引文做為最終回應的基礎。

若要進一步了解如何利用 Amazon Nova Web Grounding，您可以參考 [Amazon Nova Web Grounding 使用者指南](https://docs.aws.amazon.com/nova/latest/nova2-userguide/web-grounding.html)。

## 產生結構化輸出
<a name="prompting-structured-output"></a>

為了確保一致的結構化輸出格式，您可以使用結構化輸出，包括 XML、JSON、Markdown 等格式，或使用工具使用功能。
+ 此方法可讓下游系統更有效地了解和剖析模型產生的輸出。
+ 透過提供明確指示給模型，模型會以遵循預先定義之結構描述的方式產生回應。

例如，如果下游剖析器預期 JSON 物件中金鑰的特定命名慣例，您應該在提示結尾指定回應結構描述。此外，如果您偏好回應為 JSON 格式，而且沒有任何前序文字，請相應地指示模型。也就是說，明確狀態 **請僅產生 JSON 輸出。請勿提供任何前綴。** 以確保輸出乾淨。

**提示**  
當資料格式要求是在結構描述本身中定義，而不是透過使用範例 （例如，以 YYYY/MM/DD 格式指定日期） 時，我們會觀察到最符合資料格式的要求。
對於最多 10 個金鑰的簡單 JSON 輸出，您可以在下面找到結構描述。對於更複雜的結構描述，我們建議您透過工具定義結構描述。工具使用利用稱為限制解碼的技術，這將提高模型對這些複雜結構的遵循。

### 常見格式結構描述
<a name="common-formatting-schemas"></a>

以下是常見格式結構描述的範例。

------
#### [ JSON ]

```
JSON_format = """Write your response following the JSON format below:

```json
{ 
"key1": "value1",
"key2": "value2",
key3: [{
"key3_1": "value_3_1 written in YYYY/MM/DD format",
"key3_2": "value_3_2 day of the week written in full form",
...}```
"""
```

------
#### [ XML ]

```
XML_format = """Write your response following the XML format below:

<output>
    <task>"task1"</task>
    <subtask>
    <task1_result> ( task 1 result )</task1_result>
    <task2_result> ( task 2 result )</task2_result>
    <task3_result> ( task 3 result )</task3_result>
    </subtask>
    <task>"task2"</task>
    <subtask>
    <task1_result> ( task 1 result )</task1_result>
    <task2_result> ( task 2 result )</task2_result>
    <task3_result> ( task 3 result )</task3_result>
    </subtask>
</output>

"""
```

------
#### [ Markdown ]

```
markdown_schema = """Write your response following the markdown format below:


## Introduction
( 2-3 line intro)

## Design Guidance 
(Bulleted list of design guidance)

## Step by Step Instructions on Execution
( Bulleted list of instructions with each with bold title.

## Conclusion
( conclusion )


"""
```

------

### 預填充助理內容
<a name="prompting-prefill"></a>

如果您以非原因模式產生結構化輸出，您可以透過預先填入助理內容來微調模型的回應。

預填充可在非基礎模式下改善輸出格式的一致性。它可讓您指示模型的動作、略過前言，以及強制執行特定輸出格式，例如 JSON 和 XML。例如，如果您使用 `{`或 預先填入助理內容````json`，該輸入會引導模型產生 JSON 物件，無需其他資訊。

**提示**  
如果您要明確地尋找擷取 JSON，則常見的模式是預先填入 ，````json`並在 上新增停止序列`````。這可確保模型輸出可透過程式設計方式剖析的 JSON 物件。

**Example 預填充助理內容**  
以下程式碼示範如何使用 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())
```

### 指定用於複雜結構描述的工具
<a name="prompting-tool-complex-schemas"></a>

另一種方法是使用工具來強制模型回應的特定結構描述，方法是在工具使用結構描述區段中包含 *pydantic JSON* 結構描述。您可以為提供的結構描述指定工具選擇，Amazon Nova 的回應將根據選取的工具進行結構化。若要進一步了解如何利用工具，請參閱[工具使用](https://docs.aws.amazon.com/nova/latest/userguide/tool-use.html)。

### 範例
<a name="structured-output-examples"></a>

#### 範例 1：新增輸出結構描述
<a name="add-output-schema-example"></a>

在輸出結構描述區段新增適當的結構描述，可讓模型偏好符合該結構描述。不過，模型輸出不是確定性的，並且可能與輸出結構描述不同。

------
#### [ Unspecific Prompt ]

使用者：

```
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.
```

助理：

```
```json
 [
 {
 "name": "Sony Alpha A7R IV",
 "brand": "Sony",
 "price": "Approximately $3,500",
 "summary": "The Sony Alpha A7R IV is renowned for its exceptional image quality, thanks to a 61-megapixel full-frame sensor. It also features 4K video recording and a robust build, making it a favorite among professional photographers and videographers."
 },
 {
 "name": "Canon EOS R5",
 "brand": "Canon",
 "price": "Approximately $3,900",
 "summary": "The Canon EOS R5 combines high-resolution imaging with advanced video capabilities. It houses a 45-megapixel sensor, 8K video recording, and impressive autofocus performance, appealing to both photography and filmmaking professionals."
 },
 {
 "name": "Nikon Z7 II",
 "brand": "Nikon",
 "price": "Approximately $2,800",
 "summary": "The Nikon Z7 II offers a 45.7-megapixel full-frame sensor and is praised for its high resolution and excellent dynamic range. It also supports 4K video recording and features a versatile Z-mount lens system, making it a strong contender in the full-frame market."
 },
 {
 "name": "Fujifilm GFX 100S",
 "brand": "Fujifilm",
 "price": "Approximately $7,000",
 "summary": "While not a traditional full-frame camera, the Fujifilm GFX 100S stands out with its 102-megapixel medium format sensor. It is lauded for its stunning detail and color reproduction, though it comes at a higher price point and is aimed at specialized users."
 }
 ]
 ```
```

------
#### [ Specific Prompt ]

使用者：

```
Provide details about the best selling full-frame cameras in past three years.
You MUST answer in JSON format only. Write your response following the the format below:
[{
“name”: “name goes here”,
“brand”: “brand goes here”,
“price”: “price goes here“,
"summary": "summary goes here"
}]
```

助理：

```
[
 {
 "name": "Nikon D850",
 "brand": "Nikon",
 "price": "$3,296.95",
 "summary": "The Nikon D850 is a professional full-frame DSLR camera known for its exceptional image quality, 45.7-megapixel resolution, 7 fps continuous shooting, and 4K video capabilities."
 },
 {
 "name": "Canon EOS 5D Mark IV",
 "brand": "Canon",
 "price": "$3,499.00",
 "summary": "The Canon EOS 5D Mark IV is a popular full-frame DSLR appreciated for its 30.4-megapixel sensor, 4K video recording, robust build quality, and reliable autofocus system."
 },
 {
 "name": "Sony A7R III",
 "brand": "Sony",
 "price": "$3,198.00",
 "summary": "The Sony A7R III is a high-resolution full-frame mirrorless camera renowned for its 42.4-megapixel sensor, excellent low-light performance, and versatile lens compatibility."
 },
 {
 "name": "Fujifilm GFX 100S",
 "brand": "Fujifilm",
 "price": "$5,999.99",
 "summary": "The Fujifilm GFX 100S is a medium format mirrorless camera that stands out for its 102-megapixel sensor, high dynamic range, and exceptional color reproduction."
 },
 {
 "name": "Sony A7 III",
 "brand": "Sony",
 "price": "$1,998.00",
 "summary": "The Sony A7 III is a full-frame mirrorless camera popular among enthusiasts and professionals for its 24.2-megapixel sensor, fast autofocus, and 4K video capabilities."
 }
 ]
```

------

#### 範例 2：預先填入模型回應
<a name="prefill-model-response-example"></a>

另一種方法是透過在助理的訊息中包含所需的初始文字，來預先填入模型的回應。在此情況下，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."
 }
 ]
 }
 ```
```

#### 範例 3：指定要使用的工具
<a name="specify-tool-use-example"></a>

除了使用結構化輸出的預填充技術之外，您還可以將 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"
            }
        }
    }
```

## 多語言使用案例
<a name="prompting-multilingual"></a>

Amazon Nova 2 模型已針對超過 200 種語言進行訓練，並針對 15 種語言進行最佳化。

**Topics**
+ [提示正確翻譯](#accurate-translations)
+ [強制執行一致的撰寫慣例](#consistent-writing-conventions)

### 提示正確翻譯
<a name="accurate-translations"></a>

若要利用此功能進行短格式翻譯 （幾個句子），您可以指示模型將文字翻譯為指定的目標語言。

**Example 翻譯提示**  

```
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}
```

### 強制執行一致的撰寫慣例
<a name="consistent-writing-conventions"></a>

在以字元為基礎的語言中，Amazon Nova 2 模型可能會利用來源語言的字元集。您可以使用下列提示來強制執行一致的輸出。

**Example 強制撰寫慣例**  

```
When translating, ensure to use the correct orthography / script / writing convention of the target language, not the source language's characters
```

## 工具呼叫
<a name="tool-calling-advanced-techniques"></a>

### 代理系統
<a name="agentic-systems"></a>

**Topics**
+ [設定正確的推論參數](#set-inference-parameters)
+ [考慮延遲要求](#consider-latency-requirements)
+ [使用工具呼叫指示的刻意措辭](#intentional-wording-tool-calling)
+ [利用「思考」命令](#leverage-thinking-commands)
+ [工具呼叫排序](#tool-call-ordering)
+ [建立品質工具結構描述](#designing-tool-schema)
+ [建立子代理程式](#create-sub-agents)
+ [使用工具進行多模態輸入](#use-tools-multimodal-inputs)
+ [後續步驟](#next-steps-best-practices)

#### 設定正確的推論參數
<a name="set-inference-parameters"></a>

工具呼叫需要模型中非常特定的結構化輸出，並使用下列推論參數來改善：
+ **非推理模式：**溫度：0.7 & Top P：0.9
+ **原因模式：**溫度：1 & Top P：0.9

#### 考慮延遲要求
<a name="consider-latency-requirements"></a>

**提示**  
Amazon Nova 2 模型能夠使用推理開啟和關閉的工具呼叫。不過，推理模式會對延遲產生重大影響。

對於延遲敏感應用程式，您應該針對推斷模式進行最佳化，並盡可能簡化必要的工具呼叫。將多步驟工作流程分割為離散步驟，以減少模型對調節不必要的參數的依賴。

#### 使用工具呼叫指示的刻意措辭
<a name="intentional-wording-tool-calling"></a>

**工具名稱：**在系統提示中參考工具在工具呼叫系統中很常見，以指示模型何時呼叫工具。當您在提示中參考工具時，我們建議您使用工具名稱，而不是 xml 或 pythonic 參考或範例。

##### 良好工具參考的範例
<a name="Example-of-a-good-tool-reference"></a>

```
Use the 'run_shell_command' tool for running shell commands
```

##### 錯誤工具參考的範例
<a name="Example-of-a-bad-tool-reference"></a>

```
Call run_shell_command() to run shell commands
```

#### 利用「思考」命令
<a name="leverage-thinking-commands"></a>

對於思考有利於工具呼叫的所有使用案例，我們建議您利用推理模式，而不是提示模型「在標籤中思考」或使用「思考」工具。

 Amazon Nova 2 模型經過廣泛的推理模式訓練，在推理模式用於思維鏈時會產生最佳結果。

#### 工具呼叫排序
<a name="tool-call-ordering"></a>

在可能需要同時使用內建工具和原生工具呼叫的使用案例中，模型會偏向先呼叫內建工具。

請勿指示模型在提示中採取不同的動作。反之，請設計您的工作流程以將此納入考量。

例如，如果您不希望模型使用內建工具，請勿將這些工具包含在工作流程中，讓模型不會偏離它們。

#### 建立品質工具結構描述
<a name="designing-tool-schema"></a>

工具結構描述是您可以提示設計有效工具呼叫系統的關鍵位置之一。不過，請務必考慮在工具結構描述中擷取的內容、如何以語意描述每個結構描述元素，以及系統提示如何在系統指示中參考工具和結構描述元素。

Amazon Nova 2 模型已針對工具結構描述中的簡潔描述進行最佳化。保持簡短。

**工具結構描述與系統提示準則：**

**包含在工具結構描述中：**
+ 核心功能：工具的功能 （建議 20-50 個字）
+ 參數規格：清除每個參數的描述 （每個參數大約 10 個字）
+ 預期的格式：資料類型 （例如列舉、整數、浮點數）、必要欄位和有效值範圍

**在系統提示中包含：**
+ 使用協同運作邏輯 （使用特定工具的時間和原因） 和業務規則 （條件式邏輯、排序需求和相依性） 專用`#Tool Usage`區段。
+ **錯誤處理策略：**新增 `#Error Handling and Troubleshooting`區段，其中包含如何回應失敗或非預期輸出的指示
+ **輸出格式：**新增如何呈現給使用者的詳細資訊

##### 範例
<a name="sample-example"></a>

```
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>
```

#### 建立子代理程式
<a name="create-sub-agents"></a>

當您遇到下列情況時，請考慮建立專用子代理程式，而不是具有許多工具的單一代理程式：
+ **工具計數超過 20：**大型工具集變得難以管理和增加選擇錯誤
+ **不同的功能網域：**工具自然叢集分為不同的類別 （例如資料擷取與處理與報告）
+ **複雜結構描述：**當參數深度超過 3-4 個層級時，或工具具有複雜的相互依存性
+ **對話長度：**工作流程定期超過 15-20 個回合可能受益於特殊的子代理程式
+ **效能降低：**如果您發現工具選擇的準確性降低或延遲增加

**提示**  
MCP 伺服器隨附您無法控制的工具和結構描述。僅包含工作流程完成必要任務所需的工具。

#### 使用工具進行多模態輸入
<a name="use-tools-multimodal-inputs"></a>

對於多模式任務，我們尚未觀察到利用結構化任務工具 （例如擷取或產生時間戳記） 來提高準確性。

反之，我們建議您檢閱提示多模式輸入區段中的相關區段，了解如何使用提供的範本成功提示模型。

#### 後續步驟
<a name="next-steps-best-practices"></a>
+ 如需多模式提示，請參閱 [提示多模態輸入](prompting-multimodal.md)。