Skip to content

Third Party Tools

python_only

ADK is designed to be highly extensible, allowing you to seamlessly integrate tools from other AI Agent frameworks like CrewAI and LangChain. This interoperability is crucial because it allows for faster development time and allows you to reuse existing tools.

1. Using LangChain Tools

ADK provides the LangchainTool wrapper to integrate tools from the LangChain ecosystem into your agents.

Example: Web Search using LangChain's Tavily tool

Tavily provides a search API that returns answers derived from real-time search results, intended for use by applications like AI agents.

  1. Follow ADK installation and setup guide.

  2. Install Dependencies: Ensure you have the necessary LangChain packages installed. For example, to use the Tavily search tool, install its specific dependencies:

    pip install langchain_community tavily-python
    
  3. Obtain a Tavily API KEY and export it as an environment variable.

    export TAVILY_API_KEY=<REPLACE_WITH_API_KEY>
    
  4. Import: Import the LangchainTool wrapper from ADK and the specific LangChain tool you wish to use (e.g, TavilySearchResults).

    from google.adk.tools.langchain_tool import LangchainTool
    from langchain_community.tools import TavilySearchResults
    
  5. Instantiate & Wrap: Create an instance of your LangChain tool and pass it to the LangchainTool constructor.

    # Instantiate the LangChain tool
    tavily_tool_instance = TavilySearchResults(
        max_results=5,
        search_depth="advanced",
        include_answer=True,
        include_raw_content=True,
        include_images=True,
    )
    
    # Wrap it with LangchainTool for ADK
    adk_tavily_tool = LangchainTool(tool=tavily_tool_instance)
    
  6. Add to Agent: Include the wrapped LangchainTool instance in your agent's tools list during definition.

    from google.adk import Agent
    
    # Define the ADK agent, including the wrapped tool
    my_agent = Agent(
        name="langchain_tool_agent",
        model="gemini-2.0-flash",
        description="Agent to answer questions using TavilySearch.",
        instruction="I can answer your questions by searching the internet. Just ask me anything!",
        tools=[adk_tavily_tool] # Add the wrapped tool here
    )
    

Here's the full code combining the steps above to create and run an agent using the LangChain Tavily search tool.

# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
from google.adk import Agent, Runner
from google.adk.sessions import InMemorySessionService
from google.adk.tools.langchain_tool import LangchainTool
from google.genai import types
from langchain_community.tools import TavilySearchResults

# Ensure TAVILY_API_KEY is set in your environment
if not os.getenv("TAVILY_API_KEY"):
    print("Warning: TAVILY_API_KEY environment variable not set.")

APP_NAME = "news_app"
USER_ID = "1234"
SESSION_ID = "session1234"

# Instantiate LangChain tool
tavily_search = TavilySearchResults(
    max_results=5,
    search_depth="advanced",
    include_answer=True,
    include_raw_content=True,
    include_images=True,
)

# Wrap with LangchainTool
adk_tavily_tool = LangchainTool(tool=tavily_search)

# Define Agent with the wrapped tool
my_agent = Agent(
    name="langchain_tool_agent",
    model="gemini-2.0-flash",
    description="Agent to answer questions using TavilySearch.",
    instruction="I can answer your questions by searching the internet. Just ask me anything!",
    tools=[adk_tavily_tool] # Add the wrapped tool here
)

async def setup_session_and_runner():
    session_service = InMemorySessionService()
    session = await session_service.create_session(app_name=APP_NAME, user_id=USER_ID, session_id=SESSION_ID)
    runner = Runner(agent=my_agent, app_name=APP_NAME, session_service=session_service)
    return session, runner

# Agent Interaction
async def call_agent_async(query):
    content = types.Content(role='user', parts=[types.Part(text=query)])
    session, runner = await setup_session_and_runner()
    events = runner.run_async(user_id=USER_ID, session_id=SESSION_ID, new_message=content)

    async for event in events:
        if event.is_final_response():
            final_response = event.content.parts[0].text
            print("Agent Response: ", final_response)

# Note: In Colab, you can directly use 'await' at the top level.
# If running this code as a standalone Python script, you'll need to use asyncio.run() or manage the event loop.
await call_agent_async("stock price of GOOG")

Example: Using LangChain's StructuredTool

from google.adk.agents.llm_agent import Agent # Import the core Agent class to create the AI assistant from google.adk.tools.langchain_tool import LangchainTool # Import wrapper to make LangChain tools compatible with ADK from langchain_core.tools import tool # Import decorator to quickly turn functions into LangChain tools from langchain_core.tools.structured import StructuredTool # Import class for creating tools with explicit schemas from pydantic import BaseModel # Import BaseModel to define structured data schemas for tool inputs

async def add(x: int, y: int) -> int: """ An asynchronous function that performs addition.

Args:
    x (int): The first number.
    y (int): The second number.

Returns:
    int: The sum of x and y.
"""
return x + y  # Returns the result of adding x and y

@tool def minus(x: int, y: int) -> int: """ A synchronous function decorated as a LangChain tool to perform subtraction.

The @tool decorator automatically converts this function into a LangChain tool 
using the function name as the tool name and this docstring as the description.

Args:
    x (int): The number to subtract from.
    y (int): The number to be subtracted.

Returns:
    int: The difference between x and y.
"""
return x - y  # Returns the result of subtracting y from x

class AddSchema(BaseModel): """ Pydantic schema defining the input structure for the 'add' tool. This helps the LLM understand that 'x' and 'y' must be integers. """ x: int # Defines 'x' as a required integer y: int # Defines 'y' as a required integer

class MinusSchema(BaseModel): """ Pydantic schema defining the input structure for the 'minus' tool. Ensures the LLM provides the correct types when calling the subtraction tool. """ x: int # Defines 'x' as a required integer y: int # Defines 'y' as a required integer

Create a formal 'StructuredTool' from the 'add' function.

This method is more explicit than the @tool decorator, allowing for manual naming and schema binding.

test_langchain_add_tool = StructuredTool.from_function( func=add, # The actual logic (the add function defined above) name="add", # The name the LLM will see for this tool description="Adds two numbers", # Description used by the LLM to decide when to use this tool args_schema=AddSchema, # Links the Pydantic schema to validate and describe the inputs )

Initialize the Root Agent (the "brain" of the application).

root_agent = Agent( model="gemini-2.0-flash-001", # Specifies the Google Gemini model to power the agent name="test_app", # Internal identifier/name for the agent description="A helpful assistant for user questions.", # High-level description of the agent's purpose instruction=( # The system prompt that guides the agent's behavior "You are a helpful assistant for user questions, you have access to a" " tool that adds two numbers." ), tools=[ # List of tools the agent is allowed to use # Wraps the StructuredTool 'add' into the ADK format LangchainTool(tool=test_langchain_add_tool), # Wraps the decorated '@tool' function 'minus' into the ADK format LangchainTool(tool=minus), ], )

2. Using CrewAI tools

ADK provides the CrewaiTool wrapper to integrate tools from the CrewAI library.

Example: Web Search using CrewAI's Serper API

Serper API provides access to Google Search results programmatically. It allows applications, like AI agents, to perform real-time Google searches (including news, images, etc.) and get structured data back without needing to scrape web pages directly.

  1. Follow ADK installation and setup guide.

  2. Install Dependencies: Install the necessary CrewAI tools package. For example, to use the SerperDevTool:

    pip install crewai-tools
    
  3. Obtain a Serper API KEY and export it as an environment variable.

    export SERPER_API_KEY=<REPLACE_WITH_API_KEY>
    
  4. Import: Import CrewaiTool from ADK and the desired CrewAI tool (e.g, SerperDevTool).

    from google.adk.tools.crewai_tool import CrewaiTool
    from crewai_tools import SerperDevTool
    
  5. Instantiate & Wrap: Create an instance of the CrewAI tool. Pass it to the CrewaiTool constructor. Crucially, you must provide a name and description to the ADK wrapper, as these are used by ADK's underlying model to understand when to use the tool.

    # Instantiate the CrewAI tool
    serper_tool_instance = SerperDevTool(
        n_results=10,
        save_file=False,
        search_type="news",
    )
    
    # Wrap it with CrewaiTool for ADK, providing name and description
    adk_serper_tool = CrewaiTool(
        name="InternetNewsSearch",
        description="Searches the internet specifically for recent news articles using Serper.",
        tool=serper_tool_instance
    )
    
  6. Add to Agent: Include the wrapped CrewaiTool instance in your agent's tools list.

    from google.adk import Agent
    
    # Define the ADK agent
    my_agent = Agent(
        name="crewai_search_agent",
        model="gemini-2.0-flash",
        description="Agent to find recent news using the Serper search tool.",
        instruction="I can find the latest news for you. What topic are you interested in?",
        tools=[adk_serper_tool] # Add the wrapped tool here
    )
    

Full Example: Serper API

Here's the full code combining the steps above to create and run an agent using the CrewAI Serper API search tool.

# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
from google.adk import Agent, Runner
from google.adk.sessions import InMemorySessionService
from google.adk.tools.crewai_tool import CrewaiTool
from google.genai import types
from crewai_tools import SerperDevTool


# Constants
APP_NAME = "news_app"
USER_ID = "user1234"
SESSION_ID = "1234"

# Ensure SERPER_API_KEY is set in your environment
if not os.getenv("SERPER_API_KEY"):
    print("Warning: SERPER_API_KEY environment variable not set.")

serper_tool_instance = SerperDevTool(
    n_results=10,
    save_file=False,
    search_type="news",
)

adk_serper_tool = CrewaiTool(
    name="InternetNewsSearch",
    description="Searches the internet specifically for recent news articles using Serper.",
    tool=serper_tool_instance
)

serper_agent = Agent(
    name="basic_search_agent",
    model="gemini-2.0-flash",
    description="Agent to answer questions using Google Search.",
    instruction="I can answer your questions by searching the internet. Just ask me anything!",
    # Add the Serper tool
    tools=[adk_serper_tool]
)

# Session and Runner
async def setup_session_and_runner():
    session_service = InMemorySessionService()
    session = await session_service.create_session(app_name=APP_NAME, user_id=USER_ID, session_id=SESSION_ID)
    runner = Runner(agent=serper_agent, app_name=APP_NAME, session_service=session_service)
    return session, runner


# Agent Interaction
async def call_agent_async(query):
    content = types.Content(role='user', parts=[types.Part(text=query)])
    session, runner = await setup_session_and_runner()
    events = runner.run_async(user_id=USER_ID, session_id=SESSION_ID, new_message=content)

    async for event in events:
        if event.is_final_response():
            final_response = event.content.parts[0].text
            print("Agent Response: ", final_response)

# Note: In Colab, you can directly use 'await' at the top level.
# If running this code as a standalone Python script, you'll need to use asyncio.run() or manage the event loop.
await call_agent_async("what's the latest news on AI Agents?")