Skip to content

Commit 11037fc

Browse files
DeanChensjcopybara-github
authored andcommitted
chore: Filter event with only functions, thought_signatures when adding to memory
PiperOrigin-RevId: 786825628
1 parent 206a132 commit 11037fc

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/google/adk/memory/vertex_ai_memory_bank_service.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ async def add_session_to_memory(self, session: Session):
6666

6767
events = []
6868
for event in session.events:
69-
if event.content and event.content.parts:
69+
if _should_filter_out_event(event.content):
70+
continue
71+
if event.content:
7072
events.append({
7173
'content': event.content.model_dump(exclude_none=True, mode='json')
7274
})
@@ -150,3 +152,13 @@ def _convert_api_response(api_response) -> Dict[str, Any]:
150152
if hasattr(api_response, 'body'):
151153
return json.loads(api_response.body)
152154
return api_response
155+
156+
157+
def _should_filter_out_event(content: types.Content) -> bool:
158+
"""Returns whether the event should be filtered out."""
159+
if not content or not content.parts:
160+
return True
161+
for part in content.parts:
162+
if part.text or part.inline_data or part.file_data:
163+
return False
164+
return True

tests/unittests/memory/test_vertex_ai_memory_bank_service.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@
4545
author='user',
4646
timestamp=12345,
4747
),
48+
# Function call event, should be ignored
49+
Event(
50+
id='666',
51+
invocation_id='456',
52+
author='agent',
53+
timestamp=23456,
54+
content=types.Content(
55+
parts=[
56+
types.Part(
57+
function_call=types.FunctionCall(name='test_function')
58+
)
59+
]
60+
),
61+
),
4862
],
4963
)
5064

0 commit comments

Comments
 (0)