Elasticsearch:创建 geocoding workflow,并在 agent 中使用它进行位置搜索

我们知道在很多的应用场景中,我们需要定位服务,比如附近最近的餐馆或者酒店。当我们使用大模型进行 agent 任务执行的时候,我们需要位置服务。确切地说,我们需要根据位置来得到相应的经纬度来对数据进行搜索。而大模型有时不具备这种能力。我们在 AI Agents 的设计中,可以通过 workflow 的方法来创建这种工具。

创建 geocoing workflow

我们按照如下的方式来创建一个叫做 geocoding 的 workflow:

复制代码
version: "1"
name: geocoding
description: "Geocoding for a location"
enabled: true

consts:
  geocoding_api_url: https://maps.googleapis.com/maps/api/geocode/json?key=<Your API key>

inputs:
  - name: location
    type: string
    required: true
    description: "location (e.g., Washington)"

triggers:
  - type: manual


steps:
  - name: get_coordinate
    type: http
    with:
      url: "{{ consts.geocoding_api_url }}address={{ inputs.location }}"
      method: GET 


  - name: print_location
    type: console
    with:
      message: "{{ inputs.location }} coordinate is {\"lat\": {{ steps.get_coordinate.output.data.results[0].geometry.location.lat }}, \"lon\": {{ steps.get_coordinate.output.data.results[0].geometry.location.lng }} }."

在上面,我们需要填入自己的谷歌位置开发者 API key。

创建 get_coordinate_by_location 工具

我们接下来创建一个叫做 get_coordinate_by_location 的工具:

创建 agent

我们仿照之前的文章 "Elastic AI agent builder 介绍(一)" 来创建一个叫做 Find parents 的 agent。 它包含创建一个叫做 people 及 parents 的索引。

位置查询示例

我们进行如下的查询:

复制代码
哪个离湖北广水最近?

我们可以看到相应的 get_coordinate_by_location 被调用。

相关推荐
人间凡尔赛5 小时前
WAIC 2026 落幕,AI Agent 开发已进入 Harness 架构时代
人工智能·架构
-XWB-6 小时前
【LLM】Agent Planning 完全指南:8 种纯 LLM 范式 + 8 种混合规划模式详解(二)
人工智能·经验分享·aigc·学习方法·ai编程
微硬创新6 小时前
耐达讯自动化 CC-Link IE 转 PROFINET网关在污水厂智能化升级实战
人工智能·物联网·网络协议·自动化·信息与通信
Smoothcloud润云6 小时前
国内GPU算力租赁平台横向测评:资源、成本、稳定性三维对比
人工智能·ai·云计算·gpu算力·gpu
点PY6 小时前
一种从CTA图像中去除扫描床的方法及装置
人工智能·计算机视觉
晏宁科技YaningAI6 小时前
VoIP系统的工程实现模型:从信令控制到媒体传输的完整架构解析
网络·人工智能·架构·系统架构·信息与通信
IT_陈寒6 小时前
Vue这个特性差点让我加班到凌晨,谁懂啊
前端·人工智能·后端
阿里云大数据AI技术7 小时前
更快、更稳、更省:揭秘阿里云 Elasticsearch 存算分离与弹性扩缩
elasticsearch
D2aZXN3FhrDa7e2127 小时前
佛山AI智能获客系统适配性:工厂门店如何挑选工具
人工智能·美诚科技有限公司
机器之心7 小时前
WAIC现场,这家公司让一群不同的机器人共用一个大脑
人工智能·openai