chore: Filter event with only functions, thought_signatures when adding to memory

PiperOrigin-RevId: 786825628
This commit is contained in:
Shangjie Chen
2025-07-24 13:54:37 -07:00
committed by Copybara-Service
parent 206a13271e
commit 11037fc133
2 changed files with 27 additions and 1 deletions
@@ -66,7 +66,9 @@ class VertexAiMemoryBankService(BaseMemoryService):
events = []
for event in session.events:
if event.content and event.content.parts:
if _should_filter_out_event(event.content):
continue
if event.content:
events.append({
'content': event.content.model_dump(exclude_none=True, mode='json')
})
@@ -150,3 +152,13 @@ def _convert_api_response(api_response) -> Dict[str, Any]:
if hasattr(api_response, 'body'):
return json.loads(api_response.body)
return api_response
def _should_filter_out_event(content: types.Content) -> bool:
"""Returns whether the event should be filtered out."""
if not content or not content.parts:
return True
for part in content.parts:
if part.text or part.inline_data or part.file_data:
return False
return True
@@ -45,6 +45,20 @@ MOCK_SESSION = Session(
author='user',
timestamp=12345,
),
# Function call event, should be ignored
Event(
id='666',
invocation_id='456',
author='agent',
timestamp=23456,
content=types.Content(
parts=[
types.Part(
function_call=types.FunctionCall(name='test_function')
)
]
),
),
],
)