Spaces:
Sleeping
Sleeping
| """ | |
| Hiking agent for outdoor activities and trail searches. | |
| """ | |
| import re | |
| from typing import Dict | |
| from .base_agent import BaseAgent | |
| from services.hiking_service import HikingRecommendationServer | |
| class HikingAgent(BaseAgent): | |
| """Specialized agent for finding hiking trails and outdoor activities.""" | |
| def _define_capabilities(self) -> Dict[str, float]: | |
| """Define hiking search capabilities.""" | |
| return { | |
| "hike": 0.9, | |
| "hikes": 0.9, | |
| "hiking": 0.9, | |
| "trail": 0.9, | |
| "trails": 0.9, | |
| "trek": 0.8, | |
| "trekking": 0.8, | |
| "outdoor": 0.7, | |
| "mountain": 0.7, | |
| "walk": 0.6, | |
| "walking": 0.6, | |
| "nature": 0.6 | |
| } | |
| def execute(self, task: str) -> str: | |
| """Execute hiking search task.""" | |
| try: | |
| # Extract location and parameters | |
| location_pattern = r"(?:in|at|near|around|close to)\s+([a-zA-Z\s,]+)(?:\.|$|\s)" | |
| location_match = re.search(location_pattern, task.lower()) | |
| location = location_match.group(1).strip() if location_match else task | |
| # Initialize hiking server | |
| hiking_server = HikingRecommendationServer() | |
| # Get difficulty from task if mentioned | |
| difficulty = "All" | |
| if "easy" in task.lower(): | |
| difficulty = "Easy" | |
| elif "moderate" in task.lower(): | |
| difficulty = "Moderate" | |
| elif "hard" in task.lower() or "difficult" in task.lower(): | |
| difficulty = "Hard" | |
| elif "very hard" in task.lower() or "extreme" in task.lower(): | |
| difficulty = "Very Hard" | |
| # Get distance from task if mentioned | |
| distance_pattern = r"within\s+(\d+)\s*(?:mile|miles|mi)" | |
| distance_match = re.search(distance_pattern, task.lower()) | |
| max_distance = int(distance_match.group(1)) if distance_match else 50 | |
| # Get recommendations | |
| results = hiking_server.get_hiking_recommendations_structured(location, max_distance, difficulty) | |
| if not results["success"]: | |
| return results["message"] | |
| # Format output | |
| output = f"ποΈ **Hiking Trails near {location.title()}** ποΈ\n" | |
| output += f"(Within {max_distance} miles, Difficulty: {difficulty})\n\n" | |
| stats = results["stats"] | |
| output += "π **Quick Stats:**\n" | |
| output += f"β’ Total Trails: {stats['total_hikes']}\n" | |
| output += f"β’ Average Distance: {stats['avg_distance']} miles\n" | |
| output += f"β’ Average Elevation: {stats['avg_elevation']} ft\n\n" | |
| for i, hike in enumerate(results['hikes'][:5], 1): | |
| output += f"**#{i} {hike['name']}**\n" | |
| output += f"π― **Difficulty:** {hike['difficulty_level']}\n" | |
| output += f"π **Distance:** {hike['distance']} miles\n" | |
| output += f"β°οΈ **Elevation:** {hike['elevation_gain']} ft\n" | |
| output += f"β **Rating:** {hike['rating']} ({hike['reviews']} reviews)\n" | |
| output += "β" * 40 + "\n\n" | |
| output += "π₯Ύ *Happy hiking!* π₯Ύ" | |
| return output | |
| except Exception as e: | |
| return f"β Error searching for hiking trails: {str(e)}" |