-
Notifications
You must be signed in to change notification settings - Fork 1.4k
rebase keras3-dev on the current master #695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1baa5ad
cc955da
154079e
1b04833
280b93a
b9f928d
037042e
d89fc88
1cf2277
dee08bb
347de54
378b928
82d23cf
cf3c428
5519f11
754551e
9624bc6
6d4f7d8
326fbd1
418aa14
becec16
883d441
b9effab
2014b25
0b71d20
6234414
2ba415e
be3ce6b
b29cbaf
03a5e29
5661849
c4c4f83
a6df3d2
e091d74
067d916
b0782f1
b06872e
b938420
aa117da
e363d25
d60f5d4
d6d4450
7b2d43b
4cd6142
0bad91d
61e0464
6ee2c4a
73188ee
3dd550b
aa72282
4332ff1
f3570d4
54a2e85
15b6657
8ac1102
5fafa97
7d5e600
9f66373
3acc746
385e7cf
ba883ef
d0f0d4a
db11625
950d626
2d0fe67
c8b0b88
6cc65ad
47e0f37
87026b8
d6c4d98
3d45b2a
8ca65dc
f40d493
f3199fc
c195e25
84921f7
9009696
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # pylint: skip-file | ||
| from . import agent |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # pylint: skip-file | ||
| from google.adk.agents import Agent | ||
|
|
||
| MODEL = "gemini-2.0-flash" | ||
|
|
||
| from .tools import get_weather | ||
|
|
||
| root_agent = None # TODO - define the weather agent | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # pylint: skip-file | ||
| def get_weather(city: str) -> dict: | ||
| """TODO:Write a docstring for the | ||
| get_weather agent with a description of what the tool is | ||
| supposed to do and also the arguments that are needed. | ||
| """ | ||
|
Comment on lines
+3
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The docstring for the """Retrieves the current weather report for a specified city.
Args:
city (str): The name of the city (e.g., "New York", "London", "Tokyo").
""" |
||
| print( | ||
| f"--- Tool: get_weather called for city: {city} ---" | ||
| ) # Log tool execution | ||
| city_normalized = city.lower().replace(" ", "") # Basic normalization | ||
|
|
||
| # Mock weather data | ||
| mock_weather_db = { | ||
| "newyork": { | ||
| "status": "success", | ||
| "report": "The weather in New York is sunny with a temperature of 25°C.", | ||
| }, | ||
| "london": { | ||
| "status": "success", | ||
| "report": "It's cloudy in London with a temperature of 15°C.", | ||
| }, | ||
| "tokyo": { | ||
| "status": "success", | ||
| "report": "Tokyo is experiencing light rain and a temperature of 18°C.", | ||
| }, | ||
| } | ||
|
|
||
| if city_normalized in mock_weather_db: | ||
| return mock_weather_db[city_normalized] | ||
| else: | ||
| return { | ||
| "status": "error", | ||
| "error_message": f"Sorry, I don't have weather information for '{city}'.", | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # pylint: skip-file | ||
| from . import agent |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # pylint: skip-file | ||
| from google.adk.agents import Agent | ||
|
|
||
| MODEL = "gemini-2.0-flash" | ||
|
|
||
| from .tools import get_weather, say_goodbye, say_hello | ||
|
|
||
| # --- Greeting Agent --- | ||
| greeting_agent = Agent( | ||
| # TODO - Define the greeting agent | ||
| ) | ||
|
Comment on lines
+9
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| # --- Farewell Agent --- | ||
| farewell_agent = Agent( | ||
| model=MODEL, | ||
| name="farewell_agent", | ||
| instruction="You are the Farewell Agent. Your ONLY task is to provide a polite goodbye message. " | ||
| "Use the 'say_goodbye' tool when the user indicates they are leaving or ending the conversation " | ||
| "(e.g., using words like 'bye', 'goodbye', 'thanks bye', 'see you'). " | ||
| "Do not perform any other actions.", | ||
| description="Handles simple farewells and goodbyes using the 'say_goodbye' tool.", # Crucial for delegation | ||
| tools=[say_goodbye], | ||
| ) | ||
|
|
||
| root_agent = Agent( | ||
| name="weather_agent_v2", # Give it a new version name | ||
| model=MODEL, | ||
| description="The main coordinator agent. Handles weather requests and delegates greetings/farewells to specialists.", | ||
| instruction="You are the main Weather Agent coordinating a team. Your primary responsibility is to provide weather information. " | ||
| "Use the 'get_weather' tool ONLY for specific weather requests (e.g., 'weather in London'). " | ||
| "You have specialized sub-agents: " | ||
| "1. 'greeting_agent': Handles simple greetings like 'Hi', 'Hello'. Delegate to it for these. " | ||
| "2. 'farewell_agent': Handles simple farewells like 'Bye', 'See you'. Delegate to it for these. " | ||
| "Analyze the user's query. If it's a greeting, delegate to 'greeting_agent'. If it's a farewell, delegate to 'farewell_agent'. " | ||
| "If it's a weather request, handle it yourself using 'get_weather'. " | ||
| "For anything else, respond appropriately or state you cannot handle it.", | ||
| tools=[get_weather], | ||
| sub_agents=[greeting_agent, farewell_agent], | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # pylint: skip-file | ||
| def get_weather(city: str) -> dict: | ||
| """Retrieves the current weather report for a specified city. | ||
|
|
||
| Args: | ||
| city (str): The name of the city (e.g., "New York", "London", "Tokyo"). | ||
|
|
||
| Returns: | ||
| dict: A dictionary containing the weather information. | ||
| Includes a 'status' key ('success' or 'error'). | ||
| If 'success', includes a 'report' key with weather details. | ||
| If 'error', includes an 'error_message' key. | ||
| """ | ||
| print( | ||
| f"--- Tool: get_weather called for city: {city} ---" | ||
| ) # Log tool execution | ||
| city_normalized = city.lower().replace(" ", "") # Basic normalization | ||
|
|
||
| # Mock weather data | ||
| mock_weather_db = { | ||
| "newyork": { | ||
| "status": "success", | ||
| "report": "The weather in New York is sunny with a temperature of 25°C.", | ||
| }, | ||
| "london": { | ||
| "status": "success", | ||
| "report": "It's cloudy in London with a temperature of 15°C.", | ||
| }, | ||
| "tokyo": { | ||
| "status": "success", | ||
| "report": "Tokyo is experiencing light rain and a temperature of 18°C.", | ||
| }, | ||
| } | ||
|
|
||
| if city_normalized in mock_weather_db: | ||
| return mock_weather_db[city_normalized] | ||
| else: | ||
| return { | ||
| "status": "error", | ||
| "error_message": f"Sorry, I don't have weather information for '{city}'.", | ||
| } | ||
|
|
||
|
|
||
| def say_hello(name: str = "there") -> str: | ||
| """Provides a simple greeting, optionally addressing the user by name. | ||
|
|
||
| Args: | ||
| name (str, optional): The name of the person to greet. Defaults to "there". | ||
|
|
||
| Returns: | ||
| str: A friendly greeting message. | ||
| """ | ||
| if name is None or name.strip() == "": | ||
| name = "there" | ||
| print(f"--- Tool: say_hello called with name: {name} ---") | ||
| return f"Hello, {name}!" | ||
|
|
||
|
|
||
| def say_goodbye() -> str: | ||
| """Provides a simple farewell message to conclude the conversation.""" | ||
| print(f"--- Tool: say_goodbye called ---") | ||
| return "Goodbye! Have a great day." |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # pylint: skip-file | ||
| from . import agent |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # pylint: skip-file | ||
| from google.adk.agents import Agent | ||
|
|
||
| MODEL = "gemini-2.0-flash" | ||
|
|
||
| from .tools import ( | ||
| get_weather_stateful, | ||
| say_goodbye, | ||
| say_hello, | ||
| set_user_preference, | ||
| ) | ||
|
|
||
| greeting_agent = Agent( | ||
| model=MODEL, | ||
| name="greeting_agent", | ||
| instruction="You are the Greeting Agent. Your ONLY task is to provide a friendly greeting using the 'say_hello' tool. Do nothing else.", | ||
| description="Handles simple greetings and hellos using the 'say_hello' tool.", | ||
| tools=[say_hello], | ||
| ) | ||
|
|
||
| farewell_agent = Agent( | ||
| model=MODEL, | ||
| name="farewell_agent", | ||
| instruction="You are the Farewell Agent. Your ONLY task is to provide a polite goodbye message using the 'say_goodbye' tool. Do not perform any other actions.", | ||
| description="Handles simple farewells and goodbyes using the 'say_goodbye' tool.", | ||
| tools=[say_goodbye], | ||
| ) | ||
|
|
||
| root_agent = Agent( | ||
| name="weather_agent_v3_stateful", # New version name | ||
| model=MODEL, | ||
| description="Main agent: Provides weather (state-aware unit), delegates greetings/farewells, saves report to state.", | ||
| instruction="You are the main Weather Agent. Your job is to provide weather using 'get_weather_stateful'. " | ||
| "If user want to change prefered temperature unit (Celsius/Fahrenheit), use 'set_user_preference' and and change 'user:temperature_unit' state." | ||
| "The tool will format the temperature based on user preference stored in state. " | ||
| "Delegate simple greetings to 'greeting_agent' and farewells to 'farewell_agent'. " | ||
| "Handle only weather requests, greetings, and farewells.", | ||
| tools=[ | ||
| get_weather_stateful, | ||
| set_user_preference, | ||
| ], # Use the state-aware tool | ||
| sub_agents=[greeting_agent, farewell_agent], # Include sub-agents | ||
| output_key="last_weather_report", # <<< Auto-save agent's final weather response | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
root_agentis initialized toNonewith aTODOto define the weather agent. This file seems incomplete and the agent is not functional.