Spaces:
Sleeping
Sleeping
| """ | |
| Place agent for hotel and accommodation searches. | |
| """ | |
| import re | |
| from typing import Dict | |
| from .base_agent import BaseAgent | |
| from services.place_service import place_service | |
| class PlaceAgent(BaseAgent): | |
| """Specialized agent for finding hotels and accommodations.""" | |
| def _define_capabilities(self) -> Dict[str, float]: | |
| """Define place search capabilities.""" | |
| return { | |
| "hotel": 0.9, | |
| "hotels": 0.9, | |
| "accommodation": 0.9, | |
| "accommodations": 0.9, | |
| "place to stay": 0.9, | |
| "places to stay": 0.9, | |
| "stay": 0.8, | |
| "lodging": 0.8, | |
| "motel": 0.8, | |
| "resort": 0.8 | |
| } | |
| def execute(self, task: str) -> str: | |
| """Execute place search task.""" | |
| try: | |
| # Clean up the task for better tool matching | |
| task = task.strip() | |
| # 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 | |
| # Remove common prefixes to get clean location | |
| location = location.replace('hotels in ', '').replace('hotel in ', '').replace('find hotels in ', '').strip() | |
| # 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 None | |
| # Get recommendations using PlaceService | |
| results = place_service.search_places(location, max_distance) | |
| if "error" in results: | |
| return f"β {results['error']}" | |
| # Format output | |
| output = f"π¨ **Hotels & Accommodations in {results['location'].title()}** π¨\n" | |
| output += f"(Search radius: {results['search_radius']})\n\n" | |
| output += f"π **Quick Stats:**\n" | |
| output += f"β’ Total Found: {results['total_found']} places\n" | |
| output += f"β’ Showing Top: {len(results['top_places'])} results\n\n" | |
| for i, place in enumerate(results['top_places'], 1): | |
| output += f"**#{i} {place['name']}** β\n" | |
| output += f"π¨ **Type:** {place['type']}\n" | |
| output += f"π **Address:** {place['address']}\n" | |
| output += f"πΆ **Distance:** {place['distance']}\n" | |
| if place['rating'] != 'Not rated': | |
| output += f"β **Rating:** {place['rating']}\n" | |
| if place['description'] != 'No description available': | |
| output += f"βΉοΈ **About:** {place['description'][:150]}...\n" | |
| output += "\n" + "β" * 50 + "\n\n" | |
| output += "π *Happy travels!* π" | |
| return output | |
| except Exception as e: | |
| return f"β Error searching for places: {str(e)}" |