Building Web Search Agent with Google-ADK
Set up a web search agent with Google ADK and LangDB. Guide covers creating virtual MCP servers, integrating search tools, model routing, and full observability.
This guide walks you through setting up a powerful WebSearch agent that leverages Google ADK for orchestration and LangDB for LLM access, tracing, and flexible routing.
Code
Overview
The final agent will use a SequentialAgent to orchestrate two sub-agents:
Critic Agent: Receives a user's query, searches the web for information using a tool, and provides an initial analysis with source references.
Reviser Agent: Takes the critic's output, refines the content, and synthesizes a final, polished answer.
LangDB automatically captures the entire workflow, giving you full visibility into the handoff between agents and the tools they use.
Installation
Environment Variables
Project Structure
Code Walkthrough
Initialize LangDB Tracing
The most important step is to call pylangdb.adk.init() before any Google ADK modules are imported. This instruments the environment for automatic tracing.
Define the Critic Agent with a Virtual Model
The critic_agent is responsible for the web search. Instead of hard-coding a tool, we assign it a LangDB Virtual Model. This virtual model has a Tavily Search MCP attached, giving the agent search capabilities without changing its code.
Define the Sequential Agent
The root agent.py defines a SequentialAgent that orchestrates the workflow, passing the user's query first to the critic_agent and then its output to the reviser_agent.
Configuring MCPs and Virtual Models
To empower the critic_agent with live web search, we first create a Virtual MCP Server for the search tool and then attach it to a Virtual Model.
1. Create a Virtual MCP Server
First, create a dedicated MCP server for the search tool.
In the LangDB UI, navigate to Projects → MCP Servers.
Click + New Virtual MCP Server and configure it:
Name:
web-search-mcpUnderlying MCP: Select Tavily Search.
Note: The Tavily MCP requires an API key. Ensure you have added your
TAVILY_API_KEYto your LangDB account secrets for the tool to function.
2. Create and Configure the Virtual Model
Next, create a virtual model and attach the MCP you just made.
Navigate to Models → + New Virtual Model.
Give it a name (e.g.,
critic-agent).In the Tools section, click + Attach MCP Server and select the
web-search-mcpyou created.Save the model and copy its identifier (e.g.,
langdb/critic-agent_xxxxxx).Use this identifier as the
modelin yourcritic_agentdefinition.
Running the Agent
With your pyproject.toml configured for the ADK, you can run the agent locally:
Navigate to http://localhost:8000, select web-search, and enter a query.
Full Trace
Every run is captured in LangDB, showing the full sequence from the initial query to the final revised answer, including the tool calls made by the critic agent.

You can checkout the entire conversation history as well as tracing from the thread:
References
Last updated
Was this helpful?
