Repository navigation
fix(trace): skip tool-call and empty turns in final_response; keep Span.is_truncated - #593
Conversation
…an.is_truncated A run that stops on a tool-call turn (e.g. at a step limit) or on an empty model turn has no text answer, but Trace.final_response and SessionTrace.extract_final_response returned the plugin's "call: <tool>" or "None" text. Empty turns are now skipped, and a last model turn that ends in tool calls falls back to AGENT_COMPLETED, else None. Span.from_bigquery_row now keeps the is_truncated column that get_trace() and list_traces() already select. Part of GoogleCloudPlatform#435.
caohy1988
left a comment
There was a problem hiding this comment.
Thanks, this fixes a real scoring problem. A step-limit run whose last turn is call: run_python shouldn't be graded as if that were the answer, and keeping is_truncated on Span is a useful addition. I checked the new cases fail on main and pass here, and the appended field keeps positional construction working.
Approving. A few edge cases in the new detection I'd still tighten, and I'll put them in a follow-up issue. The tail regex runs on every producer, so plain-text answers written by the bundled tracing writer (a literal None, call: lookup, Status | call: support) now come back as None. A clipped ADK text answer ending in | call: support...[TRUNCATED] is also read as a tool call and dropped. And neither the empty-turn skip nor the AGENT_COMPLETED fallback is bounded to the current invocation, so in a multi-turn session an unanswered follow-up can pick up the previous turn's answer.
bc85658
into
GoogleCloudPlatform:main
Summary
First part of the plan discussed in #435: two trace-parsing fixes that the span-level failure rules depend on. The rules and the pluggable hook for benchmark-specific checks are in #594, stacked on this one.
1.
final_responseno longer returns a tool call or an empty turn as the answer.The ADK plugin logs a model turn as its parts joined by
|:call: <tool>, ortext: '...' | call: <tool>when the model also wrote textNoneWhen a run stopped on one of these turns,
Trace.final_responseandSessionTrace.extract_final_response()returned that string. That happens at a step or call limit, or after a malformed function call. Response matching and LLM judges then scoredcall: run_pythonorNoneas the agent's answer. The plugin's own eval view (eval_view_ctes_v1.sql) already treats both shapes as no text.What changes:
AGENT_COMPLETEDand returnNonewhen it has nothing.The tool-call check is one shared helper,
trace._is_tool_call_response. It matches only a response whose final|-separated segments are allcall: <name>. The plugin closes every text part with a quote, so a text answer cannot end that way. Answers that mentioncall:, and model textNone(logged astext: 'None'), are unchanged; tests cover both.2.
Spankeepsis_truncated.get_trace()andlist_traces()already select theis_truncatedcolumn, butSpan.from_bigquery_row()dropped it. Callers could not tell a clipped or redacted tool result from a complete one. It is now aboolfield:Truewhen the column is true, including numpy booleansFalsewhen it is false, NULL or missingIt is appended after the existing fields, so positional construction is unchanged; the field-order test is updated to match.
Checked on real traces
I compared
upstream/mainwith this branch on the 933 ADK runs from our KramaBench experiments that haveagent_eventsrows (40,040 rows):final_responsebeforecall: <tool>Nonecall: <tool>(one with an empty tool name)NoneNoneNoneNoneSessionTrace.extract_final_response()gives the same results. In the same runs, 158 spans haveis_truncated = TRUE; before this change the SDK had no field for them.Not in this PR
event_idas the dedup key, and our tables do have repeated rows. Butevent_idis not one of the SDK's 16 required columns, so some tables may not have it. I've raised it in RFC: AgentForensics collaboration — automated failure taxonomy and span-level trace auditing over BQAA traces #435. feat(rule_taxonomy): rule-based span attribution for failed sessions #594 drops repeated rows inside the rules only.output_schemawith tools (set_model_response) andfinal_response_tool_names. Their last model turn is a tool call, sofinal_responsenow returnsNoneinstead ofcall: set_model_response. Neither is the answer: the plugin logs the answer as anAGENT_RESPONSErow, which the SDK does not read yet. I'm happy to add that as a follow-up.Testing
tests/test_sdk_trace.pyandtests/test_performance_evaluator.py. 25 of them fail onupstream/mainand pass here. The other 7 guard behaviour that must not change: text answers that mentioncall:, a text turn after tool calls, and model textNone. The cases cover:AGENT_COMPLETEDfallbackis_truncatedforTrue,False,None,"true","false", a numpy boolean and a missing columnpyteston Python 3.13 (macOS): 11373 passed, 87 skipped. I deselected the 4browser_smokeLooker Studio tests because they hang on macOS, and they don't touch this change.bash autoformat.shleaves no diff.