实用提示:您的代理可以自行修改提示词。具体方法如下。
《实用指南》操作流程详解:您的代理可自行修复提示词,具体方法如下。适用于采用该模式的团队的合同、校验项及可直接插入的代码模块。
本指南将逐步构建从原始材料到可运行系统的完整流程,主题为“您的智能体能够自行修复提示词——具体方法如下”。重点在于可操作的步骤、明确的检查点,以及无需猜测意图即可直接放入代码库的代码。在概览阶段,应在修改代码之前明确输入参数、各步骤的负责人以及完成标准。操作人员应能够从已知的检查点重新运行相应步骤,而无需推测隐藏状态。除了功能结果外,还需记录执行时间以及令牌或查询成本。提前了解成本情况,可避免在从演示环境过渡到共享环境时出现意外费用。
教会智能体从自身错误中学习,从而打造更优秀的版本
在编写“教会你的智能体进行分阶段处理”的代码时,首先需列出合同条款:所需的输入参数、成功信号以及部分失败时的处理方式。这样的检查清单能确保后续的代码修改不会偏离原定计划。 应将配置信息与应用程序代码分开。环境文件、密钥存储以及功能开关应集中存放于一个位置,这样操作人员无需查看整个系统结构即可进行审计。 缓存系统中稳定的指令和工具架构。重复发送相同的开头信息是导致资源浪费的常见原因。
智能体
在处理“代理阶段”时,首先写下合同规范:所需的输入参数、成功信号以及部分失败时的处理方式。这样的检查清单能确保后续的代码修改保持一致性。 同时记录正常流程和故障恢复流程。重试机制、人工审核环节以及死信处理都是产品本身的组成部分,而非后续需要补充的功能。 缓存稳定的系统指令和工具架构。重复发送相同的开头信息是导致资源浪费的常见原因。
You are a helpful company information assistant.
You have the following knowledge about company policies:
- PTO: 20 days per year, accrued monthly. Up to 5 unused days roll over.
- Sick leave: 10 days per year, does not roll over.
- Remote work: Up to 3 days per week with manager approval.
- Benefits: The company offers competitive benefits.
Answer questions using only the information above. If a question is about
a topic not listed above, tell the user you do not have that information
and suggest they contact HR.
构建模块
在“构建基础模块”阶段,首先需明确合同条款:所需的输入参数、成功信号以及部分失败时的处理方式。这份清单能确保后续的代码修改保持透明可追溯。 相比冗长的脚本,应优先选择小型且易于测试的单元。当某个步骤失败时,故障应指向单一责任模块,而非复杂的流程链。 缓存系统中稳定的指令和工具结构。重复发送相同的开头信息是导致资源浪费的常见原因。 在“构建基础模块”阶段,首先需明确合同条款:所需的输入参数、成功信号以及部分失败时的处理方式。这份清单能确保后续的代码修改保持透明可追溯。 在功能结果旁记录执行时间以及令牌或查询成本。提前了解成本情况,可避免在从演示环境过渡到共享环境时出现意外费用。
改进循环
将改进循环阶段视为可度量的对象来处理效果最佳。在扩大范围之前,先记录一份优秀的案例、一个故障实例以及回滚说明。 将配置置于应用程序代码之外。环境文件、密钥存储和功能开关应集中存放,这样操作人员无需查看整个系统结构即可进行审计。 为每轮及每次会话设定预算额度。智能工具往往会大量消耗上下文资源,设置上限可避免演示过程变成意外的费用账单。
git clone https://github.com/GoogleCloudPlatform/BigQuery-Agent-Analytics-SDK.git
cd examples/agent_improvement_cycle
export PROJECT_ID=<your-project-id>
./setup.sh
./run_cycle.sh # single cycle, 10 questions, ~3-4 min
./run_cycle.sh --auto --cycles 3 --traffic-count 100
逐步操作
将分步执行流程视为可度量的对象来处理效果最佳。在扩大范围之前,先记录一个理想案例、一个失败案例以及回滚说明。同时记录正常流程与恢复流程的细节。重试机制、人工审核环节以及错误处理方式都是产品本身的一部分,而非后续需要补充的内容。为每轮对话和每次会话设定token预算。智能工具会大量消耗上下文资源,设置上限可避免演示过程变成意外的费用账单。
飞行前准备:运行理想评估集
将“飞行前测试——黄金阶段”视为可度量的对象来处理时,其效果最佳。在扩大范围之前,需记录一份理想的测试结果、一个故障案例以及回滚说明。 相较于庞大的脚本,应优先选择小型且可测试的单元。当某个步骤出现故障时,故障应指向单一责任模块,而非复杂的流程链。 需为每轮操作和每次会话设定预算额度。智能工具往往会大量消耗上下文资源,设置上限可避免演示过程变成意外的费用账单。 将“飞行前测试——黄金阶段”视为可度量的对象来处理时,其效果最佳。在扩大范围之前,需记录一份理想的测试结果、一个故障案例以及回滚说明。 除了功能结果外,还需记录执行时间以及Token或查询成本。提前了解成本情况,可避免在从演示环境过渡到共享环境时出现意外账单。
{
"eval_cases": [
{"id": "pto_balance", "question": "How many PTO days do I get per year?",
"category": "pto", "expected_tool": "lookup_company_policy"},
{"id": "sick_leave_days", "question": "How many sick days do I have?",
"category": "sick_leave", "expected_tool": "lookup_company_policy"},
{"id": "remote_work_days","question": "How many days can I work from home?",
"category": "remote_work","expected_tool": "lookup_company_policy"}
]
}
▶ PRE-FLIGHT: Verifying golden eval set passes with current prompt
PASS: pto_balance
Answer: You receive 20 PTO days per year, accrued monthly.
Up to 5 unused days can roll over.
Tools called: lookup_company_policy
PASS: sick_leave_days
Answer: You have 10 sick days per year. They do not roll over.
Tools called: lookup_company_policy
PASS: remote_work_days
Answer: You can work from home up to 3 days per week
with manager approval.
Tools called: lookup_company_policy
All cases pass.
步骤1–2:生成合成流量并通过代理处理
在“生成”阶段,应在修改代码之前明确输入参数、该步骤的负责人以及结束标准。操作人员应能够从已知的检查点重新运行该步骤,而无需猜测隐藏状态。 配置信息应置于应用程序代码之外。环境文件、密钥存储和功能标志应集中存放于一个位置,以便操作人员无需查看整个流程即可进行审计。 当下一步是代码或工具调用时,优先使用具有架构验证的结构化输出,而非自由形式的文本。
▶ STEP 1/5: GENERATE SYNTHETIC TRAFFIC
Goal: Produce diverse user questions that differ from the golden eval set
Method: Gemini generates 100 questions
...
Sample questions:
- How many PTO days do I earn per month?
- What's the maximum number of PTO days I can roll over into the next year?
- I want to take a full week off for vacation. What is the advance notice required?
...
▶ STEP 2/5: RUN TRAFFIC THROUGH AGENT
Goal: Send questions to the agent, log every session to BigQuery
...
[62/100] traffic_expenses_window_to_submit: What is the timeframe for submitting expense reports?
-> Business expenses must be submitted within 30 days.
[64/100] traffic_benefits_health_company_contribution: What percentage of my health insurance premium does the company cover?
-> The company covers 80% of health insurance premiums for employees.
[65/100] traffic_benefits_dental_coverage: What does the dental insurance plan cover?
-> I do not have specific information about what the dental insurance plan covers. The company offers competitive benefits, but details about specific plans like dental insurance are not something I have access to. Please contact HR for more information on dental insurance coverage.
[67/100] traffic_benefits_401k_match: What is the company's 401k match policy?
-> I do not have information about the company's 401k match policy. Please contact HR for details on this topic.
[68/100] traffic_benefits_401k_vesting: How long do I need to be employed to be fully vested in the 401k match?
-> I do not have information about 401k vesting. Please contact HR for details regarding the 401k match and vesting schedule.
[69/100] traffic_benefits_parental_leave_primary: What is the parental leave duration for a primary caregiver?
-> I do not have information about parental leave. Please contact HR for details on this policy.
[66/100] traffic_benefits_vision_frames: How often can I get new frames under the vision plan?
-> I do not have information about the vision plan or how often you can get new frames. Please contact HR for details about the vision plan.
[60/100] traffic_expenses_receipt_required_over_x: Expenses over what amount require a receipt?
-> I do not have information about the company's expense policy. Please contact HR for details.
[89/100] traffic_holidays_next_company_holiday: When is the next company holiday?
-> I do not have information about company holidays. Please contact HR for details.
...
Answer questions using only the information above. If a question is about
a topic not listed above, tell the user you do not have that information
and suggest they contact HR.
步骤3:评估质量
在第三步“评估质量”阶段,应在修改代码之前明确输入内容、该步骤的负责人以及结束标准。操作人员应能够从已知的检查点重新运行该步骤,而无需猜测隐藏状态。 需同时记录正常流程和异常恢复流程。重试机制、人工审核环节以及错误处理都是产品本身的组成部分,而非后续需要补充的功能。 当下一步操作为代码编写或工具调用时,应优先使用具有结构化格式且经过模式验证的输出,而非自由形式的文字描述。
QUALITY SUMMARY
Total sessions evaluated : 100
Meaningful : 64
Partial : 1
Unhelpful : 35
Unhelpful rate : 35.0%
[response_usefulness]
HELPFUL : 64 ( 64.0%) ################################
NOT HELPFUL : 35 ( 35.0%) #################
PARTIAL : 1 ( 1.0%)
[task_grounding]
GROUNDED : 90 ( 90.0%) #############################################
NOT GROUNDED : 9 ( 9.0%) ####
NO TOOL NEEDED : 1 ( 1.0%)
UNHELPFUL Sessions (showing 10 of 35)
Session: 52282245-d2a4-4998-9ad9-4373612019e8 → company_info_agent
Question: For what amount do I need to submit a receipt for expenses?
Response: "I do not have information about the specific amount for which you need to submit a receipt for expenses. Please contact HR for details on the expense policy."
Usefulness: ❌ NOT HELPFUL
Reason: The agent explicitly states it does not have the requested information and directs the user elsewhere, thus not providing a substantive answer to the user's question.
Grounding: ❌ NOT GROUNDED
Reason: The agent's response indicates a lack of specific information and directs the user to HR, suggesting it did not retrieve specific data from a tool to answer the question. The response is a generic LLM statement rather than tool-derived data.
Session: 3821b327-43d8-47c6-b922-dd8d7988c366 → company_info_agent
Question: After how many days of illness is a doctor's note mandatory?
Response: "I do not have information about when a doctor's note is mandatory for illness. Please contact HR for this information."
Usefulness: ❌ NOT HELPFUL
Reason: The agent explicitly states it does not have the requested information and directs the user elsewhere, failing to answer the user's question substantively.
Grounding: ❌ NOT GROUNDED
Reason: The agent's response indicates a lack of information, meaning it was not grounded in actual data retrieved from its tools. The question required tool usage, but no relevant data was found or presented.
...
Metric V1 Budget Status
----------- ----------- ----------- ------
Avg latency 1482.3 ms 10000 ms PASS
Total tokens 811.4 tokens 50000 tokens PASS
Turn count 1 turns 10 turns PASS
Tool error rate 0.0 rate 0.1 rate PASS
第四步:优化提示词
在“第4步:改进”阶段,修改代码之前需明确输入参数、该步骤的负责人以及结束标准。操作人员应能够从已知的检查点重新运行该步骤,而无需猜测隐藏状态。 相较于冗长的脚本,更应采用小型、可测试的单元。当某一步骤失败时,故障原因应能指向单一责任模块,而非复杂的流程链。 如果后续步骤是代码调用或工具调用,应优先使用具有结构化格式且经过模式验证的输出,而非自由形式的文字描述。 在“第4步:改进”阶段,修改代码之前需明确输入参数、该步骤的负责人以及结束标准。操作人员应能够从已知的检查点重新运行该步骤,而无需猜测隐藏状态。 除了功能结果外,还需记录执行时间以及令牌或查询成本。提前了解成本情况,可避免在流程从演示环境转向共享环境时出现意外费用。
Extracted 12 failed cases, added 12 new to golden set (15 total).
Q: As a primary caregiver, how many weeks of parental leave am I eligible for?
Agent: I do not have information about parental leave. Contact HR.
Teacher: As a primary caregiver, you are eligible for 16 weeks of paid parental leave.
Q: What percentage of my contributions does the company match for 401k?
Agent: I do not have information about 401k matching. Contact HR.
Teacher: The company matches 4% of your contributions to the 401k. Fully vested after 1 year.
Q: When is the next company holiday?
Agent: I do not have information about company holidays. Contact HR.
Teacher: The next company holiday is May 25, 2026.
Q: What are the core hours I need to be available if I'm working remotely?
Agent: I do not have information about core hours. Contact HR.
Teacher: Core collaboration hours for remote employees are 10am-3pm in your local timezone.
Calling Vertex AI Prompt Optimizer with 12 ground truth examples...
(The optimizer is a server-side job -- typically 2-4 minutes.)
... still optimizing (15s elapsed)
... still optimizing (30s elapsed)
... still optimizing (45s elapsed)
Optimizer returned a candidate prompt.
PASS: pto_balance
Question: How many PTO days do I get per year?
Answer: You get 20 PTO days per year, which are accrued monthly...
Tools called: lookup_company_policy | Expected: lookup_company_policy
PASS: extracted_as_a_primary_caregiver_how_many_weeks_of
Question: As a primary caregiver, how many weeks of parental leave am I eligible for?
Answer: As a primary caregiver, you are eligible for 16 weeks of paid parental leave.
Tools called: lookup_company_policy | Expected: lookup_company_policy
PASS: extracted_what_percentage_of_my_contributions_does
Question: What percentage of my contributions does the company match for 401k?
Answer: The company matches 4% of your 401(k) contributions, and you are fully vested after 1 year of employment.
Tools called: lookup_company_policy | Expected: lookup_company_policy
PASS: extracted_what_does_the_dental_insurance_plan_cove
Question: What does the dental insurance plan cover?
Answer: The dental insurance plan covers full preventive care and 80% for major procedures.
Tools called: lookup_company_policy | Expected: lookup_company_policy
PASS: extracted_when_is_the_next_company_holiday
Question: When is the next company holiday?
Answer: The next company holiday is Memorial Day on May 25, 2026.
Tools called: lookup_company_policy, get_current_date | Expected: lookup_company_policy
...
15/15 passed
Prompt: V1 -> V2
Golden set: 3 -> 15 cases
第5步:衡量改进效果
在执行第5步“衡量改进效果”时,首先列出相关要求:所需输入、成功标志以及部分失败时的处理方式。这样的清单能确保后续的代码修改保持透明。 应将配置信息与应用程序代码分开存放。环境文件、密钥存储以及功能开关应集中管理,以便操作人员无需查看全部内容即可进行审计。 缓存系统中稳定的指令和工具结构。重复发送相同的开头信息是导致资源浪费的常见原因。
[44/100] traffic_expenses_004: I booked a flight for $600 for a business trip. Do I need pre-approval?
-> Travel expenses over $500 require pre-approval from your manager. Since your flight is $600, you will need pre-approval.
[80/100] traffic_benefits_020: If I leave the company after 6 months, will I get to keep the 401k match?
-> No, the company 401(k) match is fully vested after 1 year of employment. If you leave after 6 months, you will not get to keep the 401k match.
[84/100] traffic_holidays_004: Is the day after Thanksgiving a paid holiday?
-> Yes, the day after Thanksgiving is a paid holiday.
[19/100] traffic_sick_004: I was sick for two days; do I need to provide any documentation?
-> Employees receive 10 sick days per year. A doctor's note is required for absences longer than 3 consecutive days. Since you were sick for two days, you do not need to provide any documentation.
QUALITY SUMMARY
Total sessions evaluated : 100
Meaningful : 99
Partial : 1
Unhelpful : 0
Unhelpful rate : 0.0%
[response_usefulness]
HELPFUL : 99 ( 99.0%) #################################################
PARTIAL : 1 ( 1.0%)
[task_grounding]
GROUNDED : 99 (100.0%) ##################################################
Session: 4e0ea11d-d4dc-4a59-b337-30415a595c90 → company_info_agent
Question: If I'm sick for more than 3 days, what kind of doctor's note is required?
Response: "If you are sick for more than 3 consecutive days, a doctor's note is required."
Usefulness: PARTIAL
Reason: The response confirms a doctor's note is required but does not specify
the 'kind' of note, which was part of the user's question.
Grounding: GROUNDED
Reason: The agent's response directly reflects the information retrieved
from the 'lookup_company_policy' tool.
CYCLE 1 RESULTS
Before (V1): 64.0% meaningful (64/100 sessions)
After (V2): 99.0% meaningful (98/99 sessions)
Quality 99.0% meets threshold (95%) -- stopping auto-continue.
DONE (total wall time: 12m 39s)
Prompt version: V2
Golden eval set: 15 cases
Metric V1 V2 Budget Status
----------- ----------- ----------- ----------- ------
Avg latency (v) 1482.3 ms 1088.4 ms 10000 ms PASS
Total tokens (^) 811.4 tokens 1339.7 tokens 50000 tokens PASS
Turn count (=) 1 turns 1 turns 10 turns PASS
Tool error (=) 0.0 rate 0.0 rate 0.1 rate PASS
V2提示语
在处理 V2 提示阶段时,首先写下相关规范:所需的输入参数、成功标志以及部分失败时的处理方式。这样的检查清单能确保后续的代码修改保持一致性。 同时记录正常流程和异常恢复流程。重试机制、人工审核环节以及错误消息处理都是产品本身的组成部分,而非后续需要补充的功能。 缓存稳定的系统指令和工具结构。重复发送相同的开头信息是导致资源浪费的常见原因。
You are a helpful company information assistant. Your primary function
is to answer employee questions about company policies by using the
available tools.
Core Directives:
1. Tool-First Approach: For EVERY user question, your first and only
action should be to use one of the provided tools to find the answer.
2. No Answering from Memory: Do not use any general knowledge. The
tools are the only source of truth.
3. Mandatory Tool Use: You MUST call the appropriate tool to answer the
question. Do not state that you don't have the information or direct
the user to HR for topics that the tools can handle.
4. Topic Inference: Carefully analyze the user's prompt to determine
the correct topic parameter for the lookup_company_policy tool.
The user's language may not be an exact match for the available
topics (e.g., 'parental leave' or '401k' should be mapped to
the 'benefits' topic).
AVAILABLE TOOLS:
- lookup_company_policy(topic: str)
- Looks up a company policy by topic.
- topic: The policy topic to look up. Must be one of: pto, sick_leave,
remote_work, expenses, benefits, holidays.
- get_current_date()
- Gets the current date.
Your goal is to successfully call the correct tool with the correct
parameters based on the user's question.
该循环对提示设计的启示
在完成“循环所教授的内容”这一阶段时,首先需列出规范:所需的输入参数、成功信号以及部分失败时的处理方式。这样的清单能确保后续的代码修改保持透明可溯。 建议使用小型、可测试的单元,而非庞大的脚本。当某个步骤失败时,故障应指向单一责任点,而非复杂的流程链。 缓存系统中稳定的指令和工具结构。重复发送相同的开头信息是导致资源浪费的常见原因。 在完成“循环所教授的内容”这一阶段时,首先需列出规范:所需的输入参数、成功信号以及部分失败时的处理方式。这样的清单能确保后续的代码修改保持透明可溯。 在功能结果旁记录执行时间以及令牌或查询成本。提前了解成本情况,可避免在从演示环境过渡到共享环境时出现意外费用。
自行运行
将“自行运行”阶段视为可度量的基准,效果最佳。在扩大范围之前,先记录一个成功的案例、一个失败案例以及回滚说明。 将配置置于应用程序代码之外。环境文件、密钥存储和功能开关应集中存放,以便操作人员无需查看全部内容即可进行审计。 为每轮及每次会话设定令牌预算。智能工具会大量消耗上下文资源,设置上限可避免演示过程突然产生额外费用。
git clone https://github.com/GoogleCloudPlatform/BigQuery-Agent-Analytics-SDK.git
cd examples/agent_improvement_cycle
export PROJECT_ID=<your-project-id>
./setup.sh
./run_cycle.sh
./reset.sh
核心要点
将“提取要点”阶段视为可度量的工作面时,其效果最佳。在扩大范围之前,需记录一份理想的对话文本、一个故障案例以及回滚说明。
操作检查清单
将“操作检查清单”阶段视为可度量的工作面时,其效果最佳。在扩大范围之前,需记录一份理想的对话文本、一个故障案例以及回滚说明。
应将此阶段视为输入与已验证输出之间的契约。为相关成果命名,明确成功标准,杜绝默许的半完成状态。
每轮及每次会话的预算令牌数量。智能工具会大量消耗上下文资源,设置上限可避免演示变成意外账单。
对于涉及资金支出或修改生产数据的操作,必须经过人工审批。编译时的连接方式并不等同于业务功能的完整性。
编写简短的操作手册:包括如何轮换密钥、如何清空队列以及如何回滚上一次的导入操作。
同时记录正常流程和故障恢复流程。重试机制、人工审核环节以及死信处理都是产品不可或缺的部分,而非后续需要补充的功能。
在推广该技术栈之前,应冻结版本、为关键流程保存标准操作记录,并确认回滚步骤。共享环境需要设置速率限制、进行租户检查,同时明确密钥轮换的负责人。与其追求花哨的一次性演示,不如注重扎实的可靠性。
f7bfa970ccb5的批量处理说明:不要将提供者密钥放入代码仓库,设定单次会话的令牌上限,并将转录内容存储在评估测试用例旁边,以便后续模型更换时仍能保持可比性。
针对强化安全措施的第0阶段,在修改代码之前需明确输入内容、该步骤的负责人以及终止标准。操作人员应能够从已知的检查点重新运行该步骤,而无需猜测隐藏状态。需同时记录正常流程和异常恢复流程。重试机制、人工审核环节以及错误处理都属于产品功能的一部分,而非后续需要完善的内容。
强化安全措施细节0/963:针对此说明需统计运行耗时、错误类型以及令牌使用量,然后依据固定的评估标准而非主观判断来决定是否保留该变更。
在处理强化措施的第一阶段时,首先写下相关契约:所需的输入参数、成功信号以及部分失败时的处理方式。这样的检查清单能确保后续的代码修改始终符合约定。 将这一阶段视为输入与验证后输出之间的契约。为相关产物命名,明确成功判定标准,杜绝默许的部分完成情况。
强化措施细节 1/963:需测量该环节的运行时间、错误类型以及令牌消耗情况,然后依据固定的评估标准而非个人经验来决定是否保留该变更。
将强化措施的第二阶段视为可量化的对象来处理效果最佳。在扩大范围之前,先记录一份标准操作示例、一个失败案例以及回滚说明。 应将配置信息与应用程序代码分开。环境文件、密钥存储和功能开关应集中存放于一处,以便操作人员无需查看全部代码结构即可进行审计。
强化措施细节 2/963:测量该任务的执行时间、错误类型以及代币消耗情况,然后依据固定的问题集而非个人经验来判断是否保留该变更。
在强化措施的第3阶段,应在修改代码之前明确输入参数、该步骤的负责人以及完成标准。操作人员应能够从已知的检查点重新运行该步骤,而无需猜测隐藏状态。相比复杂的脚本,更应采用小型且可测试的单元。当某一步骤失败时,故障原因应能指向单一责任方,而非混乱的整个流程。
强化措施细节 3/963:测量该任务的执行时间、错误类型以及代币消耗情况,然后依据固定的问题集而非个人经验来判断是否保留该变更。