feat: add live_bidi_streaming_demo_app sample - #6493
Closed
kazunori279 wants to merge 1 commit into
Closed
Conversation
Add a standalone FastAPI application demonstrating the full ADK bidirectional streaming lifecycle over a WebSocket, with a browser UI for text, voice, and camera input. Unlike the other samples under contributing/samples/live/, this one does not run under `adk web`. It owns its own Runner, LiveRequestQueue, and run_live() loop, so it shows what an application built directly on ADK's streaming primitives looks like end to end: application initialization, per-connection session initialization, concurrent upstream/downstream tasks, and termination. The bundled UI renders every raw ADK Event as it arrives, which makes it useful for inspecting Live API behavior. This app is the reference implementation for the Gemini Live API Toolkit development guide at https://adk.dev/streaming/dev-guide/part1/, which walks through its source line by line. It was previously published under google/adk-samples and is being moved here so the guide references live alongside the ADK source.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a standalone FastAPI application demonstrating the full ADK bidirectional streaming lifecycle over a WebSocket, with a browser UI for text, voice, and camera input.
Unlike the other samples under
contributing/samples/live/, this one does not run underadk web. It owns its ownRunner,LiveRequestQueue, andrun_live()loop, so it shows what an application built directly on ADK's streaming primitives looks like end to end:Agent,SessionService,RunnerSession,RunConfig,LiveRequestQueue, startrun_live()LiveRequestQueuein afinallyblockThe bundled UI renders every raw ADK
Eventas it arrives, which makes it useful for inspecting Live API behavior directly.Why here
This app is the reference implementation for the Gemini Live API Toolkit development guide, which walks through its source line by line with 36 pinned line-level references. It is currently published under
google/adk-samples; moving it here keeps the guide's references alongside the ADK source they explain. The docs will be re-pointed at this path once this merges.Only the minimum set needed to run and to satisfy those references is included. Deliberately excluded, since
contributing/README.mdscopes samples as "minimal and simplistic":Dockerfile, Agent Engine deployment scripts,pyproject.toml/uv.lock, and the test suite.Testing Plan
Tested against ADK 2.5.0 on Vertex AI with
gemini-live-2.5-flash-native-audioinus-east1.Automated
An 8-test suite (kept in the source repo, not shipped here) spawns the real uvicorn server and talks to the real Live API. 8/8 pass, 33.9s.
/servesindex.html; static JS/CSS return 200outputTranscription+turnCompleteinputTranscriptionand a matching reply{"type":"image"}, then a prompt about itexecutableCode/functionCall/webSearchQueries/groundingChunks?proactivity=true&affective_dialog=trueaccepted and appliedsession_idreuses the sessionLiveRequestQueuewith no unhandled errorBrowser
Chrome DevTools MCP: page loads, WebSocket auto-connects, a text turn produced the expected reply with streaming output transcription, token usage, and turn-complete events; with "Show audio" enabled the console showed
audio/pcmresponse frames. 0ERRORlines in the server log across the session; the only console error is afavicon.ico404. Teardown logged the clean sequence (Client disconnected→Closing live_request_queue).In place, from this path
Ran
uvicorn main:appfromcontributing/samples/live/live_bidi_streaming_demo_app/app/to confirm thegoogle_search_agentimport and static paths resolve here, then drove one live WebSocket turn against it — 3 audio parts returned, transcript"4"for "What is 2 plus 2?".Lint
pre-commit run --files <all 13 files>— all hooks pass (isort, pyink, addlicense, ADK Compliance Checks, mdformat, codespell, whitespace).Not covered
The Gemini API (non-Vertex) path is untested — no API key was available on the test machine. The code path differs only in which env vars
load_dotenv()supplies togoogle-genai.Notes for reviewers
agentvsroot_agent. Sibling live samples exportroot_agentbecause they load underadk web. This one is a standalone app that imports the symbol itself, and it exportsagentto stay consistent with the published guide's code snippets. Happy to rename if you'd prefer uniformity — it would mean a follow-up docs update.AUDIOresponse modality with transcription in both directions. Half-cascade support was removed during testing because no half-cascade model was reachable (gemini-live-2.5-flashserves only fromglobal;gemini-2.0-flash-live-001only fromus-east1)..env.example, not.env. The repo.gitignoreblocks.env, so setup iscp .env.example app/.env.