ADK评估中的用户模拟功能:革新AI代理测试方式

谷歌宣布在代理开发套件(ADK)中推出用户模拟功能,利用LLM动态生成多轮对话测试,帮助开发者构建更健壮的AI代理测试流程,大幅减少测试脚本编写时间。

宣布ADK评估中的用户模拟功能

2025年11月7日

Dima Melnyk
产品经理
Cloud AI

Sita Lakshmi Sangameswaran
高级开发者关系工程师
Cloud AI

代理本质上是对话式的。用户可能需要提出后续问题、优化之前的请求,并根据需要提供额外信息。然而,为这种多轮对话手动编写代理测试脚本是一个脆弱且耗时的过程。你编写了数十个用户输入和预期输出对,结果它们却因为代理行为的微小变化而失效,将测试维护变成了一项令人沮丧的杂事。

今天,我们很高兴地宣布代理开发套件(ADK)中的一项新功能,有助于解决这个问题:用户模拟。这项新功能让你能够摆脱测试僵化的实现路径,转而评估代理实际实现用户意图的能力。

什么是用户模拟器?

用户模拟器的核心是一个由LLM驱动的用户提示生成器。此首次发布直接集成到ADK评估框架中,允许你在本地运行它。你提供一个高级目标,它会动态生成对话的用户端来追求该目标。它不是一个单独的服务;它是ADK中的一个工具,你在本地运行,支持快速迭代的"内循环"工作流程。

工作原理

定义对话场景

你不是提供僵化的逐轮脚本,而是提供一个ConversationScenario。这是一个简单的JSON对象,包含两个关键部分:

  • starting_prompt:开始对话的固定初始提示。
  • conversation_plan:告诉模拟器其目标的自然语言指南。

以下是一个代理评估集的示例,该代理具有掷骰子和检查质数的工具:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
{
  "scenarios": [
    {
      "starting_prompt": "What can you do for me?",
      "conversation_plan": "Ask the agent to roll a 20-sided die. After you get the result, ask the agent to check if it is prime."
    },
    {
      "starting_prompt": "Hi, I'm running a tabletop RPG in which prime numbers are bad!",
      "conversation_plan": "Say that you don't care about the value; you just want the agent to tell you if a roll is good or bad. Once the agent agrees, ask it to roll a d6. Finally, ask the agent to do the same with 2 d20."
    }
  ]
}

当你运行评估时,模拟器将动态处理来回对话,直到conversation_plan完成。以下是上述第一个场景可能生成的对话示例(为清晰起见重新格式化):

1
2
3
4
5
6
7
8
9
[USER]: What can you do for me?
[AGENT]: I can roll dice and check if numbers are prime. How can I help?
[USER]: Please roll a 20-sided die for me.
[AGENT]: Of course. The result is 17.
[USER]: Thanks. Can you check if 17 is a prime number?
[AGENT]: Yes, 17 is a prime number.
[USER]: </finished>
--------------------
EVALUATION RESULT: COMPLETED

请注意conversation_plan如何定义一系列目标。它不指定用户的确切提示或代理的确切预期响应。它只关心结果:获得骰子掷出结果,然后对该结果进行质数检查。这使得测试对你的代理对话风格或内部逻辑的微小变化具有弹性。

配置模拟

通过提供EvalConfig文件,你可以直接控制模拟器的行为。这允许你根据特定的测试需求微调模拟。

以下是你可以配置的关键参数:

  • 模型:指定支持用户模拟器的模型(例如,gemini-2.5-flash)。
  • 模型配置:指定模型的选项,例如思考行为。
  • 轮次预算:设置对话终止前的最大用户-代理交互次数(max_allowed_invocations),防止无限循环。
  • 自定义行为:除了上述参数,你还可以覆盖默认的系统提示来更改模拟器的角色。这允许你测试代理如何处理不同类型的用户,例如困惑的用户或要求更高的用户。我们计划很快通过EvalConfig添加角色配置支持。

以下是一个配置文件的示例,包含评估标准和用户模拟器的配置:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
{
  "criteria": {
   "hallucinations_v1": {
     "threshold": 0.5,
     "evaluate_intermediate_nl_responses": true
   }
 },
  "user_simulator_config": {
    "model": "gemini-2.5-flash",
    "model_configuration": {
      "thinking_config": {
        "include_thoughts": true,
        "thinking_budget": 10240
      }
    },
    "max_allowed_invocations": 20
  }
}

运行评估

准备好场景和配置后,你可以运行评估以获得交互的详细分解。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
*********************************************************************
Eval Run Summary
eval_set_with_scenarios:
  Tests passed: 2
  Tests failed: 0
********************************************************************
Eval Set Id: eval_set_with_scenarios
Eval Id: 83903cba
Overall Eval Status: PASSED
---------------------------------------------------------------------
Metric: hallucinations_v1, Status: PASSED, Score: 1.0, Threshold: 0.5
---------------------------------------------------------------------
Invocation Details:
+----+----------------------+------------------------------------------+-------------------+
|    | prompt               | actual_response                          | hallucinations_v1 |
+====+======================+==========================================+===================+
|  0 | What can you do for  | I can roll dice of different sizes and   | Status: PASSED,   |
|    | me?                  | check if numbers are prime. For example, | Score: 1.0        |
|    |                      | I can roll an 8-sided die and tell you   |                   |
|    |                      | the result. Also, I can check if a       |                   |
|    |                      | number (or a list of numbers) is prime.  |                   |
+----+----------------------+------------------------------------------+-------------------+
|  1 | Please roll a        | I rolled a 20-sided die, and the result  | Status: PASSED,   |
|    | 20-sided die for me. | is 16.                                   | Score: 1.0        |
+----+----------------------+------------------------------------------+-------------------+
|  2 | Can you check if 16  | No, 16 is not a prime number.            | Status: PASSED,   |
|    | is a prime number?   |                                          | Score: 1.0        |
+----+----------------------+------------------------------------------+-------------------+

********************************************************************
Eval Set Id: eval_set_with_scenarios
Eval Id: b7944d3f
Overall Eval Status: PASSED
---------------------------------------------------------------------
Metric: hallucinations_v1, Status: PASSED, Score: 0.875, Threshold: 0.5
---------------------------------------------------------------------
Invocation Details:
+----+---------------------------+------------------------------------------+-------------------+
|    | prompt                    | actual_response                          | hallucinations_v1 |
+====+===========================+==========================================+===================+
|  0 | Hi, I'm running a         | Understood! I can roll dice and check if | Status: PASSED,   |
|    | tabletop RPG in which     | the results are prime numbers for you.   | Score: 1.0        |
|    | prime numbers are bad!    | Let me know when you need me to roll a   |                   |
|    |                           | die and check for primes.                |                   |
+----+---------------------------+------------------------------------------+-------------------+
|  1 | I don't really care about | Alright, I can roll dice for you and     | Status: PASSED,   |
|    | the actual number; I just | tell you whether the result is a prime   | Score: 1.0        |
|    | need you to tell me if    | number (bad) or not (good). Just tell me |                   |
|    | the roll is good or bad.  | how many sides the die should have.      |                   |
+----+---------------------------+------------------------------------------+-------------------+
|  2 | Great, please roll a d6.  | The result is 6, which is not a prime    | Status: PASSED,   |
|    |                           | number. That's a good roll!              | Score: 1.0        |
+----+---------------------------+------------------------------------------+-------------------+
|  3 | Okay, now please roll 2   | Okay, so 19 is prime (bad) and 6 is not  | Status: PASSED,   |
|    | d20.                      | prime (good). One good, one bad.         | Score: 1.0        |
+----+---------------------------+------------------------------------------+-------------------+

这对开发者意味着什么

用户模拟的此初始版本专注于解决创建和维护多轮测试的直接繁琐工作。它帮助你:

  • 大幅减少测试创建时间:停止编写复杂的逐轮脚本,转而定义简单的高级目标。
  • 构建更具弹性的测试:通过专注于意图而非特定的对话路径,你的测试不会在每次重构提示时失效。
  • 创建可靠的回归测试套件:快速生成广泛的测试用例,构建一个安全网,在回归问题到达生产环境之前捕获它们。

我们相信,健壮的目标导向模拟是构建可靠和可信AI代理的基本能力。此功能是我们更广泛愿景的基础第一步,旨在为整个代理生命周期提供全面的模拟能力。代表实现此功能的核心团队——Ankur Sharma、Keyur Joshi、Pierre Thodoroff、Sebastian Caldas和Xiaowei Li——我们很高兴看到你构建的内容,并欢迎你在开始使用此功能时提供反馈。

准备好开始了吗?深入阅读ADK文档和Colab教程,立即开始探索用户模拟功能。

comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计