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
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-001gemini-2.0-flash-live-preview-04-09- Or you can use
gemini-2.5-flashfor 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]
)
Breaking Down the Code
Let's examine each component:
- Import Statements:
-
Agentfromgoogle.adk.agents- The core agent class -
google_searchfromgoogle.adk.tools- The tool that enables web search functionality
-
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
-
Name:
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
Or launch the web interface:
adk web --port 8000
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
-
Tools Extend Capabilities: Adding tools like
google_searchdramatically expands what an agent can do - Grounding is Powerful: The ability to search and verify information makes agents more reliable
- Streaming Models: Understanding which models support live streaming is important for real-time applications
- 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:
-
Experiment with Live Models: Try
gemini-2.0-flash-live-001for enhanced streaming capabilities - Combine Multiple Tools: Explore using multiple tools together for more complex tasks
- Custom Tools: Learn how to create custom tools for specific use cases
- 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
- GitHub Repository - My code repository with all agent implementations
- YouTube Tutorial - Video walkthrough of building streaming agents
- ADK Streaming Documentation - Complete guide to streaming capabilities
Top comments (0)