don't send content with empty text to LLM

PiperOrigin-RevId: 753869699
This commit is contained in:
Xiang (Sean) Zhou 2025-05-01 23:01:18 -07:00 committed by Copybara-Service
parent 6c0a0d69ca
commit d387ab0c38

View File

@ -15,9 +15,7 @@
from __future__ import annotations
import copy
from typing import AsyncGenerator
from typing import Generator
from typing import Optional
from typing import AsyncGenerator, Generator, Optional
from google.genai import types
from typing_extensions import override
@ -202,8 +200,14 @@ def _get_contents(
# Parse the events, leaving the contents and the function calls and
# responses from the current agent.
for event in events:
if not event.content or not event.content.role:
# Skip events without content, or generated neither by user nor by model.
if (
not event.content
or not event.content.role
or not event.content.parts
or event.content.parts[0].text == ''
):
# Skip events without content, or generated neither by user nor by model
# or has empty text.
# E.g. events purely for mutating session states.
continue
if not _is_event_belongs_to_branch(current_branch, event):