Skip to content

fix(docs): Await session creation in runner example to prevent ValueError #434

@novoforce

Description

@novoforce

Describe the bug
In the ADK documentation (Python) in the link: https://google.github.io/adk-docs/tools/#example

The code example for using the Runner with InMemorySessionService was missing the necessary async/await structure for creating a session.

This caused the example to fail at runtime with two errors:

  1. A RuntimeWarning: coroutine 'InMemorySessionService.create_session' was never awaited
  2. A subsequent ValueError: Session not found because the session was never actually created.

To Reproduce

Steps to reproduce the behavior:

  1. Go to 'https://google.github.io/adk-docs/tools/#example'
  2. Click on 'Python'
  3. Copy the code and run in a python environment
  4. You will see the above error.

Traceback:
Exception in thread Thread-1 (_asyncio_thread_main):
Traceback (most recent call last):
File "C:\Users\ashis\miniconda3\envs\hack2\lib\threading.py", line 1016, in _bootstrap_inner
self.run()
File "C:\Users\ashis\miniconda3\envs\hack2\lib\threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\ashis\miniconda3\envs\hack2\lib\site-packages\google\adk\runners.py", line 138, in _asyncio_thread_main
asyncio.run(_invoke_run_async())
File "C:\Users\ashis\miniconda3\envs\hack2\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\ashis\miniconda3\envs\hack2\lib\asyncio\base_events.py", line 649, in run_until_complete
return future.result()
File "C:\Users\ashis\miniconda3\envs\hack2\lib\site-packages\google\adk\runners.py", line 126, in _invoke_run_async
async for event in self.run_async(
File "C:\Users\ashis\miniconda3\envs\hack2\lib\site-packages\google\adk\runners.py", line 179, in run_async
raise ValueError(f'Session not found: {session_id}')
ValueError: Session not found: 1234
sys:1: RuntimeWarning: coroutine 'InMemorySessionService.create_session' was never awaited

Expected behavior

The agent response to the hardcoded question in the example:
User Query: weather in london?
Warning: there are non-text parts in the response: ['function_call'], returning concatenated text result from text parts. Check the full candidates.content.parts accessor to get the full model response.
Agent Response: The current weather in London is cloudy with a temperature of 18 degrees Celsius and a chance of rain.

Versions

  • OS: [Windows 11]
  • ADK version: google-adk==1.2.1
  • Python version: 3.10.18

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions