Skip to content

fix(trace): skip tool-call and empty turns in final_response; keep Span.is_truncated - #593

Merged
haiyuan-eng-google merged 2 commits into
GoogleCloudPlatform:mainfrom
yihuang0830:fix/trace-final-response
Nov 23, 2026
Merged

haiyuan-eng-google merged 2 commits into
GoogleCloudPlatform:mainfrom
yihuang0830:fix/trace-final-response

Conversation

@yihuang0830

@yihuang0830 yihuang0830 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

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_response no longer returns a tool call or an empty turn as the answer.
The ADK plugin logs a model turn as its parts joined by |:

  • a tool call is call: <tool>, or text: '...' | call: <tool> when the model also wrote text
  • a turn with no content parts is the bare string None

When a run stopped on one of these turns, Trace.final_response and SessionTrace.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 scored call: run_python or None as the agent's answer. The plugin's own eval view (eval_view_ctes_v1.sql) already treats both shapes as no text.

What changes:

  • Empty turns are now skipped, the same way empty responses already were.
  • A last model turn that ends in tool calls holds no text answer. Both accessors then fall back to AGENT_COMPLETED and return None when 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 all call: <name>. The plugin closes every text part with a quote, so a text answer cannot end that way. Answers that mention call:, and model text None (logged as text: 'None'), are unchanged; tests cover both.

2. Span keeps is_truncated.
get_trace() and list_traces() already select the is_truncated column, but Span.from_bigquery_row() dropped it. Callers could not tell a clipped or redacted tool result from a complete one. It is now a bool field:

  • True when the column is true, including numpy booleans
  • False when it is false, NULL or missing

It 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/main with this branch on the 933 ADK runs from our KramaBench experiments that have agent_events rows (40,040 rows):

Run outcome Runs final_response before After
Hit the step limit 55 call: <tool> None
Errored on a tool-call turn 7 call: <tool> (one with an empty tool name) None
Empty last turn after a malformed function call 15 the string None None
Completed 686 answer text unchanged
Errored before any answer 170 None unchanged

SessionTrace.extract_final_response() gives the same results. In the same runs, 158 spans have is_truncated = TRUE; before this change the SDK had no field for them.

Not in this PR

Testing

  • 32 new test cases in tests/test_sdk_trace.py and tests/test_performance_evaluator.py. 25 of them fail on upstream/main and pass here. The other 7 guard behaviour that must not change: text answers that mention call:, a text turn after tool calls, and model text None. The cases cover:
    • runs ending on a tool call: single, parallel, after text, dotted, namespaced and empty tool names, and string content
    • empty turns, before and after a text answer
    • the AGENT_COMPLETED fallback
    • is_truncated for True, False, None, "true", "false", a numpy boolean and a missing column
  • Full pytest on Python 3.13 (macOS): 11373 passed, 87 skipped. I deselected the 4 browser_smoke Looker Studio tests because they hang on macOS, and they don't touch this change.
  • bash autoformat.sh leaves no diff.
…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 caohy1988 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@haiyuan-eng-google
haiyuan-eng-google merged commit bc85658 into GoogleCloudPlatform:main Nov 23, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants