Update sub_agents.py
Browse files- sub_agents.py +49 -9
sub_agents.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
from deepagents.middleware.subagents import SubAgent
|
| 2 |
-
from tools import route_tool, cost_tool, traffic_tool, weather_tool
|
| 3 |
|
| 4 |
route_agent = SubAgent(
|
| 5 |
name="RealRouteAgent",
|
|
@@ -20,6 +20,29 @@ route_agent = SubAgent(
|
|
| 20 |
tools=[route_tool],
|
| 21 |
)
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
cost_agent = SubAgent(
|
| 24 |
name="RealCostAgent",
|
| 25 |
description="Calculates costs when origin, destination, distance, weight, and duration are provided",
|
|
@@ -59,22 +82,28 @@ traffic_agent = SubAgent(
|
|
| 59 |
tools=[traffic_tool],
|
| 60 |
)
|
| 61 |
|
| 62 |
-
weather_agent
|
| 63 |
name="RealWeatherAnalyzer",
|
| 64 |
-
description="Analyzes weather when both origin and destination are provided",
|
| 65 |
system_prompt="""
|
| 66 |
-
You are a weather analysis expert.
|
| 67 |
|
| 68 |
CRITICAL RULES:
|
| 69 |
- ONLY use 'real_weather_analyzer' if user provides BOTH origin AND destination
|
|
|
|
| 70 |
- If locations are missing, respond: "I need both origin and destination to analyze weather. Please provide both locations."
|
| 71 |
- DO NOT assume locations
|
| 72 |
- DO NOT analyze weather if user only asks for cost calculations
|
| 73 |
|
| 74 |
-
When locations ARE provided
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
)
|
| 77 |
|
|
|
|
| 78 |
coordinator = SubAgent(
|
| 79 |
name="Coordinator",
|
| 80 |
description="Synthesizes information and handles user queries intelligently",
|
|
@@ -101,9 +130,20 @@ coordinator = SubAgent(
|
|
| 101 |
4. IF user asks for WEATHER analysis:
|
| 102 |
- Check if BOTH origin AND destination are provided
|
| 103 |
- If missing, ask for them
|
| 104 |
-
- If provided, use weather agent
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
- Check if ALL required info is provided (origin, destination, weight)
|
| 108 |
- If anything is missing, ask for it
|
| 109 |
- If all provided, coordinate all agents
|
|
|
|
| 1 |
from deepagents.middleware.subagents import SubAgent
|
| 2 |
+
from tools import route_tool, cost_tool, traffic_tool, weather_tool,forecast_weather_tool, multi_route_tool
|
| 3 |
|
| 4 |
route_agent = SubAgent(
|
| 5 |
name="RealRouteAgent",
|
|
|
|
| 20 |
tools=[route_tool],
|
| 21 |
)
|
| 22 |
|
| 23 |
+
multi_route_agent = SubAgent(
|
| 24 |
+
name="MultiRouteAgent",
|
| 25 |
+
description="Plans optimal route visiting multiple destinations when origin and list of destinations are provided",
|
| 26 |
+
system_prompt="""
|
| 27 |
+
You are a multi-destination route optimization expert.
|
| 28 |
+
|
| 29 |
+
CRITICAL RULES:
|
| 30 |
+
- ONLY use 'multi_route_planner' if user provides:
|
| 31 |
+
* ONE origin location
|
| 32 |
+
* MULTIPLE destination locations (2 or more)
|
| 33 |
+
- If locations are missing, respond: "I need an origin and at least 2 destinations to plan a multi-stop route."
|
| 34 |
+
- DO NOT use this for single destination - use regular route planning instead
|
| 35 |
+
- Valid queries: "Route from Delhi to Bhopal, Chandigarh, and Rohtak"
|
| 36 |
+
|
| 37 |
+
When all locations ARE provided:
|
| 38 |
+
- Find the optimal visiting order that minimizes total travel time
|
| 39 |
+
- Show total distance and duration
|
| 40 |
+
- Present step-by-step route segments
|
| 41 |
+
""",
|
| 42 |
+
tools=[multi_route_tool],
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
cost_agent = SubAgent(
|
| 47 |
name="RealCostAgent",
|
| 48 |
description="Calculates costs when origin, destination, distance, weight, and duration are provided",
|
|
|
|
| 82 |
tools=[traffic_tool],
|
| 83 |
)
|
| 84 |
|
| 85 |
+
weather_agent = SubAgent(
|
| 86 |
name="RealWeatherAnalyzer",
|
| 87 |
+
description="Analyzes current and forecasted weather when both origin and destination are provided",
|
| 88 |
system_prompt="""
|
| 89 |
+
You are a weather analysis expert with forecasting capabilities.
|
| 90 |
|
| 91 |
CRITICAL RULES:
|
| 92 |
- ONLY use 'real_weather_analyzer' if user provides BOTH origin AND destination
|
| 93 |
+
- Use 'forecast_weather' when user asks for future weather predictions at a location
|
| 94 |
- If locations are missing, respond: "I need both origin and destination to analyze weather. Please provide both locations."
|
| 95 |
- DO NOT assume locations
|
| 96 |
- DO NOT analyze weather if user only asks for cost calculations
|
| 97 |
|
| 98 |
+
When locations ARE provided:
|
| 99 |
+
- Give insights on CURRENT weather conditions using real_weather_analyzer
|
| 100 |
+
- If user asks about future weather, also use forecast_weather for each location
|
| 101 |
+
- Combine current conditions with forecasted trends for better insights
|
| 102 |
+
""",
|
| 103 |
+
tools=[weather_tool, forecast_weather_tool]
|
| 104 |
)
|
| 105 |
|
| 106 |
+
|
| 107 |
coordinator = SubAgent(
|
| 108 |
name="Coordinator",
|
| 109 |
description="Synthesizes information and handles user queries intelligently",
|
|
|
|
| 130 |
4. IF user asks for WEATHER analysis:
|
| 131 |
- Check if BOTH origin AND destination are provided
|
| 132 |
- If missing, ask for them
|
| 133 |
+
- If provided, use weather agent for CURRENT conditions
|
| 134 |
+
- If user asks about FUTURE weather (e.g., "will it rain tomorrow?", "forecast", "next 24 hours"):
|
| 135 |
+
* Also call forecast_weather for origin and destination
|
| 136 |
+
* Combine current conditions with forecast trends
|
| 137 |
+
- Present comprehensive weather analysis
|
| 138 |
+
|
| 139 |
+
5. IF user asks for MULTI-DESTINATION route planning:
|
| 140 |
+
- Check if origin AND multiple destinations (2+) are provided
|
| 141 |
+
- If missing, ask for them
|
| 142 |
+
- If provided, use multi_route_agent
|
| 143 |
+
- Present optimal visiting order with time/distance breakdown
|
| 144 |
+
- Format response as shown in RESPONSE FORMATS section
|
| 145 |
+
|
| 146 |
+
6. IF user asks for COMPLETE delivery planning (route + cost + traffic + weather):
|
| 147 |
- Check if ALL required info is provided (origin, destination, weight)
|
| 148 |
- If anything is missing, ask for it
|
| 149 |
- If all provided, coordinate all agents
|