fix(tools): use full query text and own logger in PreloadMemoryTool - #6885
Open
chelsealong wants to merge 1 commit into
Open
fix(tools): use full query text and own logger in PreloadMemoryTool#6885chelsealong wants to merge 1 commit into
chelsealong wants to merge 1 commit into
Conversation
PreloadMemoryTool only read the search query from the first content part, so a leading non-text part (a file/image, or a placeholder text part some providers require) either skipped the search entirely or searched memory using the placeholder instead of the user's actual question. Join text across all parts, matching the same idiom already used on the memory-rendering side in _memory_entry_utils.extract_text. Also log retrieval failures through the module's own google_adk logger instead of the root logger, so operators who configure logging by the google_adk namespace can observe and alert on a failing memory backend instead of it looking identical to "no memories matched". Fixes google#6884
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6884
Problem
PreloadMemoryTool.process_llm_requestinpreload_memory_tool.pyhad two issues, both present onmain:user_content.parts[0].text. If the first content part is non-text (a file, image, or a placeholder text part some LLM providers require ahead of a non-text part), the tool either returns early and never searches memory, or searches memory using the placeholder text instead of the user's actual question. The memory-rendering side of the same file (_memory_entry_utils.extract_text) already joins text across all parts — only the query-building side didn't.search_memorycall was logged via the rootloggingmodule instead of the module's owngoogle_adk.*logger, so applications that configure logging by thegoogle_adknamespace never see the failure. Combined with (1)'s silent early return, a memory backend that is down or misconfigured is indistinguishable from "no memories matched".Fix
user_content, mirroring the existingextract_textidiom, instead of only looking atparts[0].logger(google_adk.<module>) instead of the rootloggingmodule.This keeps the existing fail-open behavior (per #3069) — retrieval failures still don't raise — but they are now observable through the correct logger, and the query no longer silently drops or mis-targets when the first part isn't text.
Test plan
Added two tests to
tests/unittests/tools/test_preload_memory_tool.py:test_preload_memory_uses_text_from_every_part— a leading empty-text part must not blank out the real query in a later part.test_preload_memory_logs_search_failure_on_own_logger— a retrieval failure must be observable on thegoogle_adklogger.Verified both fail without the fix (reverted
preload_memory_tool.pyto the pre-fix version and reran):With the fix restored, the full file passes:
Also ran the broader
toolssuite filtered onpreload(7 passed, no regressions), and formatted withisort/pyinkperCONTRIBUTING.md.AI assistance disclosure
This change was written with the assistance of an AI coding agent (Claude), with the diff reviewed and tests verified by the submitter before opening this PR.