Step-by-Step Guide to Create an AI agent with Google ADK
Agent Development Kitis an open-source Python framework that helps developers build, manage, and deploy multi-agent systems. It’s designed to be modular and flexible, making it easy to use for both simple and complex agent-based applications.
In this tutorial, we’ll create a simple AI agent using ADK. The agent will have access to two tools:
get_company_overview
get_earnings
Step 1: Setting up the dependencies
Google API Key
To use Google’s AI services, you’ll need an API key:
Visit
Sign in and generate your API key
Copy and store it securely — we’ll use it later in the tutorial.
AlphaVantage API Key
For accessing financial data, we’ll use the Alpha Vantage API:
Go to /
Click “Get your free API key” or visit this direct link
Enter your email and follow the instructions
Once you receive your API key, copy and save it securely. We’ll use it to authenticate requests to financial endpoints.
Python Libraries
We only need one package:
pip install google-adk
Step 2: Creating the Folder structure
Set up your project folder with the following structure:
parent_folder/
│
└───multi_agent/
├── __init__.py
├── agent.py
└── .env
__init__.py
Paste the following code into multi_agent/__init__.py:
from . import agent
.env
Create a .env file inside the multi_agent folder and paste the following:
GOOGLE_GENAI_USE_VERTEXAI=FALSE
GOOGLE_API_KEY="<YOUR_GOOGLE_API_KEY>"
ALPHA_VANTAGE_API_KEY="<YOUR_ALPHA_VANTAGE_KEY"
Replace the placeholders with your actual API keys
agent.py
Paste the following code in the agent.py file:
from google.adk.agents import Agent
import requests
import os
from typing import Optional
ALPHA_VANTAGE_API_KEY = os.getenvdef get_company_overview-> dict:
"""
Get comprehensive company information and financial metrics
Args:
symbol: Stock ticker symbolReturns:
dict: Company overview data or error
"""
if not ALPHA_VANTAGE_API_KEY:
return {"status": "error", "error": "Missing API key"}
base_url = ";
params = {
"function": "OVERVIEW",
"symbol": symbol,
"apikey": ALPHA_VANTAGE_API_KEY
}
try:
response = requests.getresponse.raise_for_statusdata = response.jsonif "Error Message" in data:
return {"status": "error", "error": data}
# Filter key metrics
key_metrics = {
"Description": data.get,
"Sector": data.get,
"MarketCap": data.get,
"PERatio": data.get,
"ProfitMargin": data.get,
"52WeekHigh": data.get,
"52WeekLow": data.get}
return {
"status": "success",
"symbol": symbol,
"overview": key_metrics
}
except Exception as e:
return {"status": "error", "error": str}
def get_earnings-> dict:
"""
Get annual and quarterly earningsdata with analyst estimates and surprises
Args:
symbol: Stock ticker symbolReturns:
dict: Earnings data with estimates or error message
"""
if not ALPHA_VANTAGE_API_KEY:
return {"status": "error", "error": "Missing API key"}
base_url = ";
params = {
"function": "EARNINGS",
"symbol": symbol,
"apikey": ALPHA_VANTAGE_API_KEY
}
try:
response = requests.getresponse.raise_for_statusdata = response.jsonif "Error Message" in data:
return {"status": "error", "error": data}
# Process annual and quarterly earnings
annual_earnings = data.get# Last 5 years
quarterly_earnings = data.get# Last 4 quarters
# Format surprise percentages
for q in quarterly_earnings:
if "surprisePercentage" in q:
q= f"{q}%"
return {
"status": "success",
"symbol": symbol,
"annual_earnings": annual_earnings,
"quarterly_earnings": quarterly_earnings,
"metrics": {
"latest_eps": quarterly_earningsif quarterly_earnings else None
}
}
except Exception as e:
return {"status": "error", "error": str}
root_agent = Agent,
instruction=,
tools=,
)
In this script, we define a financial analysis agent using the Google Agent Development Kit. The agent is designed to answer user queries by accessing real-time financial data through the Alpha Vantage API. Specifically, it exposes two tools: get_company_overview and get_earnings. The get_company_overview function retrieves key company details such as sector, market capitalization, P/E ratio, and 52-week high/low values. The get_earnings function provides both annual and quarterly earnings data, including reported EPS and surprise percentages.To create the agent, we use the Agent class from the google.adk.agents module, giving it a name, a model, a description, and an instruction prompt. The agent is then equipped with the two tools mentioned above, allowing it to respond to questions related to company financials.
Step 3: Running the Agent
To run the agent, navigate to the parent directory of your agent projectparent_folder/ ← Navigate to this directory in your terminal
│
└───multi_agent/
├── __init__.py # Initializes the module
├── agent.py # Contains the agent logic and tools
└── .env # Stores your API keys securely
After navigating, run the following code:
adk web
Open the URL provideddirectly in your browser. You’ll see a simple chat interface where you can interact with your agent using the input textbox.
Additionally, you can inspect each step of the agent’s reasoning by clicking on Actions. This allows you to view:
The tools being called
The inputs and outputs of each function
The responses generated by the language model
GitHub Link
You can find the entire code along with folder structure at this link:
Arham IslamI am a Civil Engineering Graduatefrom Jamia Millia Islamia, New Delhi, and I have a keen interest in Data Science, especially Neural Networks and their application in various areas.Arham Islam
https://www.marktechpost.com/author/arhamislam/Implementing an LLM Agent with Tool Access Using MCP-UseArham Islam
https://www.marktechpost.com/author/arhamislam/Implementing an AgentQL Model Context ProtocolServerArham Islam
https://www.marktechpost.com/author/arhamislam/Implementing An Airbnb and Excel MCP ServerArham Islam
https://www.marktechpost.com/author/arhamislam/How to Create a Custom Model Context ProtocolClient Using Gemini
#stepbystep #guide #create #agent #with
Step-by-Step Guide to Create an AI agent with Google ADK
Agent Development Kitis an open-source Python framework that helps developers build, manage, and deploy multi-agent systems. It’s designed to be modular and flexible, making it easy to use for both simple and complex agent-based applications.
In this tutorial, we’ll create a simple AI agent using ADK. The agent will have access to two tools:
get_company_overview
get_earnings
Step 1: Setting up the dependencies
Google API Key
To use Google’s AI services, you’ll need an API key:
Visit
Sign in and generate your API key
Copy and store it securely — we’ll use it later in the tutorial.
AlphaVantage API Key
For accessing financial data, we’ll use the Alpha Vantage API:
Go to /
Click “Get your free API key” or visit this direct link
Enter your email and follow the instructions
Once you receive your API key, copy and save it securely. We’ll use it to authenticate requests to financial endpoints.
Python Libraries
We only need one package:
pip install google-adk
Step 2: Creating the Folder structure
Set up your project folder with the following structure:
parent_folder/
│
└───multi_agent/
├── __init__.py
├── agent.py
└── .env
__init__.py
Paste the following code into multi_agent/__init__.py:
from . import agent
.env
Create a .env file inside the multi_agent folder and paste the following:
GOOGLE_GENAI_USE_VERTEXAI=FALSE
GOOGLE_API_KEY="<YOUR_GOOGLE_API_KEY>"
ALPHA_VANTAGE_API_KEY="<YOUR_ALPHA_VANTAGE_KEY"
Replace the placeholders with your actual API keys
agent.py
Paste the following code in the agent.py file:
from google.adk.agents import Agent
import requests
import os
from typing import Optional
ALPHA_VANTAGE_API_KEY = os.getenvdef get_company_overview-> dict:
"""
Get comprehensive company information and financial metrics
Args:
symbol: Stock ticker symbolReturns:
dict: Company overview data or error
"""
if not ALPHA_VANTAGE_API_KEY:
return {"status": "error", "error": "Missing API key"}
base_url = ";
params = {
"function": "OVERVIEW",
"symbol": symbol,
"apikey": ALPHA_VANTAGE_API_KEY
}
try:
response = requests.getresponse.raise_for_statusdata = response.jsonif "Error Message" in data:
return {"status": "error", "error": data}
# Filter key metrics
key_metrics = {
"Description": data.get,
"Sector": data.get,
"MarketCap": data.get,
"PERatio": data.get,
"ProfitMargin": data.get,
"52WeekHigh": data.get,
"52WeekLow": data.get}
return {
"status": "success",
"symbol": symbol,
"overview": key_metrics
}
except Exception as e:
return {"status": "error", "error": str}
def get_earnings-> dict:
"""
Get annual and quarterly earningsdata with analyst estimates and surprises
Args:
symbol: Stock ticker symbolReturns:
dict: Earnings data with estimates or error message
"""
if not ALPHA_VANTAGE_API_KEY:
return {"status": "error", "error": "Missing API key"}
base_url = ";
params = {
"function": "EARNINGS",
"symbol": symbol,
"apikey": ALPHA_VANTAGE_API_KEY
}
try:
response = requests.getresponse.raise_for_statusdata = response.jsonif "Error Message" in data:
return {"status": "error", "error": data}
# Process annual and quarterly earnings
annual_earnings = data.get# Last 5 years
quarterly_earnings = data.get# Last 4 quarters
# Format surprise percentages
for q in quarterly_earnings:
if "surprisePercentage" in q:
q= f"{q}%"
return {
"status": "success",
"symbol": symbol,
"annual_earnings": annual_earnings,
"quarterly_earnings": quarterly_earnings,
"metrics": {
"latest_eps": quarterly_earningsif quarterly_earnings else None
}
}
except Exception as e:
return {"status": "error", "error": str}
root_agent = Agent,
instruction=,
tools=,
)
In this script, we define a financial analysis agent using the Google Agent Development Kit. The agent is designed to answer user queries by accessing real-time financial data through the Alpha Vantage API. Specifically, it exposes two tools: get_company_overview and get_earnings. The get_company_overview function retrieves key company details such as sector, market capitalization, P/E ratio, and 52-week high/low values. The get_earnings function provides both annual and quarterly earnings data, including reported EPS and surprise percentages.To create the agent, we use the Agent class from the google.adk.agents module, giving it a name, a model, a description, and an instruction prompt. The agent is then equipped with the two tools mentioned above, allowing it to respond to questions related to company financials.
Step 3: Running the Agent
To run the agent, navigate to the parent directory of your agent projectparent_folder/ ← Navigate to this directory in your terminal
│
└───multi_agent/
├── __init__.py # Initializes the module
├── agent.py # Contains the agent logic and tools
└── .env # Stores your API keys securely
After navigating, run the following code:
adk web
Open the URL provideddirectly in your browser. You’ll see a simple chat interface where you can interact with your agent using the input textbox.
Additionally, you can inspect each step of the agent’s reasoning by clicking on Actions. This allows you to view:
The tools being called
The inputs and outputs of each function
The responses generated by the language model
GitHub Link
You can find the entire code along with folder structure at this link:
Arham IslamI am a Civil Engineering Graduatefrom Jamia Millia Islamia, New Delhi, and I have a keen interest in Data Science, especially Neural Networks and their application in various areas.Arham Islamhttps://www.marktechpost.com/author/arhamislam/Implementing an LLM Agent with Tool Access Using MCP-UseArham Islamhttps://www.marktechpost.com/author/arhamislam/Implementing an AgentQL Model Context ProtocolServerArham Islamhttps://www.marktechpost.com/author/arhamislam/Implementing An Airbnb and Excel MCP ServerArham Islamhttps://www.marktechpost.com/author/arhamislam/How to Create a Custom Model Context ProtocolClient Using Gemini
#stepbystep #guide #create #agent #with