STELLAR CHART (星海図へ戻る)
Voyage ID: post-35
AI-AGENTS✦ DRAFT (下書き)Difficulty: Level 3

無題

Reading: 10 min

ADKストリーミングクイックスタート¶

このクイックスタートでは、簡単なエージェントを作成し、ADKストリーミングを使用して、低遅延で双方向の音声およびビデオ通信を可能にする方法を学びます。ADKをインストールし、基本的な「Google検索」エージェントを設定し、adk webツールでストリーミングでエージェントを実行し、ADKストリーミングとFastAPIを使用して簡単な非同期ウェブアプリを自分で構築する方法を説明します。

# ADKストリーミングクイックスタート¶ このクイックスタートでは、簡単なエージェントを作成し、ADKストリーミングを使用して、低遅延で双方向の音声およびビデオ通信を可能にする方法を学びます。ADKをインストールし、基本的な「Google検索」エージェントを設定し、`adk web`ツールでストリーミングでエージェントを実行し、ADKストリーミングと[FastAPI](https://fastapi.tiangolo.com/)を使用して簡単な非同期ウェブアプリを自分で構築する方法を説明します。
# ADK Streaming Quickstart¶ With this quickstart, you'll learn to create a simple agent and use ADK Streaming to enable voice and video communication with it that is low-latency and bidirectional. We will install ADK, set up a basic "Google Search" agent, try running the agent with Streaming with `adk web` tool, and then explain how to build a simple asynchronous web app by yourself using ADK Streaming and [FastAPI](https://fastapi.tiangolo.com/).
## Supported models for voice/video streaming¶ In order to use voice/video streaming in ADK, you will need to use Gemini models that support the Live API. You can find the **model ID(s)** that supports the Gemini Live API in the documentation: - - [Google AI Studio: Gemini Live API](https://ai.google.dev/gemini-api/docs/models#live-api) - - [Vertex AI: Gemini Live API](https://cloud.google.com/vertex-ai/generative-ai/docs/live-api)
## 1. Setup Environment & Install ADK¶ Install ADK: ```text pip install google-adk ```

2. Project Structure

Create the following folder structure with empty files:

adk-streaming/  # Project folder
└── app/ # the web app folder
    ├── .env # Gemini API key
    └── google_search_agent/ # Agent folder
        ├── __init__.py # Python package
        └── agent.py # Agent definition

agent.py

Copy-paste the following code block to the agent.py.

For model, please double check the model ID as described earlier in the Models section.

from google.adk.agents import Agent
from google.adk.tools import google_search # Import the tool

root_agent = Agent(
    name = "basic_search_agent", # A unique name for the agent.
    model = "gemini-2.0-flash-live-preview-04-09", # LLM that agent will use.
    description = "Agent to answer questions using Google Search.", # A short description of the agent's purpose.
    instruction = "You are an expert researcher. You always stick to the facts.", # Instructions to set the agent's behavior.
    tools = [google_search] # Add google_search tool to perform grounding with Google search.
)

Note: To enable both text and audio/video input, the model must support the generateContent (for text) and bidiGenerateContent methods. Verify these capabilities by referring to the List Models Documentation. This quickstart utilizes the gemini-2.0-flash-exp model for demonstration purposes.

agent.py is where all your agent(s)' logic will be stored, and you must have a root_agentdefined.

Notice how easily you integrated grounding with Google Search capabilities. The Agent class and the google_search tool handle the complex interactions with the LLM and grounding with the search API, allowing you to focus on the agent's purpose and behavior.

Copy-paste the following code block to __init__.py and main.py files.

from . import agent

3. Set up the platform¶

To run the agent, choose a platform from either Google AI Studio or Google Cloud Vertex AI:

# excute these commands in terminal

export GOOGLE_GENAI_USE_VERTEXAI=TRUE
export GOOGLE_CLOUD_PROJECT=PASTE_YOUR_ACTUAL_PROJECT_ID
export GOOGLE_CLOUD_LOCATION=us-central1

4. Try the agent with adk web¶

🐾
NAVIGATOR AI TOOLKIT

マンチカン航海士の知恵袋

マンチカン航海士が記事全文を読んでいるニャ... 🐾