NavigoAI_Voice_Agent_ADk

mcp
Guvenlik Denetimi
Basarisiz
Health Uyari
  • No license — Repository has no license file
  • Description — Repository has a description
  • Active repo — Last push 0 days ago
  • Community trust — 21 GitHub stars
Code Basarisiz
  • Hardcoded secret — Potential hardcoded credential in server/streaming_service.py
Permissions Gecti
  • Permissions — No dangerous permissions requested

Bu listing icin henuz AI raporu yok.

SUMMARY

Real-time voice travel agent on Gemini native audio + Google ADK, with Google Search and Maps MCP tools.

README.md

NaviGo AI: Real-Time Voice Travel Agent with Gemini & Google ADK

A voice-first travel assistant that streams live audio between the browser and Gemini's native-audio model through the Google Agent Development Kit (ADK), with Google Search and Google Maps (MCP) tools.

Python
Google ADK
Gemini
WebSockets
MCP
JavaScript

[!NOTE]
Featured on the Google Cloud Blog: Build a real-time voice agent with Gemini & ADK. The full walkthrough is also in docs/blog.md.


📖 Overview

Classic voice assistants chain Speech-to-Text, an LLM and Text-to-Speech. Each hop adds latency and strips out tone. NaviGo AI uses Gemini's native-audio model end to end: raw microphone audio goes to the model and spoken audio comes back over one bidirectional ADK session. The agent answers general travel questions with Google Search and route or location questions with the Google Maps MCP server (@modelcontextprotocol/server-google-maps).

🧭 What I built, step by step

  1. Agent. An ADK Agent with the NaviGo AI travel persona (SYSTEM_INSTRUCTION in core_utils.py). Model and voice come from MODEL and VOICE_NAME so I can swap native-audio models without touching code.
  2. Tools. ADK's built-in google_search for open travel questions, plus an MCPToolset that launches the Google Maps MCP server over stdio via npx. Using MCP meant I got directions and place lookups without writing a Maps client.
  3. WebSocket server. BaseStreamServer (websockets, port 8080) accepts browser connections and sends a ready message once the session is up.
  4. Live session. Each connection gets its own InMemorySessionService session, a LiveRequestQueue, and Runner.run_live with StreamingMode.BIDI, response_modalities=["AUDIO"] and input/output transcription enabled.
  5. Concurrent pipeline. An asyncio.TaskGroup per client runs four tasks: receive client messages, forward audio, forward JPEG frames, and relay model audio, transcripts, interrupted and turn_complete events. Separating them keeps playback flowing while the user is still talking, which is what makes barge-in work.
  6. Browser client. sound_handler.js captures the mic as 16 kHz PCM16 and plays 24 kHz PCM back, stopping playback on interrupted. stream_manager.js adds webcam and screen-frame capture. interface.html shows the live transcript.
  7. Write-up. I wrote the build guide that ran on the Google Cloud Blog (docs/blog.md).

🏗️ Architecture

Target architecture on Google Cloud. Run locally today; this is the production target.

Target architecture on Google Cloud

  • Gemini Live API (Vertex AI or Gemini API): receives the 16 kHz PCM stream and returns 24 kHz speech plus transcripts. google_search runs as Gemini grounding.
  • Cloud Run: hosts server/streaming_service.py (WebSocket on :8080, Runner.run_live in BIDI mode), with the Maps MCP server launched in the same container via npx.
  • HTTPS Load Balancer + Cloud Storage: terminates TLS for wss:// traffic (optionally behind IAP) and serves the static client/ files.
  • Secret Manager + IAM service account: injects GOOGLE_MAPS_API_KEY at runtime; a least-privilege service account calls Vertex AI.
  • Cloud Build + Artifact Registry: build, store and deploy the container image.
  • Cloud Logging + Cloud Monitoring: server logs, session errors, latency and connection metrics.

Diagram source: docs/architecture/gcp_architecture.py, rendered with diagrams.

Request flow

sequenceDiagram
    participant U as User (browser)
    participant C as Client JS
    participant S as StreamingService
    participant A as ADK Runner / Agent
    participant G as Gemini Live
    participant T as Tools (Search / Maps MCP)

    C->>S: WebSocket connect
    S-->>C: {"type": "ready"}
    U->>C: Click mic & speak
    loop While recording
        C->>S: {"type": "audio", "data": base64 PCM 16 kHz}
        S->>A: LiveRequestQueue.send_realtime(Blob)
        A->>G: Stream audio
    end
    G-->>A: Tool call (optional)
    A->>T: google_search / Maps MCP
    T-->>A: Result
    G-->>A: Audio chunks + transcriptions
    A-->>S: Live events
    S-->>C: audio / text / user_transcript
    C-->>U: Play 24 kHz audio, show transcript
    S-->>C: turn_complete or interrupted

✨ Key Features

  • Native-audio conversation with a configurable prebuilt voice.
  • Bidirectional streaming through Runner.run_live, StreamingMode.BIDI and a LiveRequestQueue.
  • Live transcription of both sides, sent to the UI as user_transcript and text messages.
  • Barge-in: the server forwards interrupted events and the client stops playback.
  • Tool use mid-conversation: google_search plus the Google Maps MCPToolset.
  • Multimodal input: the server accepts JPEG frames (type: "video"). stream_manager.js has webcam and screen-share capture; the default UI doesn't expose a button for it.
  • Session resumption handles are forwarded to the client as session_id messages when Gemini issues them.

🧰 Tech Stack

Layer Technology
Agent framework Google ADK (google-adk)
Model Gemini 2.5 Flash native audio (set via MODEL)
Tools ADK google_search, Google Maps MCP server
Server Python 3.11+, asyncio, websockets, python-dotenv
Client HTML, Tailwind CSS (CDN), vanilla JavaScript, Web Audio API, MediaDevices API

📁 Repository Structure

.
├── client/
│   ├── interface.html        # UI: mic button, transcript, audio indicator
│   ├── sound_handler.js      # WebSocket client, mic capture (16 kHz), playback (24 kHz)
│   └── stream_manager.js     # Adds webcam/screen frame streaming
├── server/
│   ├── core_utils.py         # Env config, system instruction, BaseStreamServer
│   ├── streaming_service.py  # Agent, tools, live session and streaming tasks (entry point)
│   ├── requirements.txt
│   ├── start_servers.sh
│   └── .env.example
├── docs/
│   ├── architecture/         # GCP diagram and its source
│   └── blog.md               # Build guide
└── README.md

🚀 Getting Started

Prerequisites

  • Python 3.11+ (the server uses asyncio.TaskGroup)
  • Node.js with npx, to launch the Maps MCP server
  • A Gemini API key from Google AI Studio, or a Google Cloud project with Vertex AI enabled
  • A Google Maps Platform API key
  • A browser with microphone access

1. Clone and install

git clone https://github.com/Ashwinikumar1/NavigoAI_Voice_Agent_ADk.git
cd NavigoAI_Voice_Agent_ADk/server

python3 -m venv .venv
source .venv/bin/activate        # Windows: .venv\Scripts\activate
pip install -r requirements.txt

2. Configure environment variables

cp .env.example .env
Variable Used by Description
GOOGLE_API_KEY google-genai SDK Gemini API key (when GOOGLE_GENAI_USE_VERTEXAI=FALSE)
GOOGLE_GENAI_USE_VERTEXAI google-genai SDK FALSE for Gemini API key, TRUE for Vertex AI
GOOGLE_CLOUD_PROJECT, GOOGLE_CLOUD_LOCATION google-genai SDK Vertex AI only
MODEL core_utils.py Native-audio model, e.g. gemini-2.5-flash-preview-native-audio-dialog
VOICE_NAME core_utils.py Prebuilt voice, e.g. Puck
PROJECT_ID, LOCATION core_utils.py Project and region
GOOGLE_MAPS_API_KEY streaming_service.py Passed to the Maps MCP server

server/.env is git-ignored. Keep it that way.

3. Run the server

./start_servers.sh          # or: python3 streaming_service.py

The server listens on ws://localhost:8080.

4. Open the client

Open client/interface.html directly, or serve it with python3 -m http.server -d client 5500 and visit http://localhost:5500/interface.html. The page connects to ws://localhost:8080 on load.

💬 Usage

  1. Click the mic button and allow microphone access.
  2. Ask a travel question:
    • "What are the must-see places in Jaipur for a weekend trip?" uses Google Search.
    • "How long does it take to drive from Bangalore to Mysore?" uses Google Maps MCP.
  3. NaviGo AI answers out loud while the transcript fills in. Speak over it to interrupt.

To change behaviour, edit SYSTEM_INSTRUCTION in server/core_utils.py. To change tools or the port, edit Agent(tools=[...]) and StreamingService(host="0.0.0.0", port=8080) in server/streaming_service.py; update the URL in client/interface.html if the port changes.

WebSocket message protocol

Direction type Payload
Client → Server audio base64 PCM16, 16 kHz
Client → Server video base64 JPEG frame, mode: webcam / screen
Client → Server end / text turn end marker / text (logged)
Server → Client ready sent on connect
Server → Client audio base64 PCM, 24 kHz
Server → Client text / user_transcript model / user transcription chunks
Server → Client interrupted / turn_complete turn state
Server → Client session_id session resumption handle

🔐 Security

  • Secrets: API keys live in server/.env; server/.env.example holds placeholders. In production, put GOOGLE_MAPS_API_KEY in Secret Manager and use Vertex AI with a service account instead of a Gemini API key.
  • Least privilege: run Cloud Run as a dedicated service account with only roles/aiplatform.user and roles/secretmanager.secretAccessor on the needed secrets. Restrict the Maps key by API and referrer or IP.
  • Endpoint auth: the local WebSocket is unauthenticated ws://. In production, serve wss:// behind an HTTPS load balancer, validate an IAP or ID token on connect, and enforce an Origin allow-list.
  • Input validation: check message type, cap payload size and rate per connection, and reject malformed base64 before it reaches the model.
  • Voice data: audio and transcripts are held in memory only. Don't log raw audio or transcripts, and tell users they are being recorded.
  • Tool guardrails: treat search results and Maps data as untrusted. Keep tools read-only and use ADK before_tool_callback or model callbacks to filter arguments and responses.
  • Audit logging: enable Cloud Audit Logs for Vertex AI and Secret Manager; log connection and session IDs, not content.

🚢 Path to Production

  • Deploy: containerize server/ (Python plus Node.js for npx) and deploy to Cloud Run with session affinity, long request timeouts for WebSockets, and min instances to avoid cold starts. Serve client/ from Cloud Storage or Firebase Hosting.
  • CI/CD: a Cloud Build trigger runs lint and tests, pushes the image to Artifact Registry, and deploys with staged traffic splitting.
  • State: swap InMemorySessionService for a persistent session service so sessions survive across instances.
  • Observability: structured logs in Cloud Logging; time-to-first-audio, interruption and tool-error metrics in Cloud Monitoring; traces in Cloud Trace.
  • Evaluation: an ADK eval set of travel queries that checks tool choice (Search vs Maps), grounding and persona before each release.
  • Scaling and cost: every connection holds a long-lived Live session. Set per-instance concurrency, max session length and idle timeouts, and put budget alerts on Gemini Live and Maps API usage.
  • Governance: pin model versions, pin the Maps MCP package version, and apply VPC Service Controls where required.

👤 Author

Ashwini Kumar · github.com/Ashwinikumar1

Yorumlar (0)

Sonuc bulunamadi