adk-java icon indicating copy to clipboard operation
adk-java copied to clipboard

VertexAiMemoryBankService

Open alexanoid opened this issue 1 year ago • 6 comments

I’m interested in using VertexAiMemoryBankService for long-term memory when working with an agent through ADK. I see that the VertexAiMemoryBankService https://github.com/google/adk-python/blob/632bf8b0bcf18ff4e4505e4e5f4c626510f366a2/src/google/adk/memory/vertex_ai_memory_bank_service.py#L38 is implemented in the Python version of ADK, but it’s not yet available in the Java version.

By analogy with the Python version, I can implement my own Java version of VertexAiMemoryBankService (implements BaseMemoryService). I can also create a custom version of VertexAiRunner based on com.google.adk.runner.Runner#Runner(com.google.adk.agents.BaseAgent, java.lang.String, com.google.adk.artifacts.BaseArtifactService, com.google.adk.sessions.BaseSessionService, com.google.adk.memory.BaseMemoryService).

My question is the following: is it enough to simply implement my own version of VertexAiMemoryBankService and pass it into the Runner constructor, since the Java ADK already has the functionality for working with long-term memory implemented at this point? In other words, does the Java ADK already know how to add and retrieve the necessary information from memory by itself for LlmAgent? Or, apart from implementing my own VertexAiMemoryBankService and passing it to the Runner constructor, would I need to do anything else to make it work? What is the current state of this memory-related functionality as of now?

It seems to me that, in addition to providing the VertexAiMemoryBankService to the agent, I also need to provide the search_memory tool (so that the agent can search the memory by itself) and add a callback for writing to the Memory Bank after each user prompt and LLM response using after_agent_callback=[auto_save_to_memory_callback]? Both, and both the search_memory tool and the auto_save_to_memory_callback should internally use the corresponding methods from VertexAiMemoryBankService, right?

alexanoid avatar Sep 20 '25 18:09 alexanoid

Your assessment is largely correct. We actually provide a LoadMemory tool already which you can just include in your agent's tools, but the saving logic is expected to be managerd by the user

Poggecci avatar Sep 23 '25 18:09 Poggecci

Thanks for the info. I was looking at this too. I was currently using the adk-python version. The only confusing thing is that the documentation clearly states that writing to memory happens automatically:

Generating Memories: At the end of a conversation, the ADK sends the session's events to the Memory Bank, which intelligently processes and stores the information as "memories."

With the service configured, the ADK automatically saves session data to the Memory Bank. To make your agent use this memory, you need to call the search_memory method from your agent's code

However, when I tried to test it, unfortunately, nothing was written. I had to write my own callback (after_agent_callback) to save the session into the memory. If writing to memory is to be a manual operation (managed by the user), the documentation needs to be updated so that it does not mislead other people.

pwiecek avatar Oct 04 '25 16:10 pwiecek

@Poggecci I have an additional question — is it possible to use VertexAiSessionService and VertexAiMemoryBankService without creating an Vertex AI Agent Engine instance? I don’t need to host my agent — I’m running it myself in Docker. I only need the functionality for storing sessions and memory (Memory Bank Service). Can my AI Agent written with ADK Java somehow access these services without creating an Agent Engine instance?

alexanoid avatar Oct 08 '25 12:10 alexanoid

@Poggecci could comment more, but it seems like it's required. VertexAiSessionService and VertexAiMemoryBankService are integral parts of Agent Engine and probably can't run separately (without having an instance). More here.

pwiecek avatar Oct 08 '25 13:10 pwiecek

@Poggecci could comment more, but it seems like it's required. VertexAiSessionService and VertexAiMemoryBankService are integral parts of Agent Engine and probably can't run separately (without having an instance). More here.

Thank you for your response. It looks like this setup is a bit excessive for my use case, and I’ll probably need to look into alternative solutions for memory — for example, https://github.com/mem0ai/mem0

alexanoid avatar Oct 08 '25 13:10 alexanoid

Is pricing already available for these two services (session and memory)? It is probably general for compute and memory resources used by the agents that are deployed to the Agent Engine managed Runtime

pwiecek avatar Oct 08 '25 13:10 pwiecek