% python -m venv .venv
% source .venv/bin/activate
% pip install google-adk
% mkdir multi_tool_agent
% cd multi_tool_agent
% echo "from . import agent" > __init__.py
공식사이트에 있는 그대로 퍼옴
import datetime
from zoneinfo import ZoneInfo
from google.adk.agents import Agent
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 (77 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 = Agent(
name="weather_time_agent",
model="gemini-2.0-flash",
description=(
"Agent to answer questions about the time and weather in a city."
),
instruction=(
"You are a helpful agent who can answer user questions about the time and weather in a city."
),
tools=[get_weather, get_current_time],
)
https://aistudio.google.com/apikey
기존 프로젝트에서 API 키 만들기 (또는 프로젝트 생성 후 재시도)
프로젝트 이름 옆의 아이콘 클릭
방금 만든 따끈따끈한 API Key
GOOGLE_GENAI_USE_VERTEXAI=FALSE
GOOGLE_API_KEY=<<Google Api Key 입력>>
소스가 들어있는 multi_tool_agent 와 동일 레벨 폴더에서 실행한다.
% adk run multi_tool_agent
시간 알려주는 mcp와 날씨 알려주는 mcp가 있다.
오직 시간과 날짜만...ㅠㅠ
이전까지 claude desktop, cursor ai, langchain+ollama 등으로 mcp 를 사부작사부작 만들었는데 google-adk 는 뭔가 기다렸다는 듯히 딱! 하고 등장한 느낌이다. API 를 거의 무료로 사용 가능하고(한도 내에서) 속도도 괜찮고 테스트 가능한 모델도 많아서 꽤 오랜 시간 이걸 가지고 둘러보지 않을까...