import httpx from tools.registry import tool_registry @tool_registry.register( name="query_weather", description="查询指定城市的实时天气信息", parameters={ "type": "object", "properties": { "city": {"type": "string", "description": "城市名称,如:北京、上海"}, }, "required": ["city"], }, ) def query_weather(city: str) -> str: try: resp = httpx.get(f"https://wttr.in/{city}?format=3", timeout=3) resp.raise_for_status() return resp.text.strip() except Exception as exc: return f"天气查询失败:{exc}"