Elasticsearch:如何在 workflow 里调用一个 agent

在 AI Agent Builder 里,我们可以创建一个 workflow 的工具从而达到调用 workflow 的目的。我们是不是也可以在 workflow 里调用 AI Agent Builder 里所创建的 Agent 呢?答案是肯定的。下面我们来用一个简单的例子来进行展示。

创建一个 agent

我们创建的一个 agent 的名字叫做 generate_audio_product_json。它是用来解析我们的输入,并提区我们所需要的信息。它的创建非常融, 我们甚至不需要使用任何的工具。

Custom Instructions

复制代码
  Extract audio product information from this description.
        Return raw JSON only. Do NOT use markdown, backticks, or code blocks.
         Extract audio product information from this description.
        Return raw JSON only. Do NOT use markdown, backticks, or code blocks.

        Fields:
        - category (string, one of: Headphones/Earbuds/Speakers/Microphones/Accessories)
        - features (array of strings from: wireless, noise_cancellation, long_battery, waterproof, voice_assistant, fast_charging, portable, surround_sound)
        - use_case (string, one of: Travel/Office/Home/Fitness/Gaming/Studio)

我使用一个简单的例子来进行展示:

复制代码
Premium wireless Bluetooth headphones with active noise cancellation, 30-hour battery life, and premium leather ear cushions. Perfect for travel and office use.

创建一个 workflow 并调用 agent

我们在 workflow 里创建一个如下的 workflow:

复制代码
version: "1"
name: invoke_audio_product_agent
description: Extract structured product data using an AI agent
enabled: true

triggers:
  - type: manual

inputs:
  - name: product_info
    type: string
    required: true
    description: product descriptions

steps:
  # Step 1: Log input (optional but recommended)
  - name: log_input
    type: console
    with:
      message: "Incoming product info: {{ inputs.product_info }}"

  # Step 2: Invoke your agent
  - name: generate_product_json
    type: ai.agent
    with:
      agent_id: "generate_audio_product_json"
      message: |
        Extract structured product data from the following input.

        Input:
        {{ inputs.product_info }}

        Return ONLY valid JSON.

  # Step 3: Print the result
  - name: print_result
    type: console
    with:
      message: "{{ steps.generate_product_json.output }}"
复制代码
Premium wireless Bluetooth headphones with active noise cancellation, 30-hour battery life, and premium leather ear cushions. Perfect for travel and office use.

格式化输出

我们也可以在 agent 调用的时候加入数据输出的格式:

复制代码
version: "1"
name: invoke_agent_example2
description: Shows a way to invoke an agent and return JSON safely
enabled: true

triggers:
  - type: manual

inputs:
  - name: query
    type: string
    default: What is the cheapest air ticket price from China to US and what are the cities?
    required: true
    description: Query a flight index

steps:
  - name: query_flight
    type: ai.agent
    with:
      agent_id: "find_the_cheapest_ticket_from_cn_us"
      message: |
        Query the flight info for this request:
        {{ inputs.query }}

        Return the result **as JSON only**, using this structure.
        Use real values if known, otherwise use null:

        {
          "price": <number or null>,
          "departure_city": "<string or null>",
          "arrival_city": "<string or null>"
        }

  - name: log_result
    type: console
    with:
      message: "Flight info JSON: {{ steps.query_flight.output }}"

如上所示,我们要求的格式是 JSON 输出:

复制代码
What is the cheapest air ticket price from China to US and what are the cities?

祝大家学习愉快!

相关推荐
南棱笑笑生1 小时前
20260420给万象奥科的开发板HD-RK3576-PI适配瑞芯微原厂的Buildroot时调通AP6256并实测网速109Mbits/sec
大数据·elasticsearch·搜索引擎·rockchip
大江东去浪淘尽千古风流人物1 小时前
【cuVSLAM】GPU 加速、多相机、实时视觉/视觉惯性 SLAM设计优势
c++·人工智能·数码相机·ubuntu·计算机视觉·augmented reality
Elastic 中国社区官方博客6 小时前
Elasticsearch:使用 Agent Builder 的 A2A 实现 - 开发者的圣诞颂歌
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
chools6 小时前
【AI超级智能体】快速搞懂工具调用Tool Calling 和 MCP协议
java·人工智能·学习·ai
郝学胜-神的一滴7 小时前
深度学习必学:PyTorch 神经网络参数初始化全攻略(原理 + 代码 + 选择指南)
人工智能·pytorch·python·深度学习·神经网络·机器学习
leobertlan7 小时前
好玩系列:用20元实现快乐保存器
android·人工智能·算法
笨笨饿7 小时前
#58_万能函数的构造方法:ReLU函数
数据结构·人工智能·stm32·单片机·硬件工程·学习方法
jr-create(•̀⌄•́)7 小时前
从零开始:手动实现神经网络识别手写数字(完整代码讲解)
人工智能·深度学习·神经网络
历程里程碑7 小时前
2. Git版本回退全攻略:轻松掌握代码时光机
大数据·c++·git·elasticsearch·搜索引擎·github·全文检索
面向Google编程7 小时前
从零学习Kafka:ZooKeeper vs KRaft
大数据·kafka