Eval results do not record why a simulated conversation ended; a run cut off by max_allowed_invocations is judged as if the user simulator had said </finished>
🔴 Required Information
Is your feature request related to a specific problem?
A conversation_scenario eval case can end in two very different ways:
- the user simulator decides the goal is met and emits
</finished>(Status.STOP_SIGNAL_DETECTED), or - the conversation is cut off at
LlmBackedUserSimulatorConfig.max_allowed_invocations(Status.TURN_LIMIT_REACHED), typically because the agent loops or never completes the task.
EvaluationGenerator only checks status == SUCCESS and breaks on anything else (evaluation_generator.py, the while True loop around get_next_user_message), so the reason is dropped. Nothing in InferenceResult or EvalCaseResult records it; the only trace is a logger.warning.
Two consequences:
- Results cannot tell "did not finish" apart from "finished". For agent evaluation, "the conversation hit the turn limit" is one of the most useful failure signals (the agent looped, kept asking for clarification, never acted), and it is fully deterministic. Today it is invisible in saved results, in
adk evaloutput and tomulti_run_configaggregation. per_turn_user_simulator_quality_v1judges a stop that never happened._evaluate_stop_signal_turnalways appends a synthetic</finished>user turn (_get_stop_signal_invocation) and asks the judge whether ending there was appropriate. For a cut-off conversation the judge is told the simulator said</finished>when it did not. Its rubric then reads it as "the Generated User Response used</finished>, but tasks in the Conversation Plan are still incomplete", which blames the simulator for a truncation done by the framework.
Offline repro (fake agent that keeps asking "Which order do you mean?", fake user simulator model that finishes in one scenario and keeps going in the other, max_allowed_invocations=4, and a fake judge that records the prompts):
$ python repro.py
cut_off status=SUCCESS turns=4 other fields set=['status']
finished status=SUCCESS turns=1 other fields set=['status']
cut_off: user turns sent to the per-turn judge: ['Order 1, please cancel it.', 'Order 1, please cancel it.', 'Order 1, please cancel it.', '</finished>']
cut_off final_eval_status=NOT_EVALUATED fields=['eval_id', 'eval_metric_result_per_invocation', 'eval_set_file', 'eval_set_id', 'final_eval_status', 'repetition_index', 'session_details', 'session_id', 'user_id']
finished final_eval_status=NOT_EVALUATED fields=['eval_id', 'eval_metric_result_per_invocation', 'eval_set_file', 'eval_set_id', 'final_eval_status', 'repetition_index', 'session_details', 'session_id', 'user_id']
The cut-off run has the same status and fields as the finished one, and its last judged user turn is a </finished> the simulator never produced.
(main at 110e826b, 2.15.1, Python 3.12.16, Linux. No API key needed.)
Describe the Solution You'd Like
- Record the termination reason. Add an optional
termination_reason(e.g.stop_signal,turn_limit,no_message) toInferenceResult, filled from the lastNextUserMessage.statusin both the regular and the live inference paths, and copy it toEvalCaseResultso it is saved byEvalSetResultsManagerand shown byadk eval.Nonefor static conversations. Backwards compatible. - Let the per-turn simulator metric see it. Pass the reason to
per_turn_user_simulator_quality_v1(it is already the only consumer of the stop-signal turn) and skip the synthetic</finished>turn when the run hit the turn limit. That turn could beNOT_EVALUATED, or the metric could judge whether the simulator should have stopped earlier. - (Optional, opt-in) Fail cases that hit the turn limit, e.g.
fail_on_turn_limit: bool = Falseon the user simulator config, or a tiny deterministic metric (conversation_completed) that scores 0 forturn_limit. That gives CI a model-free "the agent did not finish" check, complementary to the deterministic tool-call checks proposed in #8077.
Questions for maintainers:
- Is
InferenceResult/EvalCaseResultthe right place, or should the reason live on the lastInvocationso evaluators can read it without an interface change? - For (3), a flag or a metric? A metric fits the existing aggregation (
pass^ketc.) better.
Impact on your work
I found this while reading the user-simulation path for #8077. A looping agent is a common failure in multi-turn agents, and today it can only be caught if a judge-backed metric happens to notice.
Willingness to contribute
Yes. (1) and (2) are small and self-contained, and I can do (3) after agreeing on the shape.
🟡 Recommended Information
Describe Alternatives You've Considered
- Counting invocations against
max_allowed_invocationsin a custom metric: the evaluator does not receive the simulator config, and a conversation can legitimately end exactly at the limit with</finished>. - Parsing logs for the warning: not available in saved results, and not usable from
AgentEvaluator/pytest.
Reproduction code
"""A simulated conversation cut off by max_allowed_invocations looks like a finished one."""
import asyncio, logging
from typing import ClassVar
from google.adk.agents.llm_agent import LlmAgent
from google.adk.evaluation import eval_case as ec
from google.adk.evaluation.base_eval_service import (
EvaluateConfig, EvaluateRequest, InferenceConfig, InferenceRequest)
from google.adk.evaluation.conversation_scenarios import ConversationScenario
from google.adk.evaluation.in_memory_eval_sets_manager import InMemoryEvalSetsManager
from google.adk.evaluation.local_eval_service import LocalEvalService
from google.adk.evaluation.simulation.llm_backed_user_simulator import LlmBackedUserSimulatorConfig
from google.adk.evaluation.simulation.user_simulator_provider import UserSimulatorProvider
from google.adk.models.base_llm import BaseLlm
from google.adk.models.llm_response import LlmResponse
from google.adk.models.registry import LLMRegistry
from google.genai import types
logging.getLogger().setLevel(logging.CRITICAL)
class FakeAgent(BaseLlm):
@classmethod
def supported_models(cls): return [r"^fake-agent$"]
async def generate_content_async(self, req, stream=False):
yield LlmResponse(content=types.ModelContent("Which order do you mean?"))
class FakeUser(BaseLlm):
"""Finishes in the 'done' scenario; keeps asking in the 'stuck' one."""
@classmethod
def supported_models(cls): return [r"^fake-user$"]
async def generate_content_async(self, req, stream=False):
prompt = req.contents[0].parts[0].text
text = "</finished>" if "PLAN-DONE" in prompt else "Order 1, please cancel it."
yield LlmResponse(content=types.ModelContent(text))
class FakeJudge(BaseLlm):
"""Records the prompts the per-turn judge receives."""
prompts: ClassVar[list] = []
@classmethod
def supported_models(cls): return [r"^fake-judge$"]
async def generate_content_async(self, req, stream=False):
FakeJudge.prompts.append(req.contents[-1].parts[0].text)
yield LlmResponse(content=types.ModelContent("VALID"))
for c in (FakeAgent, FakeUser, FakeJudge): LLMRegistry.register(c)
async def main():
m = InMemoryEvalSetsManager(); m.create_eval_set("app", "set")
for cid, plan in [("finished", "PLAN-DONE: stop after one reply."),
("cut_off", "PLAN-STUCK: keep asking until order 1 is cancelled.")]:
m.add_eval_case("app", "set", ec.EvalCase(eval_id=cid, conversation_scenario=
ConversationScenario(starting_prompt="Cancel my order.", conversation_plan=plan)))
svc = LocalEvalService(
root_agent=LlmAgent(name="agent", model="fake-agent"), eval_sets_manager=m,
user_simulator_provider=UserSimulatorProvider(LlmBackedUserSimulatorConfig(
model="fake-user", max_allowed_invocations=4)))
infs = [r async for r in svc.perform_inference(InferenceRequest(
app_name="app", eval_set_id="set", inference_config=InferenceConfig()))]
infs.sort(key=lambda r: r.eval_case_id)
for r in infs:
extra = set(r.model_dump(exclude_none=True)) - {"app_name","eval_set_id","eval_case_id","inferences","session_id","repetition_index"}
print(f"{r.eval_case_id:9s} status={r.status.name} turns={len(r.inferences)} other fields set={sorted(extra)}")
from google.adk.evaluation.eval_metrics import EvalMetric, JudgeModelOptions, LlmBackedUserSimulatorCriterion
cut = [r for r in infs if r.eval_case_id == "cut_off"]
metric = EvalMetric(metric_name="per_turn_user_simulator_quality_v1", threshold=1.0,
criterion=LlmBackedUserSimulatorCriterion(threshold=1.0,
judge_model_options=JudgeModelOptions(judge_model="fake-judge", num_samples=1)))
async for res in svc.evaluate(EvaluateRequest(inference_results=cut,
evaluate_config=EvaluateConfig(eval_metrics=[metric]))):
judged = [p.rstrip().splitlines()[-1] for p in FakeJudge.prompts]
print("cut_off: user turns sent to the per-turn judge:", judged)
async for res in svc.evaluate(EvaluateRequest(inference_results=infs,
evaluate_config=EvaluateConfig(eval_metrics=[]))):
fields = sorted(k for k, v in res.model_dump(exclude_none=True).items() if v not in ([], ""))
print(f"{res.eval_id:9s} final_eval_status={res.final_eval_status.name} fields={fields}")
asyncio.run(main())
Additional context
Related: #8077 (deterministic tool-call expectations for conversation_scenario cases), #7886 (per-turn simulator metric scoring unjudged turns).
I used Grok Bot to help find the issue and draft this report; I reproduced the bug and checked the output locally.