Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 28 additions & 79 deletions docs/get-started/quickstart-streaming.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ADK Streaming Quickstart {#adk-streaming-quickstart}

With this quickstart, you'll learn to create a simple agent and use ADK Streaming to enable audio and video communication with it. 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/).
This Quickstart will guide you through installing ADK, setting up a basic "Google Search" agent, and building a simple asynchronous web app that uses the Streaming API and [FastAPI](https://fastapi.tiangolo.com/).

**Note:** This guide assumes you have experience using a terminal in Windows, Mac, and Linux environments.

Expand All @@ -23,14 +23,19 @@ Install ADK:
pip install google-adk
```

## 2. Project Structure {#2.-project-structure}
**Note:** We recommend using a Python virtual environment.

## 2\. Project Structure {#2.-project-structure}

Create the following folder structure with empty files:

```console
adk-streaming/ # Project folder
└── app/ # the web app folder
└── app/ # FastAPI web app folder
|── main.py # FastAPI web app
|── .env # Gemini API key
├── static/ # Static content folder
| └── index.html # The web client page
└── google_search_agent/ # Agent folder
├── __init__.py # Python package
└── agent.py # Agent definition
Expand Down Expand Up @@ -68,75 +73,7 @@ Copy-paste the following code block to `__init__.py` and `main.py` files.
from . import agent
```

## 3\. Setup Gemini API Key {#3.-setup-gemini-api-key}

To run your agent, you'll need to set up a Gemini API Key.

1. Get an API key from [Google AI Studio](https://aistudio.google.com/apikey).
2. Inside your `app` directory, create a `.env` file.
3. Add these lines to `.env`, replacing `YOUR_API_KEY_HERE` with your key:

**.env**

```
GOOGLE_API_KEY=YOUR_API_KEY_HERE # Replace with your API Key
GOOGLE_GENAI_USE_VERTEXAI=0
```

## 4. Try it with `adk web` {#4.-try-it-adk-web}

Now it's ready to try the agent. Run the following command to launch the **dev UI**. First, make sure to set the current directory to `app`:

```
cd app
```

Then, run the dev UI:

```
adk web
```

Open the URL provided (usually `http://localhost:8000` or
`http://127.0.0.1:8000`) **directly in your browser**. This connection stays
entirely on your local machine. Select `basic_search_agent`.

### 📝 Try with text

Try the following prompts by typing them in the UI.

* What is the weather in New York?
* What is the time in New York?
* What is the weather in Paris?
* What is the time in Paris?

### 📝 Try with voice

Now, click the microphone button to enable the voice input, and ask the same question in voice. You will hear the answer in voice in real-time.

### Stop the tool

Stop `adk web` by pressing `Ctrl-C` on the console.

We have checked that our basic search agent works with the ADK Streaming. In the following sections, we will learn how to build your own web application capable of the streaming communication.

## 5. Project Structure for custom streaming app {#5.-project-structure-custom-app}

Add `static` directory under `app`, and add `main.py` and `index.html` as empty files, as in the following structure:

```
adk-streaming/ # Project folder
└── app/ # the web app folder
├── main.py # FastAPI web app
└── static/ # Static content folder
└── index.html # The web client page
```

**main.py**

Copy-paste the following code block to the main.py file.

```py
```py title="main.py"
import os
import json
import asyncio
Expand Down Expand Up @@ -418,20 +355,32 @@ This HTML file sets up a basic webpage with:
* Sends the text entered in the input field to the WebSocket server when the form is submitted.
* Attempts to reconnect if the WebSocket connection closes.

## 6\. Interact with Your Streaming app {#4.-interact-with-your-streaming-app}
## 3\. Setup Gemini API Key {#3.-setup-gemini-api-key}

To interact with your agent, you'll need to set up a Gemini API Key.

1. Get an API key from [Google AI Studio](https://aistudio.google.com/apikey).
2. Inside your `app` directory, create a `.env` file.
3. Add these lines to `.env`, replacing `YOUR_API_KEY_HERE` with your key:

```shell title=".env"
GOOGLE_API_KEY=YOUR_API_KEY_HERE # Replace with your API Key
GOOGLE_GENAI_USE_VERTEXAI=0
```

## 4. Interact with Your Agent (FastAPI web app) {#4.-interact-with-your-agent-(fastapi-web-app)}

1. **Navigate to the Correct Directory:**

To run your agent effectively, you need to be in the **app folder (`adk-streaming/app`)**
To run your agent effectively, you need to be in the **app folder (`adk-streaming/app`)**

2. **Start the Fast API**: Run the following command to start CLI interface with
1. Start the Fast API: Run the following command to start CLI interface with

```
$ uvicorn main:app --reload
```shell
uvicorn main:app --reload
```

3. **Access the UI:** Once the UI server starts, the terminal will display a local URL (e.g., [http://localhost:8000](http://localhost:8501)). Click this link to open the UI in your browser. **\[hover-link\]** \[[Ref](https://screenshot.googleplex.com/4vxZejAZ4hpa4Rx)\]

2. **Access the UI:** Once the UI server starts, the terminal will display a local URL (e.g., [http://localhost:8000](http://localhost:8501)). Click this link to open the UI in your browser. **\[hover-link\]** [[Ref](https://screenshot.googleplex.com/4vxZejAZ4hpa4Rx)\]

Now you should see the ADK dev UI like this:

Expand Down