AgentEvaluator with num_runs > 1 reuses the pinned session across runs, so later runs score wrong
维护者通常 3 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 42/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
调研方向
Start in AgentEvaluator._get_eval_results_by_eval_id, which sends one InferenceRequest per run with InferenceConfig.num_runs=1, then read LocalEvalService.perform_inference and _without_pinned_session_id, which only drops a pinned session when a single request asks for several runs. Done means a regression test in tests/unittests/evaluation/test_agent_evaluator.py where a pinned session_id with num_runs=3 gives each run a fresh session, so every run passes with users=1 counter=0.
由索引模型根据 Issue 内容生成。
描述
Summary
AgentEvaluator.evaluate / evaluate_eval_set with num_runs > 1 gives wrong scores for any eval case whose session_input pins a session_id. The AgentEvaluator docstring suggests pinning a session id to preload artifacts, so this is a normal setup.
Run 2 and later continue the session that run 1 left behind. The agent sees the earlier run's conversation and changed state, and session_input.state is not applied again. Later runs then pass or fail because of leftover context, not because of the agent's behaviour, so pass rates and pass@k-style results are wrong. adk eval --num_runs on the same eval set gives correct results.
Reproduction
Run on current main (3e322e9a). The agent replies with the number of user messages in its session and a state counter that session_input.state seeds to 0. Each run should therefore reply users=1 counter=0.
import asyncio
from google.adk.agents.base_agent import BaseAgent
from google.adk.events.event import Event, EventActions
from google.adk.evaluation.agent_evaluator import AgentEvaluator
from google.adk.evaluation.eval_case import EvalCase, Invocation, SessionInput
from google.adk.evaluation.eval_metrics import EvalMetric
from google.adk.evaluation.eval_set import EvalSet
from google.adk.evaluation.simulation.user_simulator_provider import UserSimulatorProvider
from google.genai import types
class Probe(BaseAgent):
async def _run_async_impl(self, ctx):
n_user = sum(1 for e in ctx.session.events if e.author == "user")
counter = ctx.session.state.get("counter")
yield Event(author=self.name, invocation_id=ctx.invocation_id,
content=types.Content(role="model", parts=[types.Part(text=f"users={n_user} counter={counter}")]),
actions=EventActions(state_delta={"counter": (counter or 0) + 1}))
def case(session_id):
return EvalCase(
eval_id="c",
conversation=[Invocation(user_content=types.Content(role="user", parts=[types.Part(text="hi")]),
final_response=types.Content(role="model", parts=[types.Part(text="users=1 counter=0")]))],
session_input=SessionInput(app_name="app", user_id="u", session_id=session_id, state={"counter": 0}))
async def run(session_id):
res = await AgentEvaluator._get_eval_results_by_eval_id(
agent_for_eval=Probe(name="probe"), eval_set=EvalSet(eval_set_id="s", eval_cases=[case(session_id)]),
eval_metrics=[EvalMetric(metric_name="response_match_score", threshold=1.0)],
num_runs=3, user_simulator_provider=UserSimulatorProvider(), app_name="app")
for r in sorted(res["c"], key=lambda r: r.repetition_index):
resp = r.eval_metric_result_per_invocation[0].actual_invocation.final_response.parts[0].text
print(f" rep={r.repetition_index} session={r.session_id} response={resp!r} {r.final_eval_status.name}")
for sid in ["pinned", None]:
print(f"session_id={sid!r}:")
asyncio.run(run(sid))
(The public AgentEvaluator.evaluate_eval_set(..., num_runs=3) fails the same way with an AssertionError. The private helper is used here to print each run.)
Actual
session_id='pinned':
rep=0 session=pinned response='users=1 counter=0' PASSED
rep=1 session=pinned response='users=2 counter=1' FAILED
rep=2 session=pinned response='users=3 counter=2' FAILED
session_id=None:
rep=0 session=adk-eval-session-... response='users=1 counter=0' PASSED
rep=1 session=adk-eval-session-... response='users=1 counter=0' PASSED
rep=2 session=adk-eval-session-... response='users=1 counter=0' PASSED
Expected
With the pinned id, every run replies users=1 counter=0 and passes, as without the pin. The InferenceConfig.num_runs docstring (base_eval_service.py) says a pinned session id is ignored when num_runs > 1.
Cause
AgentEvaluator._get_eval_results_by_eval_id sends num_runs separate InferenceRequests, each with InferenceConfig.num_runs=1. LocalEvalService.perform_inference drops a pinned session id (_without_pinned_session_id) only when a single request asks for more than one run, so on this path the pin is never dropped. Every run uses the same session in the shared in-memory session service.
Proposed fix
Send one InferenceRequest with inference_config.num_runs = num_runs, which is what adk eval does. The service then gives each run a fresh session and sets repetition_index itself. As in adk eval, repeated runs now share the parallelism pool instead of running one after another. One regression test is in tests/unittests/evaluation/test_agent_evaluator.py.
I used an AI coding assistant (Claude) to find and analyse this; I reproduced it and checked the fix myself.
I've tested a fix with a regression test: https://github.com/chaitanya0305/adk-python/compare/main...chaitanya0305:adk-python:fix/agent-evaluator-pinned-session-num-runs. If this is accepted, I'll open the PR straight away.
- 主要语言
- Python
- 星标
- 22.3k
- 派生
- 4.4k
- 平均合并
- 1 天 2 小时
- 30 天内合并 PR
- 6
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
google/adk-python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
google/adk-python#8360 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
google/adk-python#8359 ·
维护者通常 3 天内回复
-
Can pin to litellm version be changed?可能已有人在做 @llalitkumarrr 于 10 天前认领。 未关闭models
难度 1/5 1 小时以内 新手友好度 65/100
google/adk-python#8129 · 2 条评论 · 已指派 1 人 ·
维护者通常 3 天内回复
-
OpenAPI tools ignore operation- and path-level server overrides可能已有人在做 @sanketpatil06 于 14 天前认领。 未关闭tools
难度 2/5 1-3 小时 新手友好度 75/100
google/adk-python#8064 · 4 条评论 · 已指派 1 人 ·
维护者通常 3 天内回复
-
Two docstrings in openapi_tool document parameters the signatures do not accept可能已有人在做 @surajksharma07 于 17 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 88/100
google/adk-python#8024 · 1 条评论 · 已指派 1 人 ·
维护者通常 3 天内回复
查看 google/adk-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
vllm-project/vllm#70030 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
TigreGotico/tugaphone#408 ·
维护者通常 1 天内回复
-
needs-triage
难度 2/5 1-3 小时 新手友好度 74/100
gke-labs/kube-agents#7308 ·
维护者通常 1 天内回复
-
t: bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 3 天内回复
-
chore
难度 1/5 1-3 小时 新手友好度 88/100
lugassawan/swe-workbench#841 ·