Refactor: Clean up obsolete files and organize codebase structure
This commit removes deprecated modules and reorganizes code into logical directories: Deleted files (superseded by newer systems): - claude_code_server.py (replaced by agent-sdk direct integration) - heartbeat.py (superseded by scheduled_tasks.py) - pulse_brain.py (unused in production) - config/pulse_brain_config.py (obsolete config) Created directory structure: - examples/ (7 example files: example_*.py, demo_*.py) - tests/ (5 test files: test_*.py) Updated imports: - agent.py: Removed heartbeat module and all enable_heartbeat logic - bot_runner.py: Removed heartbeat parameter from Agent initialization - llm_interface.py: Updated deprecated claude_code_server message Preserved essential files: - hooks.py (for future use) - adapters/skill_integration.py (for future use) - All Google integration tools (Gmail, Calendar, Contacts) - GLM provider code (backward compatibility) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
77
tools.py
77
tools.py
@@ -100,6 +100,21 @@ TOOL_DEFINITIONS = [
|
||||
"required": ["command"],
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "get_weather",
|
||||
"description": "Get current weather for a location using OpenWeatherMap API. Returns temperature, conditions, and brief summary.",
|
||||
"input_schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"location": {
|
||||
"type": "string",
|
||||
"description": "City name or 'City, Country' (e.g., 'Phoenix, US' or 'London, GB'). Defaults to Phoenix, AZ if not specified.",
|
||||
"default": "Phoenix, US",
|
||||
}
|
||||
},
|
||||
"required": [],
|
||||
},
|
||||
},
|
||||
# Gmail tools
|
||||
{
|
||||
"name": "send_email",
|
||||
@@ -345,6 +360,9 @@ def execute_tool(tool_name: str, tool_input: Dict[str, Any], healing_system: Any
|
||||
command = tool_input["command"]
|
||||
working_dir = tool_input.get("working_dir", ".")
|
||||
return _run_command(command, working_dir)
|
||||
elif tool_name == "get_weather":
|
||||
location = tool_input.get("location", "Phoenix, US")
|
||||
return _get_weather(location)
|
||||
# Gmail tools
|
||||
elif tool_name == "send_email":
|
||||
return _send_email(
|
||||
@@ -530,6 +548,65 @@ def _run_command(command: str, working_dir: str) -> str:
|
||||
return f"Error running command: {str(e)}"
|
||||
|
||||
|
||||
def _get_weather(location: str = "Phoenix, US") -> str:
|
||||
"""Get current weather for a location using OpenWeatherMap API.
|
||||
|
||||
Args:
|
||||
location: City name or 'City, Country' (e.g., 'Phoenix, US')
|
||||
|
||||
Returns:
|
||||
Weather summary string
|
||||
"""
|
||||
import requests
|
||||
|
||||
api_key = os.getenv("OPENWEATHERMAP_API_KEY")
|
||||
if not api_key:
|
||||
return "Error: OPENWEATHERMAP_API_KEY not found in environment variables. Please add it to your .env file."
|
||||
|
||||
try:
|
||||
# OpenWeatherMap API endpoint
|
||||
base_url = "http://api.openweathermap.org/data/2.5/weather"
|
||||
params = {
|
||||
"q": location,
|
||||
"appid": api_key,
|
||||
"units": "imperial" # Fahrenheit
|
||||
}
|
||||
|
||||
response = requests.get(base_url, params=params, timeout=10)
|
||||
response.raise_for_status()
|
||||
|
||||
data = response.json()
|
||||
|
||||
# Extract weather data
|
||||
temp = data["main"]["temp"]
|
||||
feels_like = data["main"]["feels_like"]
|
||||
description = data["weather"][0]["description"].capitalize()
|
||||
humidity = data["main"]["humidity"]
|
||||
wind_speed = data["wind"]["speed"]
|
||||
city = data["name"]
|
||||
|
||||
# Format weather summary
|
||||
summary = f"**{city} Weather:**\n"
|
||||
summary += f"🌡️ {temp}°F (feels like {feels_like}°F)\n"
|
||||
summary += f"☁️ {description}\n"
|
||||
summary += f"💧 Humidity: {humidity}%\n"
|
||||
summary += f"💨 Wind: {wind_speed} mph"
|
||||
|
||||
return summary
|
||||
|
||||
except requests.exceptions.HTTPError as e:
|
||||
if e.response.status_code == 401:
|
||||
return "Error: Invalid OpenWeatherMap API key. Please check your OPENWEATHERMAP_API_KEY in .env file."
|
||||
elif e.response.status_code == 404:
|
||||
return f"Error: Location '{location}' not found. Try format: 'City, Country' (e.g., 'Phoenix, US')"
|
||||
else:
|
||||
return f"Error: OpenWeatherMap API error: {e}"
|
||||
except requests.exceptions.Timeout:
|
||||
return "Error: Weather API request timed out. Please try again."
|
||||
except Exception as e:
|
||||
return f"Error getting weather: {str(e)}"
|
||||
|
||||
|
||||
# Google Tools Handlers
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user