Dify Agent 调用自定义接口

目的

基于:Dify创建自定义工具 – dager

创建的自定义工具,整合在Agent里,让AI 根据需求自动调用

步骤

创建Agent智能体

由于上篇文章是查询用户信息的,所以这个文章以查询你用户信息为主题。

首先写入提示词

You are a user administrator who can query various user-related information using this tool based on the requirements. Although you call a tool intelligently each time, you can execute multiple iterations to call different tools to meet the user's needs.
You can break down the task according to the following steps:
1.Query the ID based on the username.
2.Retrieve the user details or teacher information based on the ID.
3.Further query the ID or other information based on the teacher's name."

添加上个文章开发好的工具

选择模型

  • 先使用4o-mini进行测试看能否满足需求。

测试

四个接口的返回信息是内置的:

测试迭代2次,查询一次接口

  • 根据用户名查询用户的ID
  • 流程
    • 大模型判断是否要调用接口,返回接口信息和参数。(大模型参与)
    • 调用相关接口 返回数据给大模型
    • 大模型获取返回的数据根域用户问题总结返回。(大模型参与)

测试迭代3次,查询两次接口

  • 根据用户名查询用户的信息-邮箱

测试迭代4次,查询三次接口

  • 小明语文老师的用户ID

测试迭代5次,查询四次接口

  • 查询语文老师的头像

发表评论