DEV Community

Cover image for Getting Started with Streaming Agents in Google ADK
Md Enayetur Rahman
Md Enayetur Rahman

Posted on

Getting Started with Streaming Agents in Google ADK

My Next Step: Streaming with Real-Time Search

After successfully creating my first basic agent with Google ADK, I was excited to take the next step: building a streaming agent that can perform real-time Google searches. This allows the agent to access current information and provide up-to-date answers, making it much more powerful than a static knowledge base.

I'll walk you through how I built this streaming search agent, sharing the code and process so you can build your own.

Building a Streaming Search Agent

My streaming agent combines the power of Google's Gemini models with real-time Google Search capabilities. This enables the agent to answer questions using the most current information available on the web.

Step 1: Setting Up the Project

I created a new directory for my streaming agent project:

C:\Agent\adk_streaming>python -m venv .venv
C:\Agent\adk_streaming>.venv\Scripts\activate.bat
(.venv) C:\Agent\adk_streaming>pip install google-adk
Enter fullscreen mode Exit fullscreen mode

Just like with my first agent, I set up a clean virtual environment and installed the Google ADK package.

Step 2: Understanding Streaming Models

Before diving into the code, I learned about the different model options available for streaming. According to the ADK documentation, there are specific models that support live streaming:

  • gemini-2.0-flash-live-001
  • gemini-2.0-flash-live-preview-04-09
  • Or you can use gemini-2.5-flash for general streaming capabilities

For this project, I started with gemini-2.0-flash-001 as it provides a good balance of performance and streaming capabilities.

Step 3: Creating the Streaming Agent with Google Search

The key difference in this agent is the integration of the google_search tool, which enables real-time web search capabilities. Here's the complete agent code:

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

root_agent = Agent(
   # A unique name for the agent.
   name="basic_search_agent",
   # The Large Language Model (LLM) that agent will use.
   # Please fill in the latest model id that supports live from
   # https://google.github.io/adk-docs/get-started/streaming/quickstart-streaming/#supported-models
   model="gemini-2.5-flash",  # for example: model="gemini-2.0-flash-live-001" or model="gemini-2.0-flash-live-preview-04-09"
   # A short description of the agent's purpose.
   description="Agent to answer questions using Google Search.",
   # Instructions to set the agent's behavior.
   instruction="You are an expert researcher. You always stick to the facts.",
   # Add google_search tool to perform grounding with Google search.
   tools=[google_search]
)
Enter fullscreen mode Exit fullscreen mode

Breaking Down the Code

Let's examine each component:

  1. Import Statements:
  • Agent from google.adk.agents - The core agent class
  • google_search from google.adk.tools - The tool that enables web search functionality
  1. Agent Configuration:
    • Name: basic_search_agent - A descriptive identifier for this agent
    • Model: gemini-2.5-flash - The LLM that powers the agent's reasoning
    • Description: Explains what the agent does (answers questions using Google Search)
    • Instruction: Sets the agent's behavior as an expert researcher that sticks to facts
    • Tools: [google_search] - This is the key addition! It enables the agent to perform real-time web searches

Step 4: How the Google Search Tool Works

The google_search tool provides grounding capabilities, which means the agent can:

  • Search the web for current information
  • Retrieve relevant search results
  • Use those results to provide accurate, up-to-date answers
  • Cite sources when appropriate

This is particularly powerful for questions about:

  • Current events and news
  • Recent developments in technology
  • Up-to-date statistics or data
  • Information that changes frequently

Step 5: Running the Streaming Agent

Once the agent is set up, you can run it just like any other ADK agent:

adk run adk_streaming
Enter fullscreen mode Exit fullscreen mode

Or launch the web interface:

adk web --port 8000
Enter fullscreen mode Exit fullscreen mode

When you interact with the agent, it will automatically use Google Search when it needs current information to answer your questions. The streaming capabilities mean you'll see responses appear in real-time as the agent processes and searches for information.

Key Differences from My First Agent

Comparing this streaming search agent to my initial quickstart agent:

Feature Basic Agent Streaming Search Agent
Model gemini-2.5-flash gemini-2.0-flash-001 (or live models)
Tools None google_search
Information Source Pre-trained knowledge Real-time web search
Use Case General questions Current events, real-time data

What I Learned

  1. Tools Extend Capabilities: Adding tools like google_search dramatically expands what an agent can do
  2. Grounding is Powerful: The ability to search and verify information makes agents more reliable
  3. Streaming Models: Understanding which models support live streaming is important for real-time applications
  4. Simple Integration: The ADK makes it surprisingly easy to add powerful tools to agents

Next Steps

As I continue exploring streaming agents, I'm planning to:

  1. Experiment with Live Models: Try gemini-2.0-flash-live-001 for enhanced streaming capabilities
  2. Combine Multiple Tools: Explore using multiple tools together for more complex tasks
  3. Custom Tools: Learn how to create custom tools for specific use cases
  4. Streaming Optimization: Understand how to optimize streaming performance

Key Takeaways

  • Streaming agents can access real-time information through tools like google_search
  • The ADK makes it simple to add powerful capabilities with just a few lines of code
  • Grounding with web search makes agents more reliable for current information
  • The same familiar ADK patterns apply when adding tools and streaming capabilities

Resources

Top comments (0)