Google ADK with Azure
How to leverage the Google ADK using Azure OpenAI
Google ADK with Azure
Entering this dynamic field with its own comprehensive offering, Google has introduced the Google Agent Development Kit (ADK), an open-source Python library. Think of ADK as a toolkit designed to streamline the entire process of creating, testing, and launching sophisticated AI agents. Whether you need a chatbot that understands natural language or a behind-the-scenes process automation, ADK provides the structure and tools to build robust solutions. But it doesnt mean you need to be locked down to use only the models available from Google. I typically use the Azure OpenAI models on my projects and want to show you how you can do the same.
Create your python envrionment and install the required libraries
python -m venv .venv
source .venv/bin/activate
pip install google-adk,openai,litellm,python-dotenv
We will be using LiteLLM which will enable us to leverage the models available from Azure OpenAI. Create a .env with the following:
AZURE_API_KEY = <AZURE API KEY>
AZURE_API_BASE= <AZURE API BASE ENDPOINT>
AZURE_API_VERSION = <AZURE API VERSION>
Once you have this in place, you can create your main agents.py file as below:
import os
import datetime
from zoneinfo import ZoneInfo
from google.adk.agents import LlmAgent
from google.adk.models.lite_llm import LiteLlm
from dotenv import load_dotenv
load_dotenv()
AZURE_API_KEY = os.getenv("AZURE_API_KEY")
AZURE_API_BASE= os.getenv("AZURE_API_BASE")
AZURE_API_VERSION = os.getenv("AZURE_API_VERSION")
def get_weather(city: str) -> dict:
"""Retrieves the current weather report for a specified city.
Args:
city (str): The name of the city for which to retrieve the weather report.
Returns:
dict: status and result or error msg.
"""
if city.lower() == "new york":
return {
"status": "success",
"report": (
"The weather in New York is sunny with a temperature of 25 degrees"
" Celsius (41 degrees Fahrenheit)."
),
}
else:
return {
"status": "error",
"error_message": f"Weather information for '{city}' is not available.",
}
def get_current_time(city: str) -> dict:
"""Returns the current time in a specified city.
Args:
city (str): The name of the city for which to retrieve the current time.
Returns:
dict: status and result or error msg.
"""
if city.lower() == "new york":
tz_identifier = "America/New_York"
else:
return {
"status": "error",
"error_message": (
f"Sorry, I don't have timezone information for {city}."
),
}
tz = ZoneInfo(tz_identifier)
now = datetime.datetime.now(tz)
report = (
f'The current time in {city} is {now.strftime("%Y-%m-%d %H:%M:%S %Z%z")}'
)
return {"status": "success", "report": report}
root_agent = LlmAgent(
name="weather_time_agent",
model=LiteLlm(model="azure/gpt-4o"), # LiteLLM model string format
description=(
"Agent to answer questions about the time and weather in a city."
),
instruction=(
"I can answer your questions about the time and weather in a city."
),
tools=[get_weather, get_current_time],
)
Run the following command to launch the dev UI.
adk web
Open the URL provided (usually http://localhost:8000 or http://127.0.0.1:8000) directly in your browser. In the top-left corner of the UI, you can select your agent in the dropdown. Select "multi_tool_agent". Now you can chat with your agent using the textbox
And thats it. You should have your sample agent up and running. You can now modifiy the code to put in your logic and build out your app. Enjoy your build.