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 被调用。

相关推荐
Shockang3 小时前
AI 智能体安全沙盒实战
人工智能
yuhulkjv3354 小时前
Claude表格复制到word不再崩溃,AI导出鸭批量导出+格式无损一键搞定
人工智能·ai·c#·word·ai导出鸭
guwentian4 小时前
Git Worktree 实战:用并行多 Agent 把开发提速 N 倍
大数据·git·elasticsearch·wroktree
大明者省5 小时前
WSL2 Ubuntu22.04 GPU训练环境配置指南
人工智能·算法·计算机视觉
抱抱宝5 小时前
Agent-study项目教程(03):手写 Mini-ReAct Agent(不依赖框架)
javascript·人工智能·gpt·react.js·prompt·agent
抱抱宝5 小时前
大模型应用开发教程08 | 构建完整 RAG 应用(Chroma/FAISS 实战)
人工智能·gpt·prompt·agent
美团技术团队6 小时前
KDD‘26 美团学术论文精选及KDD Cup‘26 DataAgents赛道冠军思路解读
人工智能
AKAMAI6 小时前
当AI模型超出存储增长时
人工智能·云计算
科技绘图6 小时前
快鲸GEO vs 传统AI搜索优化:全链路自动化与高效内容生产在转化闭环上的对比
数据库·人工智能·自动化
DS随心转小程序6 小时前
ChatGPT 文字怎么转为 word?解析各类转换方案,AI 导出鸭成为高效文档转换新选择
人工智能·chatgpt·word·豆包·deepseek·ai导出鸭