adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

Streaming tools example in the documentation does not work

Open alvarossl opened this issue 11 months ago • 13 comments

Describe the bug The streaming tool example in https://google.github.io/adk-docs/streaming/streaming-tools/ returns errors on tool invokation.

To Reproduce

Steps to reproduce the behavior: Run adk create streaming-tool-example Take the code from the documentation and replace in agent.py file (adding right imports, API key etc) Run adk web

Error 1 - running the example as is

ValueError: Failed to parse the parameter return_value: AsyncGenerator[str, NoneType] of function monitor_stock_price for automatic function calling.Automatic function calling works best with simpler function signature schema, consider manually parsing your function declaration for function monitor_stock_price.

Error 2 - removing type hinting from the monitor_stock_price function

async def monitor_stock_price(stock_symbol: str) -> AsyncGenerator[str, None]: with async def monitor_stock_price(stock_symbol: str):

Running adk web and requesting the agent eg "provide stock price for GOOGL" returns the following error:

Unable to serialize unknown type: <class 'async_generator'>. TypeError: cannot pickle 'async_generator'

Desktop (please complete the following information):

  • OS: macOS
  • Python version(python -V): Python 3.11.14
  • ADK version(pip show google-adk): 1.21.0 , 1.18.0 (tested both)

Model Information:

  • Are you using LiteLLM: No
  • gemini-2.0-flash-exp

alvarossl avatar Dec 17 '25 18:12 alvarossl

More detail on error 2:

2025-12-18 11:53:36,801 - ERROR - adk_web_server.py:1509 - Error in event_generator: Unable to serialize unknown type: <class 'async_generator'> Traceback (most recent call last): File "/opt/anaconda3/envs/agent-conda/lib/python3.11/site-packages/google/adk/cli/adk_web_server.py", line 1499, in event_generator async for event in agen: File "/opt/anaconda3/envs/agent-conda/lib/python3.11/site-packages/google/adk/runners.py", line 505, in run_async async for event in agen: File "/opt/anaconda3/envs/agent-conda/lib/python3.11/site-packages/google/adk/runners.py", line 493, in _run_with_trace async for event in agen: File "/opt/anaconda3/envs/agent-conda/lib/python3.11/site-packages/google/adk/runners.py", line 769, in _exec_with_plugin await self.session_service.append_event( File "/opt/anaconda3/envs/agent-conda/lib/python3.11/site-packages/google/adk/cli/utils/local_storage.py", line 200, in append_event return await service.append_event(session, event) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/anaconda3/envs/agent-conda/lib/python3.11/site-packages/google/adk/sessions/sqlite_session_service.py", line 392, in append_event event.model_dump_json(exclude_none=True), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/anaconda3/envs/agent-conda/lib/python3.11/site-packages/pydantic/main.py", line 528, in model_dump_json return self.pydantic_serializer.to_json( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pydantic_core._pydantic_core.PydanticSerializationError: Unable to serialize unknown type: <class 'async_generator'>

alvarossl avatar Dec 18 '25 12:12 alvarossl

Hello @alvarossl ,

Thank you for bringing this to our attention. We have reproduced the issue and observed the same error. We are currently investigating it in detail. In the meantime, could you please check if Bidi Streamer meets your requirements?

llalitkumarrr avatar Jan 09 '26 07:01 llalitkumarrr

Hello @llalitkumarrr Jumping right from the ADK community call, did your team already start working on this ? I can have a look as a first issue.

morganroux avatar Jan 21 '26 18:01 morganroux

After investigating, I found the root cause: adk web doesn't call the /run_live endpoint when using text input. As a result, streaming tools are not processed correctly.

Quick workaround: Using the microphone button and speaking to the agent (instead of typing) triggers the correct /run_live endpoint, which properly showcases the example.

Proposed solutions:

  1. Documentation update: Clarify that this example currently only works with the live-audio option, and direct users to the bidi-demo sample for reference.

  2. Feature enhancement: I can dig into implementing text-based live streaming in adk web, similar to how it's done in the bidi-demo, to enable the /run_live endpoint for text input.

What do you think @llalitkumarrr?

morganroux avatar Jan 25 '26 13:01 morganroux

Hello @morganroux ,

Thank you for taking time to dig deep into this, you are welcome to raise PR with your proposed solution. Our team will review it and merge once all checks are cleared.

llalitkumarrr avatar Feb 05 '26 08:02 llalitkumarrr

Hi this PR works to close this issue: #4447

ItsMacto avatar Feb 11 '26 02:02 ItsMacto

Hello @ItsMacto ,

I think this PR needs to be rebased as the branch is currently out of date. Could you please take a look at this?

@ryanaiagent , could you please guide us on the next steps required to merge this?

llalitkumarrr avatar Feb 11 '26 09:02 llalitkumarrr

Hi @llalitkumarrr , Should be up-to-date with main. Thanks

ItsMacto avatar Feb 11 '26 13:02 ItsMacto

Hello @ItsMacto @llalitkumarrr @ryanaiagent I just finished my PR to solve the issue here on adk-web side.

morganroux avatar Feb 14 '26 16:02 morganroux

@llalitkumarrr can you help me to move my adk-web PR forward please ?

morganroux avatar Mar 01 '26 19:03 morganroux

Hello @rohityan ,

Please take a look at this.

llalitkumarrr avatar Mar 16 '26 09:03 llalitkumarrr

This issue has been automatically marked as stale because it has not had recent activity for 7 days after a maintainer requested clarification. It will be closed if no further activity occurs within 7 days.

adk-bot avatar Mar 24 '26 06:03 adk-bot

This has been automatically closed because it has been marked as stale for over 7 days.

adk-bot avatar Mar 31 '26 06:03 adk-bot