哈利波特问答 Agent Builder + Workflow 教程

作者:来自 Elastic 朱杰

第一部分:熟悉 阿里云 控制台,获得需要的信息

1)熟悉阿里云控制台,试用页面创建好集群后可以进入到下面的控制台管理试用集群,管理推理服务,这个教程需要用 embedding 模型、 千问 大语言模型

2)点击左侧 AI搜索 开放平台 进入下方的页面,点击左侧 API Keys 开通AI搜索模型服务

3)上面界面点击 API Key 开通服务后,会生成模型调用访问域名,注意左侧下拉选择华北2 北京,和 API Key

4)访问 AI搜索开放平台 文档,熟悉可以调用哪些 LLM 和 Embedding 模型

5)打开 AI搜索开放平台 文档,熟悉红框的链接,后续在Kibana中配置模型连接器的时候需要参考页面中的信息。

注意:上面 URL 中 host 指的是上方第3步页面中的访问域名 例如:

Embedding OpenAI 兼容访问接口

bash 复制代码
`http://default-xxx.platform-cn-beijing.opensearch.aliyuncs.com/compatible-mode/v1/embeddings`AI代码解释

Embedding的 模型 ID 点击左侧 文本向量 页面。注意不要选择 turbo 模型,因为无法完成复杂的推理任务

第二部分:在Kibana中配置模型调用连接器

1)创建 Alibaba Embedding 连接器

点击 Kibana 菜单左侧 Agent ,第一次使用需要配置模型连接器,点击 Connect LLM 跳转到连接器配置页面

下面的 Model ID 和 URL 参考 第一部分,第 5 步

API Key 参考 第一部分 第 3 步 点击 Additional settings, 编辑 Inference ID,会在 Elasticsearch中创建一个推理接口,在往 ES 中写入文档时候可以配置自动调用这个接口调用外部 Embedding 服务,最后点击 保存并测试

2)创建 Alibaba Qwen 连接器

选择 OpenAI 连接器,注意:不是上一步的 AI Connector,OpenAI 连接器有更好的兼容性适配 OpenAI 兼容接口

下面的 Model ID 和 URL 参考 第一部分,第 5 步

测试连接器是不是成功

第三部分:上传 Harry Potter PDF,自动调用 Alibaba Embedding连接器转化为向量并写入索引

左侧选择 集成, 右边查找输入框 输入 file,找到 上传文件

Index name 输入 harrypotter 选择上传文件 harrypotter_sorcerers_stone_chapter_5.pdf

文件从这里下载 文档(或者是你想要的 pdf 文件)

上传完PDF后,点击 Advanced options,添加 semantic text field,copy to field 输入 content_vector Inference endpoint 选择第二部分创建的 alibaba Embedding 接口,最后点击 Add 按钮,然后点击 Import

传输成功后出现下面的界面

第四部分:创建 Agent Builder

1)为 Agent 创建 Tools,我们创建一个查询 harrypotter 内容的 搜索 Tool,可以根据用户输入的内容先进行语义查询,然后获得内容再交给 大模型 进行回答。进入 Agent 页面,右侧 More里面 选择 View all tools

然后点击 New Tool 创建新的工具

Type 选择 Index search

Target pattern:

go 复制代码
`harrypotter`AI代码解释

Tool ID:

go 复制代码
`potter.chapter.5`AI代码解释
go 复制代码
`Description:` AI代码解释
python 复制代码
`Fetches information and data from Harry Potter and the Sorcerer's Stone, Chapter 5 (Diagon Alley) from vector embeddings. Returns relevant passages, quotes, and context based on search queries about the chapter's content, characters, events, and themes.`AI代码解释

最后点击 Save

2)创建 Agent

然后点击右上角 + New Agent

Agent ID:

go 复制代码
`potter-answers`AI代码解释

Custom Instructions:

csharp 复制代码
``

1.  You are an expert on Harry Potter Chapter 5 (Diagon Alley). Help users explore the chapter by retrieving relevant passages from vectors. Be accurate, cite sources, provide context, and maintain an enthusiastic but educational tone. Clarify when information is outside Chapter 5's scope. You will only answer questions based on context provided. Do not use external sources not explicitly provided.

3.  ## Tools

5.  ### `potter.chapter.5`
6.  Use this tool to fetch relevant passages and content from Chapter 5. Always use this tool when answering questions about the chapter.

8.  ### `potter.send.email`
9.  Use this tool when the user asks you to send an email. Accepts a recipient name or email address, a subject, and a body. If a name is provided, the tool resolves the email address automatically.

``AI代码解释![](https://csdnimg.cn/release/blogv2/dist/pc/img/runCode/icon-arrowwhite.png)

Display Name:

go 复制代码
`Potter Answers`AI代码解释

Display Description:

python 复制代码
`Your expert guide to Harry Potter and the Sorcerer's Stone, Chapter 5! I help you explore Diagon Alley, from Ollivander's wand shop to Gringotts Bank. Ask me about any scene, character, or magical detail from this iconic chapter.`AI代码解释

为这个 Agent 配置可以使用的Tools,加上我们之前创建的 potter 搜索 Tool

搜索 pott,然后选择 potter.chapter.5 这个 Tool

最后点击 Save 保存 Agent 配置

3)测试 Agent

进入 Agent 页面,右侧选择刚才创建的 Potter Answer Agent,左侧选择之前创建的 Alibaba qwen 连接器

输入测试问题:

vbnet 复制代码
`What is Quidditch, and which Hogwarts House does Hagrid warn Harry against, linking it to dark wizards?`AI代码解释

第五部分:Workflow 调用 Agent

在 9.3 中开启 workflow 功能,9.3中 workflow还是测试试用阶段,需要在 Kibana - Stack Management - 高级设置 中开启 workflow 功能

然后就可以在左侧主菜单中找到 Workflow

进入页面后点击 创建 workflow,进入workflow 编辑界面,workflow是yaml定义的一个工作流,可以在这个界面中编辑、运行测试这个yaml

yaml 复制代码
`

1.  name: Call Agent workflow
2.  enabled: false
3.  description: This is a new workflow
4.  triggers:
5.    - type: manual

7.  steps:
8.    - name: potter_agent
9.      type: kibana.request
10.      with:
11.        method: "POST"
12.        path: "/api/agent_builder/converse"
13.        headers:
14.          kbn-xsrf: "true"
15.        body:
16.          agent_id: potter-answers
17.          input: "What is Quidditch, and which Hogwarts House does Hagrid warn Harry against, linking it to dark wizards?"
18.      timeout: 10m
19.      on-failure:
20.        retry:
21.          max-attempts: 3
22.    - name: get_conversation
23.      type: kibana.request
24.      with:
25.        method: "GET"
26.        path: "/api/agent_builder/conversations/{{steps.potter_agent.output.conversation_id}}"
27.        headers:
28.          kbn-xsrf: "true"
29.    - name: hello_world_step
30.      type: console
31.      with:
32.        message: "{{ steps.get_conversation.output.rounds[0].response.message}}"

`AI代码解释![](https://csdnimg.cn/release/blogv2/dist/pc/img/runCode/icon-arrowwhite.png)

详细 Workflow 文档 Workflows | Elastic Docs

相关推荐
Elasticsearch2 小时前
复制、粘贴,即刻捕获:利用文本指纹识别检测电子邮件和生成式人工智能提示词中的数据泄露
elasticsearch
岳涛18 小时前
考古|ES 0.90 的 _ttl 让文档到期自动删,2.0 起引擎只做引擎,5.0 清掉内置字段
elasticsearch
wuyk55518 小时前
Spider-第14讲-表单提交与CSRF
前端·爬虫·python·elasticsearch·csrf
岳涛20 小时前
时序|ES 9.1 存下写坏的文档,响应码从 400 变成 201,写入端仍当它成功
elasticsearch
Elasticsearch1 天前
九条 ES|QL 查询,揭示你的 Foundry agent 的词元消耗去向
elasticsearch
顧棟2 天前
【ES实战】 索引模板「可追溯、可校验」:一种模板治理的工程化思路
java·数据库·elasticsearch
新*2 天前
520 万数据迁移实战:Elasticsearch 索引重建与"改名"的完整踩坑记录
python·mysql·elasticsearch·数据迁移
阿里云大数据AI技术3 天前
云栖实录|倍思科技 × 阿里云:让VOC洞察从“生成报告”走向“业务可用”
人工智能·elasticsearch·agent
大雪冬至686061258873 天前
【一次 Elasticsearch 高基数聚合慢查询的定位与优化】
elasticsearch