demeter

Autonomous Hydroponic Intelligence

agent/sub_agents/water_and_atmospheric_dependencies/tools.py (1098B)


 1from langchain.tools import tool
 2import math
 3
 4@tool
 5def calculate_vpd(air_temp_c: float, humidity: float) -> float:
 6    """Calculates Vapor Pressure Deficit (kPa). Target: 0.8-1.2 kPa."""
 7    svp = 0.6108 * math.exp((17.27 * air_temp_c) / (air_temp_c + 237.3))
 8    avp = svp * (humidity / 100.0)
 9    return round(svp - avp, 2)
10
11@tool
12def check_ph_safety(current_ph: float, proposed_change: float) -> str:
13    """Checks if a pH swing is too aggressive (>0.5 change)."""
14    predicted_ph = current_ph + proposed_change
15    swing = abs(predicted_ph - current_ph)
16    if swing > 0.5:
17        return f"DANGER: pH swing of {swing} is too high. Max safe swing is 0.5."
18    if predicted_ph < 5.0 or predicted_ph > 7.0:
19        return f"WARNING: Target pH {predicted_ph} is out of safe range (5.5-6.5)."
20    return "SAFE"
21
22# Placeholder for your Web Search (Tavily/Serper)
23@tool
24def web_search(query: str) -> str:
25    """Searches the web for specific hydroponic thresholds."""
26    # Implement your search logic here (or use LangChain's TavilySearchResults)
27    return f"Simulated search result for: {query}"