From 36ebfb2352b9165f0075656ff86ef811733b4830 Mon Sep 17 00:00:00 2001 From: Charlene Date: Fri, 30 May 2025 14:19:24 -0400 Subject: [PATCH] testing --- .../app/google_search_agent/__init__.py | 1 + .../app/google_search_agent/agent.py | 16 +++++ src/google/adk/cli/utils/logs.py | 8 ++- src/google/adk/multi_tool_agent/__init__.py | 1 + src/google/adk/multi_tool_agent/agent.py | 67 +++++++++++++++++++ 5 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 src/google/adk-streaming/app/google_search_agent/__init__.py create mode 100644 src/google/adk-streaming/app/google_search_agent/agent.py create mode 100644 src/google/adk/multi_tool_agent/__init__.py create mode 100644 src/google/adk/multi_tool_agent/agent.py diff --git a/src/google/adk-streaming/app/google_search_agent/__init__.py b/src/google/adk-streaming/app/google_search_agent/__init__.py new file mode 100644 index 000000000..63bd45e6d --- /dev/null +++ b/src/google/adk-streaming/app/google_search_agent/__init__.py @@ -0,0 +1 @@ +from . import agent \ No newline at end of file diff --git a/src/google/adk-streaming/app/google_search_agent/agent.py b/src/google/adk-streaming/app/google_search_agent/agent.py new file mode 100644 index 000000000..139327cb5 --- /dev/null +++ b/src/google/adk-streaming/app/google_search_agent/agent.py @@ -0,0 +1,16 @@ +from google.adk.agents import Agent +from google.adk.tools import google_search # Import the tool + +root_agent = Agent( + # A unique name for the agent. + name="basic_search_agent", + # The Large Language Model (LLM) that agent will use. + model="gemini-2.0-flash-exp", # Google AI Studio + #model="gemini-2.0-flash-live-preview-04-09" # Vertex AI Studio + # A short description of the agent's purpose. + description="Agent to answer questions using Google Search.", + # Instructions to set the agent's behavior. + instruction="You are an expert researcher. You always stick to the facts.", + # Add google_search tool to perform grounding with Google search. + tools=[google_search] +) \ No newline at end of file diff --git a/src/google/adk/cli/utils/logs.py b/src/google/adk/cli/utils/logs.py index 9723df061..a6035cc40 100644 --- a/src/google/adk/cli/utils/logs.py +++ b/src/google/adk/cli/utils/logs.py @@ -16,6 +16,7 @@ import os import tempfile import time +import shutil LOGGING_FORMAT = ( '%(asctime)s - %(levelname)s - %(filename)s:%(lineno)d - %(message)s' @@ -64,9 +65,10 @@ def log_to_tmp_folder( print(f'Log setup complete: {log_filepath}') latest_log_link = os.path.join(log_dir, f'{log_file_prefix}.latest.log') - if os.path.islink(latest_log_link): - os.unlink(latest_log_link) - os.symlink(log_filepath, latest_log_link) + try: + shutil.copy2(log_filepath, latest_log_link) + except Exception as e: + logging.getLogger(__name__).error(f"Failed to update latest log link: {e}") print(f'To access latest log: tail -F {latest_log_link}') return log_filepath diff --git a/src/google/adk/multi_tool_agent/__init__.py b/src/google/adk/multi_tool_agent/__init__.py new file mode 100644 index 000000000..63bd45e6d --- /dev/null +++ b/src/google/adk/multi_tool_agent/__init__.py @@ -0,0 +1 @@ +from . import agent \ No newline at end of file diff --git a/src/google/adk/multi_tool_agent/agent.py b/src/google/adk/multi_tool_agent/agent.py new file mode 100644 index 000000000..da6309a89 --- /dev/null +++ b/src/google/adk/multi_tool_agent/agent.py @@ -0,0 +1,67 @@ +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], +) \ No newline at end of file