Skip to content

Build a live streaming agent with Kotlin

Supported in ADKKotlin v1.6.0Experimental

In this quickstart, you build a live streaming agent with ADK Kotlin and hold a real-time, bidirectional voice conversation with it. You set up a Gradle project, define a Google Search agent with GoogleSearchTool, and run the agent in the ADK web interface with AdkDevServer.

Experimental for Kotlin

The live streaming API in ADK Kotlin is an experimental release. It may change in future releases and is not recommended for production use.

Supported models for voice streaming

Voice streaming requires a Gemini model that supports the Live API. Find the supported model IDs in the documentation:

Set up your environment and install ADK

Before you start, verify that you have the following tools installed:

  • JDK 17
  • Gradle 8.0 or higher

Gradle downloads the required ADK Kotlin dependencies, com.google.adk:google-adk-kotlin-core and com.google.adk:google-adk-kotlin-webserver, when you configure build.gradle.kts in the next section.

Project structure

Create a project directory with the following files:

adk-streaming/
├── build.gradle.kts
├── .env
└── src/
    └── main/
        └── kotlin/
            └── com/
                └── example/
                    └── streaming/
                        ├── SearchAgent.kt
                        └── Main.kt

build.gradle.kts

Define the build configuration for your project. The following code example shows the required configuration for the build.gradle.kts build file:

adk-streaming/build.gradle.kts
plugins {
    kotlin("jvm") version "2.1.20"
    application
}

repositories {
    mavenCentral()
}

dependencies {
    implementation("com.google.adk:google-adk-kotlin-core:1.6.0")
    implementation("com.google.adk:google-adk-kotlin-webserver:1.6.0")
}

kotlin {
    jvmToolchain(17)
}

application {
    mainClass.set("com.example.streaming.MainKt")
}

SearchAgent.kt

Create the definition of your live agent using the following code example. For modelName, verify the latest model ID that supports the Live API in Supported models for voice streaming.

adk-streaming/src/main/kotlin/com/example/streaming/SearchAgent.kt
package com.example.streaming

import com.google.adk.kt.agents.Instruction
import com.google.adk.kt.agents.LlmAgent
import com.google.adk.kt.models.Gemini
import com.google.adk.kt.models.VertexCredentials
import com.google.adk.kt.tools.GoogleSearchTool

object SearchAgent {
    private val modelName =
        System.getenv("DEMO_AGENT_MODEL")
            ?.takeUnless { it.isBlank() }
            ?: "gemini-3.8-live"

    private val model =
        if (System.getenv("GOOGLE_GENAI_USE_ENTERPRISE").equals("TRUE", ignoreCase = true)) {
            val location =
                System.getenv("GOOGLE_CLOUD_LOCATION")
                    ?.takeUnless { it.isBlank() }
                    ?: "us-central1"
            Gemini(
                name = modelName,
                vertexCredentials = VertexCredentials(location = location),
            )
        } else {
            Gemini(name = modelName)
        }

    val rootAgent = LlmAgent(
        // A unique name for the agent.
        name = "basic_search_agent",
        // The Large Language Model (LLM) that the agent uses.
        model = model,
        // A short description of the agent's purpose.
        description = "Agent to answer questions using Google Search.",
        // Instructions to set the agent's behavior.
        instruction = Instruction(
            "You are an expert researcher. You always stick to the facts."
        ),
        // Add GoogleSearchTool to perform grounding with Google Search.
        tools = listOf(GoogleSearchTool()),
    )
}

The LlmAgent class and GoogleSearchTool manage the model connection and grounding with Google Search, so you can focus on the agent's purpose and instructions.

"Diagram showing user input flowing through the basic search agent to the Google Search tool and Google Search API, returning results and a response"

Main.kt

Copy the following code into Main.kt to serve the agent and the bundled ADK web interface on localhost:

adk-streaming/src/main/kotlin/com/example/streaming/Main.kt
package com.example.streaming

import com.google.adk.kt.webserver.AdkServerConfig
import com.google.adk.kt.webserver.dev.AdkDevServer

fun main() {
    val server = AdkDevServer(AdkServerConfig.inMemory(SearchAgent.rootAgent))
    println("Serving basic_search_agent at http://localhost:8080/dev-ui")
    server.start(wait = true)
}

Set up the platform

Choose either Google AI Studio or Google Cloud Agent Platform to run the agent:

  1. Get an API key from Google AI Studio.
  2. Open the .env file, or create .env.ps1 on Windows PowerShell, in adk-streaming/ and add the following environment variables. Do not commit this file to source control:

    .env
    export GOOGLE_GENAI_USE_ENTERPRISE=FALSE
    export GOOGLE_API_KEY="PASTE_YOUR_ACTUAL_API_KEY_HERE"
    export DEMO_AGENT_MODEL="gemini-3.8-live"
    
    .env.ps1
    $env:GOOGLE_GENAI_USE_ENTERPRISE = "FALSE"
    $env:GOOGLE_API_KEY = "PASTE_YOUR_ACTUAL_API_KEY_HERE"
    $env:DEMO_AGENT_MODEL = "gemini-3.8-live"
    
  3. Replace PASTE_YOUR_ACTUAL_API_KEY_HERE with your actual API key.

  1. Prepare a Google Cloud account and project. For details on connecting ADK agents with Google Cloud, see Connect to Google Cloud.
  2. Open the .env file, or create .env.ps1 on Windows PowerShell, in adk-streaming/, add the following environment variables, and update the project ID and regional location. Do not commit this file to source control:

    .env
    export GOOGLE_GENAI_USE_ENTERPRISE=TRUE
    export GOOGLE_CLOUD_PROJECT="PASTE_YOUR_ACTUAL_PROJECT_ID"
    export GOOGLE_CLOUD_LOCATION="us-central1"
    export DEMO_AGENT_MODEL="gemini-3.8-live"
    
    .env.ps1
    $env:GOOGLE_GENAI_USE_ENTERPRISE = "TRUE"
    $env:GOOGLE_CLOUD_PROJECT = "PASTE_YOUR_ACTUAL_PROJECT_ID"
    $env:GOOGLE_CLOUD_LOCATION = "us-central1"
    $env:DEMO_AGENT_MODEL = "gemini-3.8-live"
    

    Live API models require a regional endpoint such as us-central1, not the global endpoint.

For more information on connecting to Google Cloud from ADK agents, see Connect to Google Cloud and Agent Platform.

Run agent with ADK Web

Load your environment variables and start AdkDevServer from the adk-streaming/ project directory:

source .env
gradle run
. .\.env.ps1
gradle run

Open http://localhost:8080/dev-ui or http://127.0.0.1:8080/dev-ui directly in your browser. The browser connection to AdkDevServer stays on your local machine. Select basic_search_agent from the agent menu.

Caution: ADK Web for development only

Do not use ADK Web in production deployments. Use AdkDevServer and ADK Web for development and debugging only.

Test voice input

Once you have built and run your agent, you can test it with voice input. The agent uses GoogleSearchTool to retrieve current information and responds with real-time audio.

To try voice input:

  1. Reload the browser page for ADK Web.
  2. Select the microphone button to enable voice input.
  3. Try speaking questions, such as:
    • What is the weather in New York?
    • What is the weather in Paris?
    • What is the time in Paris?

Text input not supported for Live models

Do not use the text input with native-audio, live-only models, including Gemini Live models. Typing a message in ADK Web sends a non-live request to /run_sse, which live-only models reject.

Stop the server

Stop the server by pressing Ctrl-C in the terminal.

Next steps: build a custom streaming application

To build a custom live streaming application in ADK Kotlin, opt in with @OptIn(ExperimentalLiveApi::class) and call runner.runLive() with a LiveRequestQueue and a RunConfig that carries your LiveRunConfig settings, such as RunConfig(live = LiveRunConfig(...)). For a complete Kotlin microphone and speaker example, see LiveAgentDemo.kt in the google/adk-kotlin repository.

To learn more about live agent concepts and server design, see the following guides, which show Python examples for the same runner and lifecycle patterns:

  • Sessions covers the live application lifecycle and session resumption.
  • Events describes the events that live runs return.
  • Build a custom server walks through bridging a WebSocket client to a live agent runner.