Skip to content

Commit c84c17a

Browse files
google-genai-botcopybara-github
authored andcommitted
feat: Added Log info when agent run is cancelled and log warning if putting sentinel on queue fails during cleanup avoiding silent error suppression
PiperOrigin-RevId: 939668348
1 parent 50c81eb commit c84c17a

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/google/adk/agents/parallel_agent.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from __future__ import annotations
1818

1919
import asyncio
20+
import logging
2021
import sys
2122
from typing import AsyncGenerator
2223
from typing import ClassVar
@@ -32,6 +33,8 @@
3233
from .invocation_context import InvocationContext
3334
from .parallel_agent_config import ParallelAgentConfig
3435

36+
logger = logging.getLogger('google_adk.' + __name__)
37+
3538

3639
def _create_branch_ctx_for_sub_agent(
3740
agent: BaseAgent,
@@ -65,9 +68,15 @@ async def process_an_agent(events_for_one_agent):
6568
await queue.put((event, resume_signal))
6669
# Wait for upstream to consume event before generating new events.
6770
await resume_signal.wait()
71+
except asyncio.CancelledError:
72+
logger.info('Agent run cancelled.')
73+
raise
6874
finally:
6975
# Mark agent as finished.
70-
await queue.put((sentinel, None))
76+
try:
77+
await queue.put((sentinel, None))
78+
except Exception as e:
79+
logger.warning('Failed to put sentinel on queue: %s', e)
7180

7281
async with asyncio.TaskGroup() as tg:
7382
for events_for_one_agent in agent_runs:

0 commit comments

Comments
 (0)