mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
chore: Filter event with only functions, thought_signatures when adding to memory
PiperOrigin-RevId: 786825628
This commit is contained in:
committed by
Copybara-Service
parent
206a13271e
commit
11037fc133
@@ -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')
|
||||
)
|
||||
]
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user