View a markdown version of this page

进阶提示技巧 - Amazon Nova

进阶提示技巧

以下章节提供了进阶指导,帮助您了解如何提高提示质量以及利用扩展思考等关键功能。

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} STARTDOCUMENT {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 模型无需通过提示词直接要求引文作为依据文本,而是内置了 Web Grounding 工具。启用后,Amazon Nova 2 模型将直接查询 Web 和 Amazon 的知识图谱,并在最终响应中附带引文依据。

要详细了解如何利用 Amazon Nova Web Grounding,请参阅《Amazon Nova Web Grounding 用户指南》。

为确保输出格式的一致性和结构化,您可以使用结构化输出,包括 XML、JSON、Markdown 等格式,或使用工具使用功能。

  • 这种方法可使下游系统更有效地理解和解析模型生成的输出。

  • 向模型提供明确指令,生成的回复将以符合预定义架构的方式呈现。

例如,若下游解析器希望 JSON 对象的键名遵循特定命名约定,您应该在提示末尾指定响应架构。此外,如果希望回复以 JSON 格式呈现,且不带任何前言文本,则须相应地向模型提供指令。即明确写明:“请仅输出 JSON 内容,切勿添加任何前置说明”,保证输出格式纯净。

提示
  • 我们发现,将数据格式要求直接定义在架构本身中,模型的遵守效果最佳,优于通过示例进行指定(例如将日期格式设为 YYYY/MM/DD)。

  • 对于最多包含 10 个键的简单 JSON 输出,可直接使用下方提供的架构。对于更复杂的架构,建议通过工具来定义架构。工具使用采用了一种名为“约束解码”的技术,可提升模型对这类复杂架构的遵从度。

常见格式架构

以下是常见格式架构的示例。

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 ) """

预填充助手内容

如果您在非推理模式下生成结构化输出,则可以通过预填充助手内容来引导模型的响应。

预填充可以提高非推理模式下输出格式的一致性。这有助于引导模型的行为,省略前置说明,并强制输出 JSON、XML 等指定格式。例如,若使用 {```json 预填充助手内容,则该输入可引导模型直接生成不带额外信息的 JSON 对象。

提示

若需明确提取 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 就会根据所选工具的架构生成回复。如需了解关于如何使用工具的详情,请参阅工具使用

示例

向“输出架构”部分添加恰当的架构可引导模型遵循该架构生成内容。然而,模型输出具有不确定性,可能与输出架构存在差异。

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." } ]

第二种方法是在助手消息中包含所需的初始文本,从而预填充模型的回复。在这种情况下,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

代理系统

设置正确的推理参数

工具调用要求模型输出高度特定的结构化内容,通过以下推理参数可提升效果:

  • 非推理模式:Temperature:0.7;TopP:0.9

  • 推理模式:Temperature:1;TopP: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 模型针对推理模式进行了大量训练,在推理模式下执行思维链任务可获得最优效果。

工具调用顺序

在需要同时使用内置工具与原生工具调用的场景中,模型会优先调用内置工具。

请勿在提示词中指示模型改变行为,而应在工作流设计中对此加以考量。

例如,若不希望模型使用内置工具,只需将其排除在工作流之外,即可避免模型倾向于调用此类工具。

构建高质量工具架构

工具架构是通过提示工程实现高效工具调用系统的核心环节之一。设计时需重点关注:架构本身应包含哪些内容、各元素的语义描述方式,以及系统提示在指令中如何引用工具与架构元素。

Amazon Nova 2 模型针对工具架构的简洁描述进行了专项优化。请保持描述简短精炼。

工具架构与系统提示指南:

工具架构应包含以下内容:

  • 核心功能:工具实现的功能(建议 20 – 50 个字)

  • 参数规范:各参数清晰描述(每个参数约 10 个字)

  • 格式要求:数据类型(如枚举、整数、浮点数)、必填字段及有效值范围

系统提示应包含以下内容:

  • 专门设立 #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 服务器自带部分无法自主管控的工具与架构,仅需纳入工作流执行任务所需的必要工具即可。

多模态输入的工具使用

在多模态任务中,使用工具处理结构化任务(如信息提取、时间戳生成)并未提升准确率。

建议查阅“多模态输入提示”章节中的相关内容,参考提供的模板编写有效提示词。

后续步骤