Commit f022307
fix: avoid UserWarning in _build_response_log when response has funct…
Merge google#6127
# Fix: `_build_response_log()` triggers genai SDK UserWarning on every tool call
Closes google#4685
## What's the problem?
Every time an ADK agent invokes a tool, the debug logger calls `_build_response_log(response)`, which includes `resp.text` in its f-string:
```python
return f"""
LLM Response:
...
Text:
{resp.text} # ← triggers UserWarning
...
"""
```
The `GenerateContentResponse.text` property in the google-genai SDK raises a `UserWarning` whenever the response contains non-text parts — which is exactly the case when the model responds with a `function_call`. This means **every single tool invocation floods the log with warnings** like:
```
UserWarning: Warning: there are non-text parts in the response: ['function_call'],returning concatenated text result from text parts, check `response.parts` directly to inspect non-text parts
warnings.warn(
```
Since `_build_response_log` is only called inside `if logger.isEnabledFor(logging.DEBUG)`, this hits any developer who enables debug logging — which is common when debugging agents.
## Root cause
`GenerateContentResponse.text` is a convenience property that warns when mixed content is present. Accessing it in a log formatter silently poisons the log output whenever agents use tools.
## Fix
Replace `resp.text` with a manual join of only the text parts from `resp.candidates`, bypassing the warning entirely:
```python
# Before
return f"""
...
Text:
{resp.text}
...
"""
# After — safe extraction with no warning
text_parts = []
if resp.candidates:
for candidate in resp.candidates:
if candidate.content and candidate.content.parts:
text_parts.extend(
p.text for p in candidate.content.parts if p.text is not None
)
text = ''.join(text_parts)
return f"""
...
Text:
{text}
...
"""
```
This produces identical output when only text parts are present, and correctly shows an empty string (rather than a warning) when the response is a function call — which is the right behavior for a debug log.
## Files changed
- `src/google/adk/models/google_llm.py` — 10-line change inside `_build_response_log()`, no other logic touched
Co-authored-by: Yifan Wang <wanyif@google.com>
COPYBARA_INTEGRATE_REVIEW=google#6127 from AdeevMardia2008:fix/response-log-text-warning 011c153
PiperOrigin-RevId: 9334408661 parent d9f189c commit f022307
1 file changed
Lines changed: 20 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
614 | 614 | | |
615 | 615 | | |
616 | 616 | | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
617 | 636 | | |
618 | 637 | | |
619 | 638 | | |
620 | 639 | | |
621 | | - | |
| 640 | + | |
622 | 641 | | |
623 | 642 | | |
624 | 643 | | |
| |||
0 commit comments