File tree Expand file tree Collapse file tree 2 files changed +66
-2
lines changed
src/google/adk/flows/llm_flows
tests/unittests/flows/llm_flows Expand file tree Collapse file tree 2 files changed +66
-2
lines changed Original file line number Diff line number Diff line change @@ -224,7 +224,8 @@ def _contains_empty_content(event: Event) -> bool:
224224
225225 This can happen to the events that only changed session state.
226226 When both content and transcriptions are empty, the event will be considered
227- as empty.
227+ as empty. The content is considered empty if none of its parts contain text,
228+ inline data, file data, function call, or function response.
228229
229230 Args:
230231 event: The event to check.
@@ -239,7 +240,14 @@ def _contains_empty_content(event: Event) -> bool:
239240 not event .content
240241 or not event .content .role
241242 or not event .content .parts
242- or event .content .parts [0 ].text == ''
243+ or all (
244+ not p .text
245+ and not p .inline_data
246+ and not p .file_data
247+ and not p .function_call
248+ and not p .function_response
249+ for p in [event .content .parts [0 ]]
250+ )
243251 ) and (not event .output_transcription and not event .input_transcription )
244252
245253
Original file line number Diff line number Diff line change @@ -465,6 +465,43 @@ async def test_events_with_empty_content_are_skipped():
465465 author = "user" ,
466466 content = types .UserContent ("How are you?" ),
467467 ),
468+ # Event with content that has only empty text part
469+ Event (
470+ invocation_id = "inv6" ,
471+ author = "user" ,
472+ content = types .Content (parts = [types .Part (text = "" )], role = "model" ),
473+ ),
474+ # Event with content that has only inline data part
475+ Event (
476+ invocation_id = "inv7" ,
477+ author = "user" ,
478+ content = types .Content (
479+ parts = [
480+ types .Part (
481+ inline_data = types .Blob (
482+ data = b"test" , mime_type = "image/png"
483+ )
484+ )
485+ ],
486+ role = "user" ,
487+ ),
488+ ),
489+ # Event with content that has only file data part
490+ Event (
491+ invocation_id = "inv8" ,
492+ author = "user" ,
493+ content = types .Content (
494+ parts = [
495+ types .Part (
496+ file_data = types .FileData (
497+ file_uri = "gs://test_bucket/test_file.png" ,
498+ mime_type = "image/png" ,
499+ )
500+ )
501+ ],
502+ role = "user" ,
503+ ),
504+ ),
468505 ]
469506 invocation_context .session .events = events
470507
@@ -478,4 +515,23 @@ async def test_events_with_empty_content_are_skipped():
478515 assert llm_request .contents == [
479516 types .UserContent ("Hello" ),
480517 types .UserContent ("How are you?" ),
518+ types .Content (
519+ parts = [
520+ types .Part (
521+ inline_data = types .Blob (data = b"test" , mime_type = "image/png" )
522+ )
523+ ],
524+ role = "user" ,
525+ ),
526+ types .Content (
527+ parts = [
528+ types .Part (
529+ file_data = types .FileData (
530+ file_uri = "gs://test_bucket/test_file.png" ,
531+ mime_type = "image/png" ,
532+ )
533+ )
534+ ],
535+ role = "user" ,
536+ ),
481537 ]
You can’t perform that action at this time.
0 commit comments