From 7b707cebea00e9e3d46693b406a2ef74836f2147 Mon Sep 17 00:00:00 2001 From: Shangjie Chen Date: Fri, 26 Sep 2025 16:15:15 -0700 Subject: [PATCH] chore: Simplfiy the parallel agent py version handling logic PiperOrigin-RevId: 811992425 --- src/google/adk/agents/parallel_agent.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/google/adk/agents/parallel_agent.py b/src/google/adk/agents/parallel_agent.py index 3f18fd4b..1697c3c3 100644 --- a/src/google/adk/agents/parallel_agent.py +++ b/src/google/adk/agents/parallel_agent.py @@ -188,18 +188,17 @@ class ParallelAgent(BaseAgent): pause_invocation = False try: # TODO remove if once Python <3.11 is no longer supported. - if sys.version_info >= (3, 11): - async with Aclosing(_merge_agent_run(agent_runs)) as agen: - async for event in agen: - yield event - if ctx.should_pause_invocation(event): - pause_invocation = True - else: - async with Aclosing(_merge_agent_run_pre_3_11(agent_runs)) as agen: - async for event in agen: - yield event - if ctx.should_pause_invocation(event): - pause_invocation = True + merge_func = ( + _merge_agent_run + if sys.version_info >= (3, 11) + else _merge_agent_run_pre_3_11 + ) + + async with Aclosing(merge_func(agent_runs)) as agen: + async for event in agen: + yield event + if ctx.should_pause_invocation(event): + pause_invocation = True if pause_invocation: return