Skip to content

Instantly share code, notes, and snippets.

@kuc-arc-f
Last active June 15, 2025 02:14
Show Gist options
  • Save kuc-arc-f/6681d0aa03acc25c38471e508d311b62 to your computer and use it in GitHub Desktop.
Save kuc-arc-f/6681d0aa03acc25c38471e508d311b62 to your computer and use it in GitHub Desktop.
seq_agent2 , agent example
GOOGLE_GENAI_USE_VERTEXAI=FALSE
GOOGLE_API_KEY="key"
from . import agent
import datetime
from zoneinfo import ZoneInfo
from google.adk.agents import Agent
from datetime import datetime, timedelta, timezone
from google.adk.agents import LlmAgent
import logging
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s %(levelname)s %(name)s: %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
)
#logging.info("通常の情報メッセージ")
def get_current_date(time_difference: int) -> str:
"""Return the current date expressed in the format %m月%d日.
Args:
time_difference (int): Time difference from Coordinated Universal Time (UTC)
Returns:
str: Current time expressed in the format %m月%d日
"""
tz = timezone(timedelta(hours=time_difference))
now = datetime.now(tz)
return now.strftime("%m月%d日")
current_date_agent = LlmAgent(
name="current_date_agent",
model="gemini-2.0-flash",
description="Agent to answer questions about the current date.",
instruction=(
"You are a helpful agent that answers questions about the current date."
"First, guess the time difference from Coordinated Universal Time (UTC) for the city specified by the user."
"Then, retrieve the current date based on the time difference using the `get_current_date` tool."
"Be sure to include the city name and the current date in the `%m月%d日` format in your answer."
),
tools=[get_current_date],
output_key="current_date"
)
from pydantic import BaseModel, Field
from google.adk.agents import LlmAgent
class DateOutput(BaseModel):
city: str = Field(description="A city name")
date: str = Field(description="A date in the format `%m月%d日`")
tomorrows_date_agent = LlmAgent(
name="tomorrows_date_agent",
model="gemini-2.0-flash",
instruction=(
"You are a helpful agent that answers tomorrow's date for a specified city."
"You are given the city name and the current date as input."
"Be sure to include the city name and tomorrow's date in the `%m月%d日` format in your answer."
"**the city name and the current date**"
"{current_date}"
),
output_schema=DateOutput,
output_key="tomorrow_date"
)
from google.adk.agents import SequentialAgent
root_agent = SequentialAgent(
name="tomorrows_date_agent",
sub_agents=[current_date_agent, tomorrows_date_agent]
)
#sub_agents=[current_date_agent, tomorrows_date_agent, tomorrows_weather_agent]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment