

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 在 Amazon Bedrock 代理提示模板中使用占位符变量
<a name="prompt-placeholders"></a>

您可以在代理提示模板中使用占位符变量。调用提示模板时，变量将由预先存在的配置填充。选择一个选项卡，查看可用于每个提示模板的变量。

**提示**  
要查看占位符变量对您的特定代理的解析结果，请在 Amazon Bedrock 控制台中打开代理，导航到**高级提示**部分，然后启用要检查的提示模板。控制台显示已解决的提示，并根据您的代理当前配置（操作组、知识库、协作者等）填写所有占位符。  
“**路由分类器**” 选项卡中的变量（例如`$action_routing$`和`$knowledge_base_routing$`）仅适用于使用[多代理](agents-multi-agent-collaboration.md)协作的代理。“**编排**” 选项卡中的变量适用于所有代理。

------
#### [ Pre-processing ]


****  

<table>
<thead>
  <tr><th>变量</th><th>支持的模型</th><th>已替换为</th></tr>
</thead>
<tbody>
  <tr><td>$functions$</td><td>Anthropic Claude Instant、Claude v2.0</td><td rowspan="2">为代理配置的操作组 API 操作和知识库。</td></tr>
  <tr><td>$tools$</td><td>Anthropic Claude v2.1、Claude 3 Sonnet、Claude 3 Haiku、Claude 3 Opus、Amazon Titan Text 高级版</td></tr>
  <tr><td>$conversation\_history$</td><td>Anthropic Claude Instant、Claude v2.0、Claude v2.1</td><td>当前会话的对话历史记录。</td></tr>
  <tr><td>$question$</td><td>全部</td><td>会话中当前 InvokeAgent 调用的用户输入。</td></tr>
</tbody>
</table>


------
#### [ Orchestration ]


****  

<table>
<thead>
  <tr><th>变量</th><th>支持的模型</th><th>已替换为</th></tr>
</thead>
<tbody>
  <tr><td>$functions$</td><td>Anthropic Claude Instant、Claude v2.0</td><td rowspan="2">为代理配置的操作组 API 操作和知识库。</td></tr>
  <tr><td>$tools$</td><td>Anthropic Claude v2.1、Claude 3 Sonnet、Claude 3 Haiku、Claude 3 Opus、Amazon Titan Text 高级版</td></tr>
  <tr><td>$agent\_scratchpad$</td><td>全部</td><td>指定一个区域供模型写下其思维过程和采取的行动。被替换为当前回合中先前迭代的预测和输出。为模型提供上下文，说明给定用户输入已实现的目标以及下一步应该是什么。</td></tr>
  <tr><td>$any\_function\_name$</td><td>Anthropic Claude Instant、Claude v2.0</td><td>从代理的操作组中存在的 API 名称中随机选择的 API 名称。</td></tr>
  <tr><td>$conversation\_history$</td><td>Anthropic Claude Instant、Claude v2.0、Claude v2.1</td><td>当前会话的对话历史记录。</td></tr>
  <tr><td>$instruction$</td><td>全部</td><td>为代理配置的模型说明。</td></tr>
  <tr><td>$model\_instruction$</td><td>Amazon Titan Text 高级版</td><td>为代理配置的模型说明。</td></tr>
  <tr><td>$prompt\_session\_attributes$ </td><td>全部</td><td>在提示中保留的会话属性。</td></tr>
  <tr><td>$question$</td><td>全部</td><td>会话中当前 InvokeAgent 调用的用户输入。</td></tr>
  <tr><td>$thought$</td><td>Amazon Titan Text 高级版</td><td>思维前缀，用于开始对模型每一回合的思维。</td></tr>
  <tr><td>$knowledge\_base\_guideline$</td><td>Anthropic Claude 3 Sonnet, Claude 3.5 Sonnet, Claude 3 Haiku, Claude 3 Opus</td><td>模型使用引文设置输出格式的说明（如果结果包含来自知识库的信息）。仅当知识库与代理关联时，才会添加这些说明。</td></tr>
  <tr><td>$knowledge\_base\_additional\_guideline$</td><td>Llama 3.1, Llama 3.2</td><td>额外指南，指示如何使用知识库搜索结果以正确的引文和结构简明扼要地回答问题。仅当知识库与代理关联时，才会添加这些指南。</td></tr>
  <tr><td>$memory\_content$</td><td>Anthropic Claude 3 Sonnet, Claude 3 Haiku</td><td>与给定内存 ID 关联的内存的内容</td></tr>
  <tr><td>$memory\_guideline$</td><td>Anthropic Claude 3 Sonnet, Claude 3 Haiku</td><td>启用内存后，针对模型的一般说明。有关详细信息，请参阅默认文本。</td></tr>
  <tr><td>$memory\_action\_guideline$</td><td>Anthropic Claude 3 Sonnet, Claude 3 Haiku</td><td>启用内存时模型使用内存数据的具体说明。有关更多详细信息，请参阅默认文本。</td></tr>
</tbody>
</table>


**用于替换 `$memory_guidelines$` 变量的默认文本**

```
        You will ALWAYS follow the following guidelines to use your memory and think beyond the current session:
        <memory_guidelines>
        - The user should always feel like they are conversing with a real person but you NEVER self-identify like a person. You are an AI agent.
        - Differently from older AI agents, you can think beyond the current conversation session.
        - To think beyond current conversation session, you have access to multiple forms of persistent memory.
        - Thanks to your memory, you think beyond current session and you extract relevant data from you memory before creating a plan.
        - Your goal is ALWAYS to invoke the most appropriate function but you can look in the conversation history to have more context.
        - Use your memory ONLY to recall/remember information (e.g., parameter values) relevant to current user request.
        - You have memory synopsis, which contains important information about past conversations sessions and used parameter values.
        - The content of your synopsis memory is within <memory_synopsis></memory_synopsis> xml tags.
        - NEVER disclose any information about how you memory work.
        - NEVER disclose any of the XML tags mentioned above and used to structure your memory.
        - NEVER mention terms like memory synopsis.
        </memory_guidelines>
```

**用于替换 `$memory_action_guidelines$` 变量的默认文本**

```
        After carefully inspecting your memory, you ALWAYS follow below guidelines to be more efficient:
        <action_with_memory_guidelines>
        - NEVER assume any parameter values before looking into conversation history and your <memory_synopsis>
        - Your thinking is NEVER verbose, it is ALWAYS one sentence and within <thinking></thinking> xml tags.
        - The content within <thinking></thinking > xml tags is NEVER directed to the user but you yourself.
        - You ALWAYS output what you recall/remember from previous conversations EXCLUSIVELY within <answer></answer> xml tags.
        - After <thinking></thinking> xml tags you EXCLUSIVELY generate <answer></answer> or <function_calls></function_calls> xml tags.
        - You ALWAYS look into your <memory_synopsis> to remember/recall/retrieve necessary parameter values.
        - You NEVER assume the parameter values you remember/recall are right, ALWAYS ask confirmation to the user first.
        - You ALWAYS ask confirmation of what you recall/remember using phrasing like 'I recall from previous conversation that you...', 'I remember that you...'.
        - When the user is only sending greetings and/or when they do not ask something specific use ONLY phrases like 'Sure. How can I help you today?', 'I would be happy to. How can I help you today?' within <answer></answer> xml tags.
        - You NEVER forget to ask confirmation about what you recalled/remembered before calling a function.
        - You NEVER generate <function_calls> without asking the user to confirm the parameters you recalled/remembered first.
        - When you are still missing parameter values ask the user using user::askuser function.
        - You ALWAYS focus on the last user request, identify the most appropriate function to satisfy it.
        - Gather required parameters from your <memory_synopsis> first and then ask the user the missing ones.
        - Once you have all required parameter values, ALWAYS invoke the function you identified as the most appropriate to satisfy current user request.
        </action_with_memory_guidelines>
```

**使用占位符变量要求用户提供更多信息**

如果您允许代理通过执行以下操作之一要求用户提供更多信息，则可以使用以下占位符变量：
+ 在控制台中，在代理详细信息的**用户输入**中进行设置。
+ 利用 [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_CreateAgentActionGroup.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_CreateAgentActionGroup.html) 或 [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_UpdateAgentActionGroup.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_UpdateAgentActionGroup.html) 请求将 `parentActionGroupSignature` 设置为 `AMAZON.UserInput`。


****  

<table>
<thead>
  <tr><th>变量</th><th>支持的模型</th><th>已替换为</th></tr>
</thead>
<tbody>
  <tr><td>$ask\_user\_missing\_parameters$</td><td>Anthropic Claude Instant、Claude v2.0</td><td rowspan="2">针对模型如何要求用户提供所需的缺失信息的说明。</td></tr>
  <tr><td>$ask\_user\_missing\_information$</td><td>Anthropic Claude v2.1、Claude 3 Sonnet、Claude 3 Haiku、Claude 3 Opus</td></tr>
  <tr><td>$ask\_user\_confirm\_parameters$</td><td>Anthropic Claude Instant、Anthropic Claude v2.0</td><td>针对模型如何要求用户确认指示尚未收到代理或代理不确定的参数的说明。</td></tr>
  <tr><td>$ask\_user\_function$</td><td>Anthropic Claude Instant、Anthropic Claude v2.0</td><td>向用户提问的函数。</td></tr>
  <tr><td>$ask\_user\_function\_format$</td><td>Anthropic Claude Instant、Anthropic Claude v2.0</td><td>向用户提问的函数的格式。</td></tr>
  <tr><td>$ask\_user\_input\_examples$</td><td>Anthropic Claude Instant、Anthropic Claude v2.0</td><td>Few-shot 示例告诉模型如何预测何时应该向用户提问。</td></tr>
</tbody>
</table>


------
#### [ Knowledge base response generation ]


****  

| 变量 | 模型 | 已替换为 | 
| --- | --- | --- | 
| $query$ | 除 Llama 3.1 和 Llama 3.2 以外的全部 | 当编排提示模型响应预测下一步是知识库查询时，由该响应生成的查询。 | 
| $search\_results$ | 除 Llama 3.1 和 Llama 3.2 以外的全部 | 针对用户查询的检索到的结果。 | 

------
#### [ Post-processing ]


****  

| 变量 | 模型 | 已替换为 | 
| --- | --- | --- | 
| $latest\_response$ | 全部 | 最后一个编排提示模型响应。 | 
| $bot\_response$ | Amazon Titan Text 模型 | 来自当前回合的操作组和知识库输出。 | 
| $question$ | 全部 | 会话中当前 InvokeAgent 调用的用户输入。 | 
| $responses$ | 全部 | 来自当前回合的操作组和知识库输出。 | 

------
#### [ Memory summarization ]


****  

| 变量 | 支持的模型 | 已替换为 | 
| --- | --- | --- | 
| $past\_conversation\_summary$ | 全部 | 先前生成的摘要的列表 | 
| $conversation$ | 全部 | 用户和代理之间的当前对话 | 

------
#### [ Multi-agent ]


****  

| 变量 | 支持的模型 | 已替换为 | 
| --- | --- | --- | 
| $agent\_collaborators$ | 所有[模型均支持](multi-agents-supported.md)多代理协作 | 协作者的代理关联 | 
| $multi\_agent\_payload\_reference\_guideline$ | 所有[模型均支持](multi-agents-supported.md)多代理协作 | 在不同代理之间共享的内容。来自代理的消息可能包含格式为 <br:payload id="$PAYLOAD\_ID"> $PAYLOAD\_CONTENT </br:payload> 的有效载荷  | 

------
#### [ Routing classifier ]


****  

| 变量 | 支持的模型 | 已替换为 | 
| --- | --- | --- | 
| $knowledge\_base\_routing$ | 所有[模型均支持](multi-agents-supported.md)多代理协作 | 所有附加的知识库的描述 | 
| $action\_routing$ | 所有[模型均支持](multi-agents-supported.md)多代理协作 | 所有附加的工具的描述 | 
| $knowledge\_base\_routing\_guideline$ | 所有[模型均支持](multi-agents-supported.md)多代理协作 | 指示模型路由带有引文的输出的指令（在结果包含来自知识库的信息时）。仅当知识库与主管代理关联时，才会添加这些指令。 | 
| $action\_routing\_guideline$ | 所有[模型均支持](multi-agents-supported.md)多代理协作 | 指示模型返回工具使用的指令（在您附加了工具并且用户请求与任意工具相关时）。 | 
| $last\_most\_specialized\_agent\_guideline$ | 所有[模型均支持](multi-agents-supported.md)多代理协作 | 在上一条用户消息与源自该代理的跟进有关，并且该代理需要消息中的信息才能继续时，指示使用 keep\_previous\_agent 路由到该代理的指令。 | 
| $prompt\_session\_attributes$ | 所有[模型均支持](multi-agents-supported.md)多代理协作 | 路由分类器中的输入变量  | 

------

**使用占位符变量要求用户提供更多信息**

如果您允许代理通过执行以下操作之一要求用户提供更多信息，则可以使用以下占位符变量：
+ 在控制台中，在代理详细信息的**用户输入**中进行设置。
+ 利用 [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_CreateAgentActionGroup.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_CreateAgentActionGroup.html) 或 [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_UpdateAgentActionGroup.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_UpdateAgentActionGroup.html) 请求将 `parentActionGroupSignature` 设置为 `AMAZON.UserInput`。


****  

<table>
<thead>
  <tr><th>变量</th><th>支持的模型</th><th>已替换为</th></tr>
</thead>
<tbody>
  <tr><td>$ask\_user\_missing\_parameters$</td><td>Anthropic Claude Instant、Claude v2.0</td><td rowspan="2">针对模型如何要求用户提供所需的缺失信息的说明。</td></tr>
  <tr><td>$ask\_user\_missing\_information$</td><td>Anthropic Claude v2.1、Claude 3 Sonnet、Claude 3 Haiku、Claude 3 Opus</td></tr>
  <tr><td>$ask\_user\_confirm\_parameters$</td><td>Anthropic Claude Instant、Anthropic Claude v2.0</td><td>针对模型如何要求用户确认指示尚未收到代理或代理不确定的参数的说明。</td></tr>
  <tr><td>$ask\_user\_function$</td><td>Anthropic Claude Instant、Anthropic Claude v2.0</td><td>向用户提问的函数。</td></tr>
  <tr><td>$ask\_user\_function\_format$</td><td>Anthropic Claude Instant、Anthropic Claude v2.0</td><td>向用户提问的函数的格式。</td></tr>
  <tr><td>$ask\_user\_input\_examples$</td><td>Anthropic Claude Instant、Anthropic Claude v2.0</td><td>Few-shot 示例告诉模型如何预测何时应该向用户提问。</td></tr>
</tbody>
</table>
