Repository navigation
Conversation
VertexAiMemoryBankService sent each event's content to memories.generate as is, so parts marked thought: true reached Memory Bank, and an event with only text thoughts was sent too. Memory Bank could then build memories from the model's reasoning. Drop the thought parts with pruneThoughts before the empty-event check and before building the request, as adk-python does.
Contributor
|
Hi @gjija, thank you for raising the PR to fix the issue. We have reviewed the code changes and it does resolve the issue. |
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
shouldFilterOutEvent; its description saysthoughtparts stay excluded)2. Or, if no issue exists, describe the change:
Problem:
VertexAiMemoryBankService.addSessionToMemoryandaddEventsToMemorysend each event's content tomemories.generateas it is. With a thinking model andthinkingConfig: {includeThoughts: true}, session events keep the model's thought parts (thought: true), so they reach Memory Bank, and Memory Bank can build memories from the model's reasoning. An event whose only part is a text thought is sent too.shouldFilterOutEventdoes not look atthought: it skips an event only when no part has text or data, and otherwise the content is sent whole, so text thoughts got through.Example: a model event with parts
[{text: 'The user may live in Paris.', thought: true}, {text: 'Try Lisbon.'}]plus an event with only{text: 'Thinking only.', thought: true}. Onmainthe request carries both thoughts:Solution:
Run each event through the existing
pruneThoughtshelper (events/event.ts) first, and use that content for both the empty-event check and the request.pruneThoughtsreturns a copy, so the caller's event is not changed. An event left with no parts is skipped, as before.This matches adk-python, where
_without_thoughtsinmemory/vertex_ai_memory_bank_service.pyis used in_should_filter_out_eventand on both write paths (generate and ingest). It landed in google/adk-python#7851. The new comment follows that helper's docstring.What changes for users: Memory Bank no longer gets thought parts, and an event with only text thoughts is not sent. If a batch holds nothing else,
generateis not called and "No events to add to memory." is logged, as for any empty batch.Testing Plan
Unit Tests:
New test in
core/test/memory/vertex_ai_memory_bank_service_test.ts, next to "still filters out an event whose only part is a thought": "leaves the model thought parts out of the events it sends". It sends the two events above and expects only[{text: 'Try Lisbon.'}]in the request, and checks that the caller's event still has 2 parts.addEventsToMemorygoes through the same function.Without the source change,
vertex_ai_memory_bank_service_test.tsfails (1 failed | 48 passed): the request still carries both thought parts, as shown above. With it:Full unit run (
npx vitest run --project unit:core --project unit:dev --project unit:integrations): all tests pass except the two streaming tests incore/test/a2a/remote_agent_test.ts, which fail only because they resolveexample.comand this machine has no outside network.dev/test/utils/agent_loader_test.tsdoes not load without a builtdist/, so its tests were skipped.prettier --check,eslintandtsc --noEmit -p coreare clean.Manual End-to-End (E2E) Tests:
Not run against a real Memory Bank: I have no Vertex AI project for it. The unit test above stands in. It checks the exact
directContentsSourceevents passed to the mockedmemories.generateInternal.Checklist
Additional context
The same gap exists in the other two memory services, which I left for separate PRs so each change comes with its own test: the RAG memory transcript (
serializeSessionTranscriptinrag_memory_transcript.ts) andInMemoryMemoryService.searchMemory. adk-python filters thoughts in both.