Skip to content

fix(live): give plain tools the input stream they declare - #8159

Open
he-yufeng wants to merge 1 commit into
google:mainfrom
he-yufeng:fix/live-input-stream-for-plain-tools
Open

he-yufeng wants to merge 1 commit into
google:mainfrom
he-yufeng:fix/live-input-stream-for-plain-tools

Conversation

@he-yufeng

Copy link
Copy Markdown
Contributor

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

Problem:

A live tool that declares input_stream: LiveRequestQueue receives that stream only when it is an async generator. A tool that watches the user's audio or video and answers with a single value gets no stream, so the call fails with TypeError: describe_scene() missing 1 required positional argument: 'input_stream' and the model is told the tool failed with an internal error. A NON_BLOCKING tool never gets a stream either. The model cannot supply the argument itself, because input_stream is always excluded from the function declaration.

Solution:

Decide whether to create the stream from the signature alone, which is what _new_input_stream already checks, instead of from is_generator. Both launch paths now register it: _launch_function_call_live and _launch_non_blocking_call_live.

is_generator keeps its current meaning. Teardown, stop_streaming and wait_for_tool_calls read it to decide whether a call runs until stopped, and a tool that returns once still finishes on its own, so none of that changes. Each call still gets its own queue, and the entry is still retired in the call's finally, so a finished call stops collecting the user's input.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Five tests, all failing before the change and passing after:

tests/unittests/flows/llm_flows/tools/test_live_caller.py

  • test_plain_tool_declaring_an_input_stream_receives_one
  • test_non_blocking_tool_declaring_an_input_stream_receives_one
  • test_parallel_plain_calls_each_get_their_own_stream

tests/unittests/streaming/test_live_tool_shutdown.py

  • test_tool_that_returns_once_still_receives_live_input — a full run_live turn: the tool reads what the user sends while it runs and answers once.
  • test_finished_tool_stops_receiving_live_input — after the answer, 25 more audio chunks are sent and the call is no longer registered, so its queue is not left growing for the rest of the session.
$ pytest tests/unittests/flows/llm_flows/tools/test_live_caller.py \
         tests/unittests/streaming/test_live_tool_shutdown.py -q
52 passed, 6 warnings in 8.18s

Wider regression run over the live and tool-calling suites:

$ pytest tests/unittests/streaming tests/unittests/live \
         tests/unittests/flows/llm_flows/tools -q
737 passed, 153 warnings, 1 error in 429.46s

The one error and two excluded modules are environment gaps in my local venv, present before this change and unrelated to it: test_live_streaming_configs.py::test_streaming_default_model_when_not_specified needs the pytest-mock mocker fixture, and test_audio_transcriber.py / test_rearranger.py import anthropic, which I do not have installed. CI covers all three.

Before the change, with only the tests applied:

FAILED test_live_caller.py::test_plain_tool_declaring_an_input_stream_receives_one
FAILED test_live_caller.py::test_non_blocking_tool_declaring_an_input_stream_receives_one
FAILED test_live_caller.py::test_parallel_plain_calls_each_get_their_own_stream
FAILED test_live_tool_shutdown.py::test_tool_that_returns_once_still_receives_live_input
FAILED test_live_tool_shutdown.py::test_finished_tool_stops_receiving_live_input

Manual End-to-End (E2E) Tests:

The two run_live tests above drive the real runner, live request queue and background-tool registry against the in-repo mock live connection, so no API key or model endpoint is involved. The agent is:

async def describe_scene(input_stream: LiveRequestQueue) -> dict[str, str]:
  request = await input_stream.get()
  return {'scene': 'described'}

root_agent = Agent(name='root_agent', tools=[describe_scene])

Before the change the model receives {'error': 'Invoking describe_scene() failed with an internal error.'}; after it, {'scene': 'described'}.

I have not run this against a real Gemini Live endpoint, so the device-level audio path is unverified. The failure and the fix are both in how ADK builds the call arguments, which the mock connection exercises in full.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

pyink 25.12, isort 8.0.1, ruff 0.15.17 and scripts/compliance_checks.py are clean on the three changed files.

The docs describe this parameter under streaming tools (runner live guide). Once this lands I will open an adk-docs PR to say that any live tool may declare it, not only async generators.

A live tool that declares `input_stream: LiveRequestQueue` only got one
when it was an async generator, so a tool that reads the user's audio or
video and answers with a single value failed with a missing-argument
TypeError. Create the stream from the signature alone, on both the
per-call and the non-blocking launch path. `is_generator` keeps its
current meaning, so teardown and stop_streaming are unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

run_live: a tool that declares input_stream only receives it when written as an async generator

2 participants