源文件:chapter2/prompt-engineering/README.md Prompt Engineering Ablation Study for Tau-Bench 概述 (Overview) 这个项目扩展了 Tau-Bench 框架,添加了三个关键的消融研究选项,用于演示提示工程:把 Agent 看成聪明的新员工章节的重要性。通过这些实验,我们可以量化不同提示工程因素对 Agent 性能的影响。
源文件:chapter2/prompt-engineering/README.md
这个项目扩展了 Tau-Bench 框架,添加了三个关键的消融研究选项,用于演示提示工程:把 Agent 看成聪明的新员工章节的重要性。通过这些实验,我们可以量化不同提示工程因素对 Agent 性能的影响。
This project extends the Tau-Bench framework with three critical ablation study options to demonstrate the importance of prompt engineering - treating agents as smart new employees. Through these experiments, we can quantify the impact of different prompt engineering factors on agent performance.
演示不同的沟通风格如何影响 Agent 的表现:
原理: 语气会影响 Agent 的专业性和任务完成质量。过于随意或夸张的语气可能导致:
使用预生成的极度混乱版本的 wiki.md:
原理: 良好组织的指令就像给新员工的培训手册。极度随机化会:
移除所有工具和参数的描述信息:
原理: 清晰的工具描述就像员工手册中的操作指南。移除描述会:
首先确保已安装基础 Tau-Bench 依赖:
cd projects/week2/prompt-engineering pip install -r requirements.txt
所有入口脚本均提供中文
--help:python run_ablation.py --help、python analyze_results.py --help。
--all 会在同一个进程内依次运行基线 + 三个维度的单独消融 + 全部叠加,跑完后直接打印成功率对比表,并把汇总统计写入 --output(默认 log-dir/ablation_summary_<时间戳>.json)。这是复现书中"实验 2-4"结论最直接的方式:
python run_ablation.py \ --model gpt-5.6-luna \ --env airline \ --end-index 10 \ --all # 说明:默认使用 OpenAI 直连(provider=openai),需设置 OPENAI_API_KEY。 # 如需走 OpenRouter,把模型写成带斜杠的 id(如 openai/gpt-5), # 脚本会自动选择 openrouter provider(需 OPENROUTER_API_KEY)。 # 通用回退:即使模型是 bare id(如 gpt-4o-mini),只要未设 OPENAI_API_KEY # 而设了 OPENROUTER_API_KEY,脚本会自动把它前缀成 openai/gpt-4o-mini 并 # 切到 openrouter provider。
跑完后会打印如下成功率对比表。下面是一次真实运行的输出(--model gpt-4o --env airline --end-index 4,即每组仅 4 个任务的冒烟样本),仅用于展示表格形态:
Experiment Success Rate Tasks Relative ---------------------------------------------------------------------- wiki_random 50.0% 2/ 4 200.0% baseline 25.0% 1/ 4 100.0% ⭐ tone_trump 25.0% 1/ 4 100.0% tone_casual 25.0% 1/ 4 100.0% no_tool_desc 0.0% 0/ 4 0.0% all_ablations 0.0% 0/ 4 0.0%
⚠️ 上表每组只有 4 个任务,样本量极小、噪声很大——例如
wiki_random这一次偶然高于baseline,这是小样本波动,并非真实结论。方向性信号(移除工具描述 → 0%、全部叠加 → 0%、语气对成功率无影响)与书中"实验 2-4"一致,但要得到稳定的量化结论(如"信息组织混乱导致成功率下降 30% 以上"),请把--end-index提高到 10 及以上并多跑几个--seed。请以你自己的完整运行结果为准,不要直接引用这里的冒烟数字。
运行基线实验(无消融):
python run_ablation.py \ --model gpt-5.6-luna \ --env airline \ --task-split test \ --start-index 0 \ --end-index 10 # Note: bare model ids (gpt-4o-mini) use OpenAI direct; ids with '/' auto-select openrouter
python run_ablation.py \ --model gpt-5.6-luna \ --env airline \ --tone-style trump \ --ablation-name trump_tone
python run_ablation.py \ --model gpt-5.6-luna \ --env airline \ --tone-style casual \ --ablation-name casual_tone
python run_ablation.py \ --model gpt-5.6-luna \ --env airline \ --randomize-wiki \ --ablation-name wiki_random
python run_ablation.py \ --model gpt-5.6-luna \ --env airline \ --remove-tool-descriptions \ --ablation-name no_tool_desc
测试多个因素的组合影响:
python run_ablation.py \ --model gpt-5.6-luna \ --env airline \ --tone-style casual \ --randomize-wiki \ --remove-tool-descriptions \ --ablation-name full_ablation
有两种等价方式跑完整套消融:
python run_ablation.py --env airline --end-index 10 --all,单进程内跑完并直接打印对比表。run_full_ablation.sh,它逐个调用 run_ablation.py 再自动调用 analyze_results.py 汇总:# 默认 10 个任务/实验;--quick 用 3 个任务快速冒烟 ./run_full_ablation.sh --model gpt-5.6-luna --env airline --num-tasks 10 ./run_full_ablation.sh --quick
每个实验的原始轨迹保存在 results_ablation/ 目录,包含:
analyze_results.py 会扫描结果目录,按实验名聚合成功率并打印对比表、消融因子影响分析和 ASCII 柱状图:
# 分析默认目录 python analyze_results.py # 指定目录并把汇总统计写入 JSON python analyze_results.py --results-dir results_ablation --output summary.json
注意:
--all模式已在运行结束时直接打印同样的对比表,analyze_results.py适用于事后重新汇总或分析历史/手动运行的结果。仓库中随附的results_ablation/*.json是少量任务(1~6 个)的调试样本,仅用于演示数据格式,样本量不足以得出统计结论,请以你自己完整运行(如--end-index 10及以上)的结果为准。
基于提示工程原理,预期性能排序:
这些实验演示了为什么要把 Agent 看成聪明的新员工:
就像培训新员工,Agent 需要:
| 参数 | 说明 | 选项 |
|---|---|---|
--tone-style |
维度一·语气风格(应用到系统提示) | default, trump, casual |
--randomize-wiki |
维度二·随机化wiki规则组织结构 | flag |
--remove-tool-descriptions |
维度三·移除工具描述 | flag |
--all |
一键运行完整消融套件并打印对比表 | flag |
--output |
(仅 --all)汇总统计 JSON 输出路径 | string |
--ablation-name |
实验名称标识 | string |
--env |
环境选择 | airline, retail |
--model |
使用的模型 | string (e.g., gpt-4o-mini, gpt-4o) |
--model-provider |
模型提供商(可选) | 自动检测(裸 id 用 openai,带 / 的 id 用 openrouter) |
--task-split |
任务集 | train, test, dev |
--start-index |
起始任务索引 | integer |
--end-index |
结束任务索引 | integer |
--log-dir |
结果保存目录 | string |
--max-concurrency 参数添加详细日志:
export LITELLM_LOG=DEBUG python run_ablation.py ...
欢迎贡献更多消融研究选项!请考虑添加:
这个消融研究框架量化展示了良好提示工程的重要性。通过系统地降解不同方面的提示质量,我们可以看到:
记住:优秀的提示工程就是优秀的员工培训!
本项目是《AI Agent 实战》第2周"提示工程"章节的配套代码。
❗News: We have released τ²-bench as an extension of \tau-bench. \tau^2-bench includes code fixes and an additional telecom domain focusing on troubleshooting scenarios. Please use the \tau^2-bench as the latest version of this benchmark.
Paper:
We propose \tau-bench, a benchmark emulating dynamic conversations between a user (simulated by language models) and a language agent provided with domain-specific API tools and policy guidelines.
| Strategy | Pass^1 | Pass^2 | Pass^3 | Pass^4 |
|---|---|---|---|---|
| TC (claude-3-5-sonnet-20241022) | 0.460 | 0.326 | 0.263 | 0.225 |
| TC (gpt-4o) | 0.420 | 0.273 | 0.220 | 0.200 |
| TC (claude-3-5-sonnet-20240620) | 0.360 | 0.224 | 0.169 | 0.139 |
| TC (mistral-large-2407) | ?? | ?? | ?? | ?? |
| TC (gpt-4o-mini) | 0.225 | 0.140 | 0.110 | 0.100 |
| Act (gpt-4o) | 0.365 | 0.217 | 0.160 | 0.140 |
| ReAct (gpt-4o) | 0.325 | 0.233 | 0.185 | 0.160 |
| Strategy | Pass^1 | Pass^2 | Pass^3 | Pass^4 |
|---|---|---|---|---|
| TC (claude-3-5-sonnet-20241022) | 0.692 | 0.576 | 0.509 | 0.462 |
| TC (gpt-4o) | 0.604 | 0.491 | 0.430 | 0.383 |
| TC (claude-3-5-sonnet-20240620) | 0.626 | 0.506 | 0.435 | 0.387 |
| TC (mistral-large-2407) | ?? | ?? | ?? | ?? |
| TC (gpt-4o-mini) | ?? | ?? | ?? | ?? |
| Act (gpt-4o) | ?? | ?? | ?? | ?? |
| ReAct (gpt-4o) | ?? | ?? | ?? | ?? |
*TC = tool-calling strategy (the function-calling strategy reported in the paper)
git clone https://github.com/sierra-research/tau-bench && cd ./tau-bench
pip install -e .
OPENAI_API_KEY=... ANTHROPIC_API_KEY=... GOOGLE_API_KEY=... MISTRAL_API_KEY=...
Run a tool-calling agent on the τ-retail environment:
python run.py --agent-strategy tool-calling --env retail --model gpt-4o --model-provider openai --user-model gpt-4o --user-model-provider openai --user-strategy llm --max-concurrency 10
Set max concurrency according to your API limit(s).
To run specific tasks, use the --task-ids flag. For example:
python run.py --agent-strategy tool-calling --env retail --model gpt-4o --model-provider openai --user-model gpt-4o --user-model-provider openai --user-strategy llm --max-concurrency 10 --task-ids 2 4 6
This command will run only the tasks with IDs 2, 4, and 6.
By default, we use gpt-4o as the user simulator with strategy llm. You can use other models by setting the --user-model flag, or other strategies by setting the --user-strategy flag. For example, run a tool-calling agent with a claude user simulator:
python run.py --agent-strategy tool-calling --env retail --model gpt-4o --model-provider openai --max-concurrency 10 --user-model claude-3-5-sonnet-20240620 --user-model-provider anthropic --user-strategy llm
Other strategies:
To run react user simulator:
python run.py --agent-strategy tool-calling --env retail --model gpt-4o --model-provider openai --max-concurrency 10 --user-model gpt-4o --user-model-provider openai --user-strategy react
Example of a react user response:
Thought: I should provide my name and zip code as I wasn't given an email address to use. User Response: Sure, my name is Yusuf Rossi, and my zip code is 19122.
To run verify user simulator:
python run.py --agent-strategy tool-calling --env retail --model gpt-4o --model-provider openai --max-concurrency 10 --user-model gpt-4o --user-model-provider openai --user-strategy verify
This strategy uses a subsequent LLM verification step to check if the user simulator's response is satisfactory. If not, the user simulator will be prompted to generate a new response.
To run reflection user simulator:
python run.py --agent-strategy tool-calling --env retail --model gpt-4o --model-provider openai --max-concurrency 10 --user-model gpt-4o --user-model-provider openai --user-strategy reflection
This strategy uses a subsequent LLM verification step to check if the user simulator's response is satisfactory. If not, the user simulator will be prompted to reflect on its response and generate a new response.
Often times, it is difficult and time consuming to manually identify specific error locations in trajectories as they can be long and the constraints can be complex. We have provided an auto error identification tool that can do the following:
Both of the labels are accompanied with a description.
To run the auto error identification, run:
python auto_error_identification.py --env <airline/retail> --platform openai --results-path <the path to your results file here> --max-concurrency 16 --output-path test-auto-error-identification --max-num-failed-results 10
Please note that this feature utilizes an LLM, which may lead to inaccurate error identifications.
*Notice: If an error is raised due to the structure of your results file, you may have to rerun the benchmark to produce a new results file. We have recently rewritten the benchmark to be more type-safe and extensible.
τ-bench might be expensive to run. We have provided a set of historical trajectories for the airline and retail environments in ./historical_trajectories.
If you would like to contribute your historical trajectories to this benchmark, please submit a PR!
See ./LICENSE.
Please submit issues or pull requests if you find problems with the benchmark.
@misc{yao2024tau, title={$\tau$-bench: A Benchmark for Tool-Agent-User Interaction in Real-World Domains}, author={Shunyu Yao and Noah Shinn and Pedram Razavi and Karthik Narasimhan}, year={2024}, eprint={2406.12045}, archivePrefix={arXiv}, primaryClass={cs.AI}, url={https://arxiv.org/abs/2406.12045}, } @misc{barres2025tau2, title={$\tau^2$-Bench: Evaluating Conversational Agents in a Dual-Control Environment}, author={Victor Barres and Honghua Dong and Soham Ray and Xujie Si and Karthik Narasimhan}, year={2025}, eprint={2506.07982}, archivePrefix={arXiv}, primaryClass={cs.AI}, url={https://arxiv.org/abs/2506.07982}, }