
在今天的文章中,我们将使用 Workflow 来展示如何使用 HTTP 来查询天气,以及发送消息到 Slack。
发送消息到 Slack
首先,我们参考之前的文章 "Elasticsearch:如何创建知识库并使用 AI Assistant 来配置 slack 连接器" 来创建一个 Webhook 链接。我们然后参考如下的步骤来创建一个叫做 slack 的连接器:





这样我们就创建了一个叫做 Slack 的连接器。
我们接下来使用如下的方法来创建一个 Workflow:


name: Send Message to Slack
enabled: true
triggers:
- type: manual
inputs:
- name: message
default: "Hello from workflow!"
description: Message to send to Slack
type: string
steps:
- name: share_message
type: slack
connector-id: slack
with:
message: |
{{ inputs.message }}

我们可以进行测试:


我们检查 Slack:

我们当然也可以发送大微信或者 DingDing。这里就不再累述了。
创建 send slack msg 工具
我们按照如下的步骤来创建一个叫做 send_msg_slack 的工具:




这样我们的工具就创建好了。
创建查询天气的 workflow
我们如法炮制,创建如下的一个叫做 Weather Lookup 的 workflow:
# =============================================================================
# Workflow: 🌤 Weather Lookup by Latitude and Longitude
# =============================================================================
name: 🌤 Weather Lookup
enabled: true
# ---------------------------------------------------------------------------
# TRIGGERS
# ---------------------------------------------------------------------------
triggers:
- type: manual
# ---------------------------------------------------------------------------
# INPUTS
# ---------------------------------------------------------------------------
inputs:
- name: latitude
default: 52.52
description: Latitude of the location
type: number
- name: longitude
default: 13.41
description: Longitude of the location
type: number
- name: hourly_params
default: temperature_2m
description: Weather parameters to request (e.g., temperature_2m, windspeed_10m)
type: string
- name: timezone
default: auto
description: Timezone for the returned times
type: string
# ---------------------------------------------------------------------------
# STEPS
# ---------------------------------------------------------------------------
steps:
# Step 1: Call Open-Meteo API
- name: get_weather
type: http
with:
url: "https://api.open-meteo.com/v1/forecast?latitude={{ inputs.latitude }}&longitude={{ inputs.longitude }}&hourly={{ inputs.hourly_params }}&timezone={{ inputs.timezone }}"
method: GET
headers:
Accept: application/json

我们可以做如下的测试:


很显然,我们的 workflow 已经创建成功。
创建 get_weather 工具
我们如法炮制,创建如下的一个叫做 get_weather 的工具:

测试
我们按照之前的文章 "Elastic AI agent builder 介绍(一)" 创建 "Find parents according to profession" agent。在这个 agent 里,我们添加上面已经创建好的两个工具。

我们然后做如下的查询:
Please find the programmer's weather and send it to slack. thanks


我们可以看到 3 个工具被调用,并分别被执行。
我们也可以尝试是用中文来进行搜索:

我们可以查看一下 Slack 上的信息:
