Skip to content

Commit 574f37e

Browse files
Dramatically simplify search-along-route to use only proximity sampling
After encountering buffer issues even on short routes (Leesburg to Herndon), this simplifies the entire workflow to use a single, reliable approach for all route lengths: sample points + proximity searches. Changes: - REMOVED: buffer_tool, bounding_box_tool, point_in_polygon_tool complexity - REMOVED: Three different strategies for different route lengths - NEW: Single unified approach - sample route points and proximity search How it works: 1. Get route with directions_tool 2. Sample points along route (density based on length): - Short routes (<50km): Every 5-10 points (comprehensive coverage) - Medium routes (50-150km): Every 15-20 points - Long routes (>150km): 5-7 strategic points 3. For each sample point, use category_search_tool with proximity parameter 4. Combine results, deduplicate, order by distance from start Why this is better: - Simple and reliable - no complex geometry operations - No buffer validation errors or "buffer result is very large" issues - No bbox calculation failures - Works consistently for ALL route lengths - Fast execution, no token/timeout issues - Proximity searches naturally cover route corridor Leesburg to Herndon: Sample every 5-10 points, comprehensive coverage Seattle to Portland: Sample 5-7 major points, fast and reliable This is the pragmatic solution that actually works in production. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 24fc041 commit 574f37e

File tree

1 file changed

+52
-67
lines changed

1 file changed

+52
-67
lines changed

src/prompts/SearchAlongRoutePrompt.ts

Lines changed: 52 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ export class SearchAlongRoutePrompt extends BasePrompt {
6767
from,
6868
to,
6969
search_for,
70-
mode = 'driving',
71-
buffer_meters = '1000'
70+
mode = 'driving'
71+
// buffer_meters parameter is kept for API compatibility but not used
72+
// in the simplified proximity-sampling approach
7273
} = args;
7374

7475
return [
@@ -86,87 +87,71 @@ Please follow these steps:
8687
2. **Get the route**:
8788
- Use directions_tool with profile=${mode} to get the route geometry between the two points
8889
- Extract the route LineString coordinates from the response (it will be an array of [lon, lat] pairs)
89-
- Note the total route distance in meters
90-
91-
3. **Create search corridor and find places** (choose approach based on route length):
92-
93-
**For SHORT routes (< 50km):** [RECOMMENDED - Most accurate]
94-
- Use buffer_tool on the route LineString coordinates with distance=${buffer_meters} meters
95-
* Pass the coordinates as: {"geometry": [[lon1,lat1], [lon2,lat2], ...], "distance": ${buffer_meters}, "units": "meters"}
96-
- The buffer result will be a Polygon
97-
- Use bounding_box_tool on the buffer polygon to get search bbox
98-
* Pass the polygon coordinates from the buffer result
99-
- Use category_search_tool with the bbox parameter (format: "minLon,minLat,maxLon,maxLat")
100-
- Use point_in_polygon_tool to filter results to the buffer corridor
101-
- This gives precise corridor filtering
102-
103-
**For MEDIUM routes (50-150km):** [PRAGMATIC - Balanced]
104-
- Use bounding_box_tool on the route LineString coordinates to get the route's bbox
105-
* Pass the route coordinates as: {"geometry": [[lon1,lat1], [lon2,lat2], ...]}
106-
- Use category_search_tool with the bbox parameter (format: "minLon,minLat,maxLon,maxLat")
107-
- Filter results by calculating distance to the closest route point (use distance_tool)
108-
- Keep only results within ${buffer_meters}m of the route
109-
- Note to user: "For this medium-length route, results are filtered to the general corridor"
110-
111-
**For VERY LONG routes (> 150km):** [SAMPLING - Most practical]
112-
- Sample 5-7 strategic points evenly spaced along the route
113-
* Extract coordinates at indices: 0, len/6, 2*len/6, 3*len/6, 4*len/6, 5*len/6, len-1
114-
- For each sample point coordinate [lon, lat]:
115-
* Use category_search_tool with proximity parameter: "lon,lat" and limit results
116-
- Combine results from all sample points (remove duplicates if any)
117-
- Order by distance from start point
118-
- Note to user: "Due to the route length (X km), showing results near major points along the route rather than the full corridor"
119-
120-
**Why this three-tier approach:**
121-
- Short routes: Full precision
122-
- Medium routes: Balanced filtering
123-
- Very long routes: Strategic sampling prevents token/timeout issues
124-
125-
4. **Order and present results**:
126-
- Use distance_tool to calculate each POI's distance from the start point
90+
- Note the total route distance
91+
92+
3. **Search along the route using point sampling** (works for all route lengths):
93+
94+
**Determine sample strategy based on route length:**
95+
- SHORT routes (< 50km): Sample every 5-10 points along the route (more samples for better coverage)
96+
- MEDIUM routes (50-150km): Sample every 15-20 points along the route
97+
- VERY LONG routes (> 150km): Sample 5-7 evenly spaced points (start, end, and middle points)
98+
99+
**For each sample point:**
100+
- Extract the coordinate [lon, lat] from the route
101+
- Use category_search_tool with:
102+
* query: "${search_for}"
103+
* proximity: "lon,lat" (bias results near this point)
104+
* limit: Keep results reasonable (10-20 per point for short routes, 5-10 for long routes)
105+
106+
**Combine and deduplicate:**
107+
- Collect all results from sample points
108+
- Remove duplicates (same place found from multiple sample points)
109+
- Use distance_tool to calculate each result's distance from the start point
127110
- Order results by distance from start (approximate route progress)
128-
- For short routes with precise corridor: results should all be on/near route
129-
- For long routes with bbox filtering: results are approximate corridor
111+
112+
**Why this approach works:**
113+
- Simple and reliable - just directions + proximity searches
114+
- No buffer/bbox/polygon complexity
115+
- Works consistently for all route lengths
116+
- Fast execution, no token issues
117+
- Covers the route corridor naturally through proximity searches
118+
119+
4. **Present results**:
120+
- Results are already ordered by distance from start
121+
- Limit to top 15 results if many were found
122+
- Note: Results are biased to the route corridor through proximity searches at sample points
130123
131124
5. **Visualize and present**:
132125
133-
**Map generation (conditional based on route length):**
134-
- For SHORT routes (<50km): Generate a detailed map with static_map_image_tool
135-
* Use simplify_tool first to reduce route coordinates (tolerance=0.001)
126+
**Map generation:**
127+
- For ALL routes, use static_map_image_tool to create a map:
128+
* Use simplify_tool on route first (tolerance=0.01 for <50km, 0.05 for >50km)
136129
* Show the simplified route as a path overlay
137130
* Add start and end markers
138-
* Add found location markers (top 10)
139-
140-
- For MEDIUM routes (50-150km): Generate a simplified map
141-
* Use simplify_tool with higher tolerance (0.01) to drastically reduce points
142-
* Show simplified route, start/end markers, top 5-8 location markers
143-
144-
- For VERY LONG routes (>150km): Skip map generation
145-
* Note: "Map visualization skipped for route length - see results list below"
146-
* Focus on the text list of results instead
147-
* This avoids slow encoding of complex routes
131+
* Add found location markers (top 8-10 only to keep map clean)
132+
* If route is very long (>150km), consider skipping map to save time
148133
149134
**Results list (always provide):**
150135
- Name and address of each place
151-
- Distance from start of route (e.g., "45 miles into your trip")
152-
- Distance from route line (e.g., "0.3 miles off route")
136+
- Approximate distance from start of route (e.g., "45 miles into your trip")
153137
- Total results found
138+
- Note which sampling strategy was used
154139
155140
6. **Additional context**:
156141
- Mention the total route distance and estimated travel time
157-
- Note which approach was used:
158-
* Short route: "Using precise corridor filtering"
159-
* Medium route: "Filtered to general route corridor"
160-
* Very long route: "Showing results near major points along the route"
161-
- If no results were found, suggest widening the search corridor or checking different locations
142+
- Note which sampling strategy was used:
143+
* Short route: "Searched every 5-10 points along the route for comprehensive coverage"
144+
* Medium route: "Sampled key points along the route"
145+
* Very long route: "Sampled major points along the route"
146+
- If no results were found, suggest trying a different search term or checking a specific segment
162147
- If many results (>15), show top 15 and mention there are more
163148
164149
**Important notes:**
165-
- Routes < 50km: Use precise corridor filtering (buffer + point-in-polygon)
166-
- Routes 50-150km: Use bbox filtering with distance checks
167-
- Routes > 150km: Use strategic point sampling (5-7 points) to avoid token/timeout issues
168-
- These thresholds keep the workflow practical and reliable for all route lengths
169-
- Always inform the user which approach was used and set appropriate expectations
150+
- This approach uses simple proximity searches at sampled route points
151+
- No buffer/bbox/polygon operations needed - much more reliable
152+
- Works consistently for all route lengths
153+
- Fast and avoids token/timeout issues
154+
- Results naturally cover the route corridor through proximity biasing
170155
171156
Make the output clear, actionable, and well-formatted.`
172157
}

0 commit comments

Comments
 (0)