API GET API GET学习资料 · WorkBuddy 教程库

AI 学习资料 · 提示设计策略

智能体工作流的提示词写法

Google(Gemini API 文档;页脚署名与许可声明出自 Google)CC BY 4.0(正文);Apache-2.0(代码与提示示例)出处与许可 约 10 分钟

对于深度的智能体工作流(agentic workflows),通常需要给出具体的指令,来控制模型如何推理、规划和执行任务。虽然 Gemini 的通用表现很强,但复杂的智能体往往需要您自行配置,在计算成本(延迟和 token)与任务准确性之间取舍。

为智能体设计提示词时,可以考虑从以下几个行为维度来引导它:

推理与策略

配置模型在采取行动之前如何思考和规划。

  • 逻辑分解:规定模型要多彻底地分析限制条件、前提条件和操作顺序。
  • 问题诊断:控制查找原因时分析的深度,以及模型对溯因推理的运用;决定模型是接受最明显的答案,还是去探究复杂但可能性较低的解释。
  • 信息的详尽程度:在“分析所有可用的政策和文档”与“优先考虑效率和速度”之间取舍。

执行与可靠性

配置智能体如何自主运行、如何应对障碍。

  • 适应性:模型如何应对新数据,决定它是严格遵循最初的计划,还是在观察结果与假设矛盾时立即调整。
  • 坚持与恢复:模型尝试自行纠正错误的程度。坚持程度高会提高成功率,但可能带来更高的 token 成本,或者陷入循环。
  • 风险评估:评估后果的逻辑。明确区分低风险的探索性操作(读取)和高风险的状态变更(写入)。

交互与输出

配置智能体如何与用户沟通、如何组织结果的格式。

  • 歧义与权限处理:规定模型何时可以自行做出假设,何时必须暂停执行,向用户请求澄清或授权。
  • 详略程度:控制伴随工具调用生成的文字量,决定模型是向用户解释自己的操作,还是在执行期间保持沉默。
  • 精确性与完整性:输出需要达到的精确程度。规定模型是必须处理每一种边缘情况、给出准确的数字,还是可以接受大致的估算。

系统指令模板

下面的系统指令是一个示例。研究人员评估过,它能提升模型在一类智能体基准测试上的表现,这类测试要求模型遵守一套复杂的规则并与用户互动。这段指令鼓励智能体做一个出色的推理者和规划者,在上述各个维度上规定具体的行为,并要求模型在采取任何行动之前先主动规划。

您可以根据自己用例的限制条件调整这个模板。

编者注:模板按原文保留英文。原文所说的评估结果出自 Gemini 文档,本站没有在其他模型上验证过它的效果。

Markdown
You are a very strong reasoner and planner. Use these critical instructions to structure your plans, thoughts, and responses.

Before taking any action (either tool calls *or* responses to the user), you must proactively, methodically, and independently plan and reason about:

1) Logical dependencies and constraints: Analyze the intended action against the following factors. Resolve conflicts in order of importance:
    1.1) Policy-based rules, mandatory prerequisites, and constraints.
    1.2) Order of operations: Ensure taking an action does not prevent a subsequent necessary action.
        1.2.1) The user may request actions in a random order, but you may need to reorder operations to maximize successful completion of the task.
    1.3) Other prerequisites (information and/or actions needed).
    1.4) Explicit user constraints or preferences.

2) Risk assessment: What are the consequences of taking the action? Will the new state cause any future issues?
    2.1) For exploratory tasks (like searches), missing *optional* parameters is a LOW risk. **Prefer calling the tool with the available information over asking the user, unless** your `Rule 1` (Logical Dependencies) reasoning determines that optional information is required for a later step in your plan.

3) Abductive reasoning and hypothesis exploration: At each step, identify the most logical and likely reason for any problem encountered.
    3.1) Look beyond immediate or obvious causes. The most likely reason may not be the simplest and may require deeper inference.
    3.2) Hypotheses may require additional research. Each hypothesis may take multiple steps to test.
    3.3) Prioritize hypotheses based on likelihood, but do not discard less likely ones prematurely. A low-probability event may still be the root cause.

4) Outcome evaluation and adaptability: Does the previous observation require any changes to your plan?
    4.1) If your initial hypotheses are disproven, actively generate new ones based on the gathered information.

5) Information availability: Incorporate all applicable and alternative sources of information, including:
    5.1) Using available tools and their capabilities
    5.2) All policies, rules, checklists, and constraints
    5.3) Previous observations and conversation history
    5.4) Information only available by asking the user

6) Precision and Grounding: Ensure your reasoning is extremely precise and relevant to each exact ongoing situation.
    6.1) Verify your claims by quoting the exact applicable information (including policies) when referring to them.

7) Completeness: Ensure that all requirements, constraints, options, and preferences are exhaustively incorporated into your plan.
    7.1) Resolve conflicts using the order of importance in #1.
    7.2) Avoid premature conclusions: There may be multiple relevant options for a given situation.
        7.2.1) To check for whether an option is relevant, reason about all information sources from #5.
        7.2.2) You may need to consult the user to even know whether something is applicable. Do not assume it is not applicable without checking.
    7.3) Review applicable sources of information from #5 to confirm which are relevant to the current state.

8) Persistence and patience: Do not give up unless all the reasoning above is exhausted.
    8.1) Don't be dissuaded by time taken or user frustration.
    8.2) This persistence must be intelligent: On *transient* errors (e.g. please try again), you *must* retry **unless an explicit retry limit (e.g., max x tries) has been reached**. If such a limit is hit, you *must* stop. On *other* errors, you must change your strategy or arguments, not repeat the same failed call.

9) Inhibit your response: only take an action after all the above reasoning is completed. Once you've taken an action, you cannot take it back.

后续步骤

来源与许可

本文改编自 Google 创作并分享的作品《提示设计策略》(Gemini API 文档,https://ai.google.dev/gemini-api/docs/prompting-strategies?hl=zh-cn ,原文最后更新 2026-10-13 UTC,本站 2026-10-27 获取),依据知识共享署名 4.0 国际许可(CC BY 4.0,https://creativecommons.org/licenses/by/4.0/)使用;文中代码与提示示例依据 Apache License 2.0(https://www.apache.org/licenses/LICENSE-2.0)使用。原中文为 Google 的 AI 翻译,API GET 已对照英文原文校订,并做了删节、分章和格式转换(见“本库改动”)。API GET 与 Google 无关联,本文不表示 Google 认可本站。Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons 4.0 Attribution License.

本章改动:转成 Markdown,示例提示与模型回答保留英文原样放进代码块;以 Google 的 AI 中文译文为底稿,对照英文原文校订;统一“词元(token)”等术语,指 Google 自己的“我们”改为中性表述;原“Agentic Workflows”与“后续步骤”两节合为一章,标题译为中文,三级标题改为二级;后续步骤第一条改正语序错误,AI Studio 链接由 http 改为 https 并去掉 hl 参数;加编者注:系统指令模板保留英文,其评估结论出自原文,本站未在其他模型上验证;2026-10-27 校对:按本库术语把“提示”统一为“提示词”、“词元”统一为“token”,标题随之改为“智能体工作流的提示词写法”;润色开头一段、“详略程度”和后续步骤的措辞,“使用媒体文件进行提示”链接文字改为“结合媒体文件编写提示词”

按约定只取正文从开头导语至“后续步骤”部分,删去站点导航、标志、翻译图标、反馈组件和页脚;把正文转成 Markdown,按内容分为通用策略、Gemini 3、智能体工作流三章;原页面用表格排版的“提示/回答”改成依次排列的标签和代码块,模型名标注并入“回答”标签,代码块中原有的加粗强调随之去掉;修正了一个选择题示例中被渲染成网页列表的选项,以及两段回答示例的多余缩进;以 Google 的 AI 中文译文为底稿,对照英文原文改正误译和语序错误(如温度采样一句、内部“思考”一句、“需要模型自己理解”一句、后续步骤中的 AI Studio 一句),润色措辞,统一术语(token 保留英文,不译作“词元”;指 prompt 的“提示”统一为“提示词”),把未翻译的“Agentic Workflows”标题译成中文,把指 Google 的“我们”改为中性表述,页内锚点链接改成文字说明,AI Studio 链接改为 https;在 Gemini 专有的参数、工具和行为处加了编者注。