Skip to content

self.search_memory() method does not work inside an agent #2543

@stepanl-bsy

Description

@stepanl-bsy

Describe the bug
I tried to use self.search_memory() for agent to keep user preferences. I followed the code in ADK docs here in official Google ADK docs website.

To Reproduce
Just copy and paste the first code snippet in the documentation page.

from google.adk.agents import Agent
from google.genai import types

class MyAgent(Agent):
    async def run(self, request: types.Content, **kwargs) -> types.Content:
        # Get the user's latest message
        user_query = request.parts[0].text

        # Search the memory for context related to the user's query
        search_result = await self.search_memory(query=user_query)

        # Create a prompt that includes the retrieved memories
        prompt = f"Based on my memory, here's what I recall about your query: {search_result.memories}\n\nNow, please respond to: {user_query}"

        # Call the LLM with the enhanced prompt
        return await self.llm.generate_content_async(prompt)

The code in the second documentation snippet works correctly (instantiating VertexAiMemoryBankService inside the Agent). I.e. replacing search_result... line above with this snippet fixes the problem.

        # print(f"User query: {user_query}")
        # self.vertexai_memorybank_service = VertexAiMemoryBankService(
        #     project=PROJECT_ID,
        #     location=LOCATION,
        #     agent_engine_id=ENGINE_NAME,  
        # )
        # search_result = await self.vertexai_memorybank_service.search_memory(query=user_query)

Expected behavior
Based on the docs, I expect the self.search_memory() to be able to retrieve user preferences recorded by the runner. The first example in the docs is unable to do that, while the second example does it fine.

Desktop (please complete the following information):

OS: Mac Sequoia 15.4
Python version(python -V): 3.12.15
ADK version(pip show google-adk): 1.10.0
Model Information:
gemini-2.5-flash and VertexAiMemoryBankService (both enterprise)

Metadata

Metadata

Assignees

Labels

bot triaged[Bot] This issue is triaged by ADK botservices[Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions