mcp_client / agents /place_agent.py
SrikanthNagelli's picture
initial commit
100c46f
"""
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)}"