Skip to content

Commit b14e3b5

Browse files
committed
Fix for python version <3.11
1 parent 3faa44e commit b14e3b5

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/google/adk/agents/map_agent.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
from typing import Annotated
23
from typing import AsyncGenerator
34

@@ -6,13 +7,16 @@
67
from google.adk.agents.invocation_context import InvocationContext
78
from google.adk.agents.parallel_agent import _create_branch_ctx_for_sub_agent
89
from google.adk.agents.parallel_agent import _merge_agent_run
10+
from google.adk.agents.parallel_agent import _merge_agent_run_pre_3_11
911
from google.adk.events import Event
1012
from google.adk.flows.llm_flows.contents import _should_include_event_in_context
1113
from google.genai import types
1214
from pydantic import Field
1315
from pydantic import RootModel
1416
from typing_extensions import override
1517

18+
from ..utils.context_utils import Aclosing
19+
1620

1721
class MapAgent(BaseAgent):
1822
sub_agents: Annotated[list[BaseAgent], Len(1, 1)] = Field(
@@ -63,10 +67,16 @@ async def _run_async_impl(
6367
for prompt, agent in zip(prompts, sub_agents)
6468
]
6569

66-
async for event in _merge_agent_run(
67-
[ctx.agent.run_async(ctx) for ctx in contexts]
68-
):
69-
yield event
70+
agent_runs = [ctx.agent.run_async(ctx) for ctx in contexts]
71+
72+
merge_func = (
73+
_merge_agent_run
74+
if sys.version_info >= (3, 11)
75+
else _merge_agent_run_pre_3_11
76+
)
77+
async with Aclosing(merge_func(agent_runs)) as agen:
78+
async for event in agen:
79+
yield event
7080

7181
def _extract_input_prompts(
7282
self, ctx: InvocationContext

0 commit comments

Comments
 (0)