From 011c153ebba123f0762d140dbe5ac526c47cd3a2 Mon Sep 17 00:00:00 2001 From: Adeev Mardia Date: Mon, 15 Jun 2026 20:59:55 +0530 Subject: [PATCH] fix: avoid UserWarning in _build_response_log when response has function_call parts --- src/google/adk/models/google_llm.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/google/adk/models/google_llm.py b/src/google/adk/models/google_llm.py index 3c4e4f88eb2..29b14f8b687 100644 --- a/src/google/adk/models/google_llm.py +++ b/src/google/adk/models/google_llm.py @@ -612,11 +612,23 @@ def _build_response_log(resp: types.GenerateContentResponse) -> str: function_calls_text.append( f'name: {func_call.name}, args: {func_call.args}' ) + # Avoid accessing resp.text directly: the genai SDK raises a UserWarning + # whenever .text is accessed on a response that contains non-text parts + # (e.g. function_call). This floods logs on every tool invocation. + # Instead, manually join only the text parts from candidates. + 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""" LLM Response: ----------------------------------------------------------- Text: -{resp.text} +{text} ----------------------------------------------------------- Function calls: {_NEW_LINE.join(function_calls_text)} @@ -676,4 +688,4 @@ def _normalize_base_url_and_api_version( normalized_base_url = urlunparse( parsed_base_url._replace(path='/', params='', query='', fragment='') ) - return normalized_base_url, version_match.group(1) + return normalized_base_url, version_match.group(1) \ No newline at end of file