Google Agent Development Kit: EASIEST way to create AI Agents!
By Mervin Praison
AITechnologyFinance
Share:
Key Concepts
- AI Agent Development Kit (ADK): A Google tool for creating, evaluating, and deploying AI agents.
- Tools: Functions that agents can use to access external information or perform specific tasks.
- State: The agent's memory of past interactions, allowing it to maintain context.
- Multi-Tool Agent: An agent that can use multiple tools to gather information.
- Structured Output Agent: An agent that returns responses in a predefined format using Pydantic.
- Callback Agent: An agent that executes specific functions before and after tool calls for debugging and monitoring.
- Deployment: The process of making an agent accessible for use, often via cloud services.
- API Server: A server that exposes the agent's functionality through an API.
1. Introduction to Google's Agent Development Kit (ADK)
- The ADK is presented as an easy-to-use tool for creating, evaluating, and deploying AI agents, even for beginners.
- It includes a built-in user interface and API server.
- The video demonstrates a locally running agent that retrieves the stock price of Apple.
- The ADK offers features like state management, artifact tracking, session handling, and evaluation capabilities.
- The video promises a step-by-step guide to building agents locally.
- ADK is simpler than other frameworks like Autogen, Langraph, and Crew AI.
- Key features: build in minutes, use multiple models, full transparency with visual debugging and evaluation.
- Three steps: install ADK, define your agent, and deploy anywhere.
2. Setting Up the ADK and Creating a Basic Agent
- Installation: The first step involves installing the ADK and the
yfinance
library usingpip install google-adk yfinance
. - Creating an App: The command
ADK create
is used to generate the necessary files for a new agent application. - Model Selection: The user is prompted to choose a model (e.g., Gemini 2.0 Flash).
- API Key: An API key from
studio.google.com/api
is required for authentication. - File Structure: The
ADK create
command generates three files:agent.py
,init.py
, and.env
. The.env
file stores environment variables, including the API key. - Basic Agent Code: The
agent.py
file contains the basic agent setup. The video modifies this file to create different types of agents. - Running the Agent: The command
ADK run app.py
starts the agent. - Testing the Agent: The agent can be tested by asking questions in the terminal.
- Available Options: The
ADK help
command displays available options, includingAPI server
andweb
. - Web Interface: The command
ADK web
launches a web interface for interacting with the agent.
3. Creating an Agent with a Tool
- Custom Tool: A custom tool called "Yahoo Finance" is created to fetch stock prices.
yfinance
Library: Theyfinance
library is used to retrieve stock data.get_stock_price
Function: A functionget_stock_price(ticker_symbol)
is defined to retrieve the stock price for a given ticker symbol.- Tool Integration: The
get_stock_price
function is added as a tool to the agent. - Agent Description: The agent is given a description, such as "a simple agent that gets stock price."
- Running the Tool Agent: The
ADK web
command is used to run the agent with the tool. - Example: The video demonstrates asking the agent "What is the stock price of Apple now?" and the agent uses the
get_stock_price
tool to provide the answer.
4. Implementing State in an Agent
- State Management: The video explains how to add state to an agent, allowing it to remember past interactions.
tool_context
Import: Thetool_context
module is imported.recent_searches
State: A state variable calledrecent_searches
is initialized as a list to store recent stock ticker searches.- Stateful Agent: A
stateful_agent
is created that uses theget_stock_price
function and updates therecent_searches
state. - Example: The video demonstrates asking the agent for the stock prices of Apple, Tesla, and Google. The
recent_searches
state is updated with each search. - Session Management: The web interface allows users to create new sessions, each with its own state.
5. Building a Multi-Tool Agent
- Multiple Tools: The video demonstrates how to create an agent that can use multiple tools.
get_stock_info
Function: A second tool,get_stock_info(company_name)
, is created to retrieve company information (ticker symbol and sector).- Tool List: Both
get_stock_price
andget_stock_info
are added to the agent's tool list. - Example: The video demonstrates asking the agent "Give me stock price of Apple and info." The agent uses both tools to provide the requested information.
6. Creating a Structured Output Agent
- Structured Output: The video explains how to create an agent that returns responses in a structured format using Pydantic.
- Pydantic: Pydantic is used to define the structure of the output.
StockAnalysis
Class: A Pydantic classStockAnalysis
is created with fields forticker_symbol
andrecommendation
.LLM Agent
: The video usesLLM Agent
for structured output.- Output Schema: The
output_schema
andoutput_key
parameters are used to specify the Pydantic class and the key for the output. - Example: The video demonstrates asking the agent "Tell me about the stock of Apple." The agent returns a structured response with the ticker symbol and a recommendation (e.g., "buy").
- Limitation: Structured responses do not currently support tools.
7. Implementing a Callback Agent
- Callback Functions: The video explains how to use callback functions to execute code before and after tool calls.
before_tool_callback
Function: A functionbefore_tool_callback
is created to run before a tool is called.after_tool_callback
Function: A functionafter_tool_callback
is created to run after a tool is called.- Callback Agent: A
callback_agent
is created with thebefore_tool_callback
andafter_tool_callback
functions specified. - Example: The video demonstrates asking the agent "What is the stock price of Apple?" The callback functions are executed before and after the
get_stock_data
tool is called. - Tracing: The trace function can be used to see clear trace information.
8. Deploying the Agent
- Deployment Options: The video mentions three deployment options: Vertex AI Agent Engine, Cloud Run, and custom infrastructure.
- Cloud Run Deployment: The video demonstrates deploying the agent to Cloud Run.
- Prerequisites: A Google Cloud account and the gcloud CLI are required.
- Login: The command
gcloud auth login
is used to log in to the Google Cloud account. - Deployment Command: The command
ADK deploy cloud run app
is used to deploy the agent to Cloud Run. - Location Selection: The user is prompted to choose a location for the deployment.
9. Setting Up the API Server
- API Server: The video explains how to set up an API server for the agent.
- Command: The command
ADK API server
starts the API server. - Documentation: The
/docs
endpoint provides documentation on the available API endpoints.
10. Conclusion
- The video concludes by summarizing the features covered: basic agent, agent with tool, agent with state, multi-tool agent, structured output agent, and callback agent.
- It mentions additional features like runner setting up MCP tools that will be covered in future videos.
- The video encourages viewers to watch another video about Olama MCP agent.
Chat with this Video
AI-PoweredHi! I can answer questions about this video "Google Agent Development Kit: EASIEST way to create AI Agents!". What would you like to know?
Chat is based on the transcript of this video and may not be 100% accurate.