Skip to content

Commit b170a84

Browse files
DeanChensjcopybara-github
authored andcommitted
chore: Handle exception in preload_memory_tool to not fail the llm request
Resolves #3069 PiperOrigin-RevId: 814391260
1 parent 5b8d523 commit b170a84

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/google/adk/tools/preload_memory_tool.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from __future__ import annotations
1616

17+
import logging
1718
from typing import TYPE_CHECKING
1819

1920
from typing_extensions import override
@@ -25,6 +26,8 @@
2526
if TYPE_CHECKING:
2627
from ..models import LlmRequest
2728

29+
logger = logging.getLogger('google_adk.' + __name__)
30+
2831

2932
class PreloadMemoryTool(BaseTool):
3033
"""A tool that preloads the memory for the current user.
@@ -56,7 +59,12 @@ async def process_llm_request(
5659
return
5760

5861
user_query: str = user_content.parts[0].text
59-
response = await tool_context.search_memory(user_query)
62+
try:
63+
response = await tool_context.search_memory(user_query)
64+
except Exception:
65+
logging.warning('Failed to preload memory for query: %s', user_query)
66+
return
67+
6068
if not response.memories:
6169
return
6270

0 commit comments

Comments
 (0)