我們需要給 Agent 更多資訊才能產生出更明確的活動地點,所以使用 Google API 實作一個列舉地點的工具來給 Agent 選擇。
一般來說在選想去的地方時 Google 地圖的評分數會是一個讓人想去看看的重點,所以在搜尋時要將評分資訊取回。
為了達到這個功能,我們實作了一個名為 get_candidate_places_by_google_map
的函數,參數有地點名稱和活動類型,函數的運作邏輯為:
places.displayName.text
)places.rating
)places.userRatingCount
)這樣就有一個提供地點清單的函數,將這個函數註冊成 Tool 並且加上 Prompt 向 AI 說明如何使用。
我這邊請他要提供一個明確的活動地點,可以使用 get_candidate_places_by_google_map
函數取得地點清單,而該函數的輸入為地區名稱和活動類別:
- Each activity should be assigned to a specific place. You can retrieve candidate locations using the get_candidate_places_by_google_map tool, which takes the location name and activity type as inputs.
執行的結果為:
{
"title": "日月潭兩日遊",
"activities": [
{
"type": "accommodation",
"location": "日月潭大飯店",
"startTimeUtc": "2025-09-10T09:00:00Z",
"duration": 90,
"endTimeUtc": "2025-09-10T10:30:00Z",
"timeZone": "Asia/Taipei",
"transportType": null,
"note": "抵達飯店辦理入住手續並稍作休息",
"childActivities": [],
"latLng": {
"latitude": 23.8661912,
"longitude": 120.90295119999999
},
"placeUri": "https://maps.google.com/?cid=16570223414603160834&g_mp=CiVnb29nbGUubWFwcy5wbGFjZXMudjEuUGxhY2VzLkdldFBsYWNlEAAYBCAA"
},
{
"type": "sightseeing",
"location": "伊達邵碼頭",
"startTimeUtc": "2025-09-10T10:30:00Z",
"duration": 120,
"endTimeUtc": "2025-09-10T12:30:00Z",
"timeZone": "Asia/Taipei",
"transportType": "walk",
"note": "探索伊達邵碼頭周邊,欣賞湖光山色",
"childActivities": [],
"latLng": {
"latitude": 23.84974,
"longitude": 120.92967
},
"placeUri": "https://maps.google.com/?cid=16747491732745082392&g_mp=CiVnb29nbGUubWFwcy5wbGFjZXMudjEuUGxhY2VzLkdldFBsYWNlEAAYBCAA"
},
{
"type": "restaurant",
"location": "日月潭-邵族頭目袁家美食",
"startTimeUtc": "2025-09-10T12:30:00Z",
"duration": 75,
"endTimeUtc": "2025-09-10T13:45:00Z",
"timeZone": "Asia/Taipei",
"transportType": "walk",
"note": "品嚐當地邵族風味餐",
"childActivities": [],
"latLng": {
"latitude": 23.848626000000003,
"longitude": 120.93045319999999
},
"placeUri": "https://maps.google.com/?cid=3408079587938168932&g_mp=CiVnb29nbGUubWFwcy5wbGFjZXMudjEuUGxhY2VzLkdldFBsYWNlEAAYBCAA"
},
...
}
在尚未導入此工具前,AI 所指定的住宿地點僅為「日月潭」這樣的模糊區域,導致查詢經緯度時僅能取得一個廣泛範圍。導入工具後,AI 能夠選出如「日月潭大飯店」這樣具體的地點,使路徑顯示更為精確。
不過,AI 回應時間從原本約 20 秒增加至 30 秒,接下來要考慮是否導入快取機制以加速處理速度。