diff --git a/src/google/adk/models/google_llm.py b/src/google/adk/models/google_llm.py index e16f09ed4f..8f0311da11 100644 --- a/src/google/adk/models/google_llm.py +++ b/src/google/adk/models/google_llm.py @@ -614,11 +614,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)} @@ -678,4 +690,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