Getting intermittently RuntimeError for agent deployed on agent engine
** Please make sure you read the contribution guide and file the issues in the right place. ** Contribution guide.
Describe the bug
For few messages I get the output from the remote agent but then starts seeing
RuntimeError: Event loop is closed and then it starts working. Not sure why this intermittent issue and the full stack trace is
DEFAULT 2025-05-31T10:17:27.047532Z Exception in thread Thread-6 (_asyncio_thread_main):
ERROR 2025-05-31T10:17:27.052034Z Traceback (most recent call last): File "/usr/local/lib/python3.11/threading.py", line 1045, in _bootstrap_inner self.run() File "/usr/local/lib/python3.11/threading.py", line 982, in run self._target(*self._args, **self._kwargs) File "/usr/local/lib/python3.11/site-packages/google/adk/runners.py", line 137, in _asyncio_thread_main asyncio.run(_invoke_run_async()) File "/usr/local/lib/python3.11/asyncio/runners.py", line 190, in run return runner.run(main)
DEFAULT 2025-05-31T10:17:27.052042Z ^^^^^^^^^^^^^^^^
DEFAULT 2025-05-31T10:17:27.052047Z File "/usr/local/lib/python3.11/asyncio/runners.py", line 118, in run
DEFAULT 2025-05-31T10:17:27.052203Z return self._loop.run_until_complete(task)
DEFAULT 2025-05-31T10:17:27.052248Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
DEFAULT 2025-05-31T10:17:27.052270Z File "/usr/local/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
DEFAULT 2025-05-31T10:17:27.052727Z return future.result()
DEFAULT 2025-05-31T10:17:27.052850Z ^^^^^^^^^^^^^^^
DEFAULT 2025-05-31T10:17:27.052917Z File "/usr/local/lib/python3.11/site-packages/google/adk/runners.py", line 125, in _invoke_run_async
DEFAULT 2025-05-31T10:17:27.053104Z async for event in self.run_async(
DEFAULT 2025-05-31T10:17:27.053122Z File "/usr/local/lib/python3.11/site-packages/google/adk/runners.py", line 174, in run_async
DEFAULT 2025-05-31T10:17:27.053294Z session = await self.session_service.get_session(
DEFAULT 2025-05-31T10:17:27.053342Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
DEFAULT 2025-05-31T10:17:27.053394Z File "/usr/local/lib/python3.11/site-packages/google/adk/sessions/vertex_ai_session_service.py", line 126, in get_session
DEFAULT 2025-05-31T10:17:27.053661Z get_session_api_response = await self.api_client.async_request(
DEFAULT 2025-05-31T10:17:27.053693Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
DEFAULT 2025-05-31T10:17:27.053719Z File "/usr/local/lib/python3.11/site-packages/google/genai/_api_client.py", line 789, in async_request
DEFAULT 2025-05-31T10:17:27.054117Z result = await self._async_request(http_request=http_request, stream=False)
DEFAULT 2025-05-31T10:17:27.054180Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
DEFAULT 2025-05-31T10:17:27.054205Z File "/usr/local/lib/python3.11/site-packages/google/genai/_api_client.py", line 726, in _async_request
DEFAULT 2025-05-31T10:17:27.054554Z response = await self._async_httpx_client.request(
DEFAULT 2025-05-31T10:17:27.054593Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
DEFAULT 2025-05-31T10:17:27.054622Z File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1540, in request
DEFAULT 2025-05-31T10:17:27.055208Z return await self.send(request, auth=auth, follow_redirects=follow_redirects)
DEFAULT 2025-05-31T10:17:27.055275Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
DEFAULT 2025-05-31T10:17:27.055293Z File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1629, in send
DEFAULT 2025-05-31T10:17:27.056197Z response = await self._send_handling_auth(
DEFAULT 2025-05-31T10:17:27.056218Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
DEFAULT 2025-05-31T10:17:27.056251Z File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1657, in _send_handling_auth
DEFAULT 2025-05-31T10:17:27.056901Z response = await self._send_handling_redirects(
DEFAULT 2025-05-31T10:17:27.056962Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
DEFAULT 2025-05-31T10:17:27.057012Z File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1694, in _send_handling_redirects
DEFAULT 2025-05-31T10:17:27.057813Z response = await self._send_single_request(request)
DEFAULT 2025-05-31T10:17:27.057948Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
DEFAULT 2025-05-31T10:17:27.058024Z File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1730, in _send_single_request
DEFAULT 2025-05-31T10:17:27.058775Z response = await transport.handle_async_request(request)
DEFAULT 2025-05-31T10:17:27.058832Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
DEFAULT 2025-05-31T10:17:27.058861Z File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 394, in handle_async_request
DEFAULT 2025-05-31T10:17:27.059462Z resp = await self._pool.handle_async_request(req)
DEFAULT 2025-05-31T10:17:27.059693Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
DEFAULT 2025-05-31T10:17:27.059728Z File "/usr/local/lib/python3.11/site-packages/httpcore/_async/connection_pool.py", line 256, in handle_async_request
DEFAULT 2025-05-31T10:17:27.060639Z raise exc from None
DEFAULT 2025-05-31T10:17:27.060858Z File "/usr/local/lib/python3.11/site-packages/httpcore/_async/connection_pool.py", line 229, in handle_async_request
DEFAULT 2025-05-31T10:17:27.061754Z await self._close_connections(closing)
DEFAULT 2025-05-31T10:17:27.061996Z File "/usr/local/lib/python3.11/site-packages/httpcore/_async/connection_pool.py", line 345, in _close_connections
DEFAULT 2025-05-31T10:17:27.062489Z await connection.aclose()
DEFAULT 2025-05-31T10:17:27.062648Z File "/usr/local/lib/python3.11/site-packages/httpcore/_async/connection.py", line 173, in aclose
DEFAULT 2025-05-31T10:17:27.063132Z await self._connection.aclose()
DEFAULT 2025-05-31T10:17:27.063220Z File "/usr/local/lib/python3.11/site-packages/httpcore/_async/http11.py", line 258, in aclose
DEFAULT 2025-05-31T10:17:27.063568Z await self._network_stream.aclose()
DEFAULT 2025-05-31T10:17:27.063788Z File "/usr/local/lib/python3.11/site-packages/httpcore/_backends/anyio.py", line 53, in aclose
DEFAULT 2025-05-31T10:17:27.064274Z await self._stream.aclose()
DEFAULT 2025-05-31T10:17:27.064429Z File "/usr/local/lib/python3.11/site-packages/anyio/streams/tls.py", line 216, in aclose
DEFAULT 2025-05-31T10:17:27.064843Z await self.transport_stream.aclose()
DEFAULT 2025-05-31T10:17:27.064918Z File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 1314, in aclose
DEFAULT 2025-05-31T10:17:27.066240Z self._transport.close()
DEFAULT 2025-05-31T10:17:27.066297Z File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 864, in close
DEFAULT 2025-05-31T10:17:27.067127Z self._loop.call_soon(self._call_connection_lost, None)
DEFAULT 2025-05-31T10:17:27.067286Z File "/usr/local/lib/python3.11/asyncio/base_events.py", line 762, in call_soon
DEFAULT 2025-05-31T10:17:27.067915Z self._check_closed()
DEFAULT 2025-05-31T10:17:27.067971Z File "/usr/local/lib/python3.11/asyncio/base_events.py", line 520, in _check_closed
DEFAULT 2025-05-31T10:17:27.068545Z raise RuntimeError('Event loop is closed')
DEFAULT 2025-05-31T10:17:28.099690Z RuntimeError: Event loop is closed
To Reproduce Steps to reproduce the behavior: My AdkApp requirement looks like:
requirements=[ "google-adk (==1.0.0)", "google-genai (==1.16.1)", "pydantic (>=2.10.6,<3.0.0)", "absl-py (>=2.2.1,<3.0.0)", "requests (>=2.32.3,<3.0.0)", "aiohttp (==3.10.11)", "google-cloud-aiplatform (==1.95.1)" ]
Hi @bipulkarnani , this should be resolved in ADK 1.1.0.