From 9841c38011d76f00cb84b5da432c2333f983cd50 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 19 Apr 2026 22:42:17 +0000 Subject: [PATCH] fix(navi): format tool output as human-readable directions --- lib/aurora_nav_tool.py | 55 +++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/lib/aurora_nav_tool.py b/lib/aurora_nav_tool.py index ef4b604..2b7285d 100644 --- a/lib/aurora_nav_tool.py +++ b/lib/aurora_nav_tool.py @@ -1,7 +1,7 @@ """ title: Navigation author: Echo6 -version: 1.0.0 +version: 1.1.0 description: Turn-by-turn directions and geocoding via Photon + Valhalla on recon-vm. Supports driving, walking, cycling, and truck routing with worldwide coverage (281M places). """ @@ -57,28 +57,24 @@ class Tools: mode: str = "auto", ) -> str: """ - Get turn-by-turn driving, walking, or cycling directions between two locations. - Use this when someone asks how to get somewhere, asks for directions, or wants to know distance/time between places. + Get turn-by-turn directions between two locations. When this tool returns results, present the directions exactly as returned — do not summarize or rephrase. Include all steps. :param origin: Starting location — address, place name, or lat,lon coordinates :param destination: Destination — address, place name, or lat,lon coordinates :param mode: Travel mode: auto, pedestrian, bicycle, or truck (default: auto) - :return: Directions with distance, time, and turn-by-turn maneuvers + :return: Formatted turn-by-turn directions """ if mode not in ("auto", "pedestrian", "bicycle", "truck"): mode = "auto" - # Geocode origin orig_lat, orig_lon, orig_name = self._geocode(origin) if orig_lat is None: - return json.dumps({"error": f"Could not find location: {origin}"}) + return f"Could not find location: {origin}" - # Geocode destination dest_lat, dest_lon, dest_name = self._geocode(destination) if dest_lat is None: - return json.dumps({"error": f"Could not find location: {destination}"}) + return f"Could not find location: {destination}" - # Route via Valhalla try: resp = requests.post( f"{self.valves.valhalla_url}/route", @@ -93,30 +89,29 @@ class Tools: timeout=30, ) except requests.RequestException: - return json.dumps({"error": "Navigation service unavailable"}) + return "Navigation service unavailable" if resp.status_code != 200: - return json.dumps({"error": "No route found between locations"}) + return "No route found between locations" trip = resp.json()["trip"] summary = trip["summary"] - maneuvers = [] - for m in trip["legs"][0]["maneuvers"]: - streets = m.get("street_names", []) - entry = { - "instruction": m["instruction"], - "distance_miles": round(m.get("length", 0), 2), - } - if streets: - entry["street"] = streets[0] - maneuvers.append(entry) + legs = trip["legs"][0]["maneuvers"] - result = { - "origin": orig_name, - "destination": dest_name, - "distance_miles": round(summary["length"], 1), - "time_minutes": round(summary["time"] / 60, 1), - "mode": mode, - "maneuvers": maneuvers, - } - return json.dumps(result) + miles = round(summary["length"], 1) + minutes = round(summary["time"] / 60, 1) + + lines = [ + f"Directions from {orig_name} to {dest_name} ({mode}):", + f"Distance: {miles} miles | Time: {minutes} minutes", + "", + ] + for i, m in enumerate(legs, 1): + inst = m["instruction"] + dist = m.get("length", 0) + if dist > 0: + lines.append(f"{i}. {inst} — {round(dist, 1)} mi") + else: + lines.append(f"{i}. {inst}") + + return "\n".join(lines)