From 2a07eefc27b8f4cde9cfb27c1a9ba5bb0e415d31 Mon Sep 17 00:00:00 2001 From: Alankrit Verma Date: Wed, 28 May 2025 12:57:33 -0700 Subject: [PATCH] chore: Raises error if the last event is partial, which is an unexpected state and can happen when the model output limit is maxed out. Copybara import of the project: -- a6e3a220a507a27523e427e88a803f4fec40db9c by Alankrit Verma : test(base_llm_flow): add test for infinite loop on truncated responses -- b5f2245788b8ed51189d1ad057372989452f070d by Alankrit Verma : feat(base_llm_flow): break run_async loop on partial/truncated events -- cbbae4c468a4de3b5a737aef07cb4615f8418c38 by Wei Sun (Jack) : Raise ValueError if the last event is partial. This is invalid state for llm flow. -- 6eebae0bc27c664eee4743ff7278ae5803415c9f by Wei Sun (Jack) : Delete tests/unittests/flows/llm_flows/test_base_llm_flow_truncation.py -- e08b0ab19ca6eb88eb84f044bf72e815b2cf317c by Wei Sun (Jack) : format base_llm_flow.py COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/659 from AlankritVerma01:fix/522-base-llm-flow-truncation e08b0ab19ca6eb88eb84f044bf72e815b2cf317c PiperOrigin-RevId: 764380150 --- src/google/adk/flows/llm_flows/base_llm_flow.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/google/adk/flows/llm_flows/base_llm_flow.py b/src/google/adk/flows/llm_flows/base_llm_flow.py index 624273c..9b9b156 100644 --- a/src/google/adk/flows/llm_flows/base_llm_flow.py +++ b/src/google/adk/flows/llm_flows/base_llm_flow.py @@ -281,6 +281,12 @@ class BaseLlmFlow(ABC): yield event if not last_event or last_event.is_final_response(): break + if last_event.partial: + # TODO: handle this in BaseLlm level. + raise ValueError( + f"Last event shouldn't be partial. LLM max output limit may be" + f' reached.' + ) async def _run_one_step_async( self,