Functional Description

A customizable API AI Agent that supports configuring HTTP method types as GET and POST APIs. Supports multiple dialogue rounds, streaming and non-streaming modes.
The agent flow chart is as follows:
ai-agent

Runtime Properties

Plugin execution phase: Default Phase Plugin execution priority: 200

Configuration Fields

Basic Configuration

NameData TypeRequirementDefault ValueDescription
llmobjectRequired-Configuration information for AI service provider
apisobjectRequired-Configuration information for external API service provider
promptTemplateobjectOptional-Configuration information for Agent ReAct template

The configuration fields for llm are as follows:

NameData TypeRequirementDefault ValueDescription
apiKeystringRequired-Token for authentication when accessing large model services.
serviceNamestringRequired-Name of the large model service
servicePortintRequired-Port of the large model service
domainstringRequired-Domain for accessing the large model service
pathstringRequired-Path for accessing the large model service
modelstringRequired-Model name for accessing the large model service
maxIterationsintRequired15Maximum steps before ending the execution loop
maxExecutionTimeintRequired50000Timeout for each request to the large model, in milliseconds
maxTokensintRequired1000Token limit for each request to the large model

The configuration fields for apis are as follows:

NameData TypeRequirementDefault ValueDescription
apiProviderobjectRequired-Information about the external API service
apistringRequired-OpenAPI documentation of the tool

The configuration fields for apiProvider are as follows:

NameData TypeRequirementDefault ValueDescription
apiKeyobjectOptional-Token for authentication when accessing external API services.
maxExecutionTimeintOptional50000Timeout for each request to the API, in milliseconds
serviceNamestringRequired-Name of the external API service
servicePortintRequired-Port of the external API service
domainstringRequired-Domain for accessing the external API

The configuration fields for apiKey are as follows:

NameData TypeRequirementDefault ValueDescription
instringOptionalnoneWhether the authentication token for accessing the external API service is in the header or in the query; If the API does not have a token, fill in none.
namestringOptional-The name of the token for authentication when accessing the external API service.
valuestringOptional-The value of the token for authentication when accessing the external API service.

The configuration fields for promptTemplate are as follows:

NameData TypeRequirementDefault ValueDescription
languagestringOptionalENLanguage type of the Agent ReAct template, including CH and EN.
chTemplateobjectOptional-Agent ReAct Chinese template
enTemplateobjectOptional-Agent ReAct English template

The configuration fields for chTemplate and enTemplate are as follows:

NameData TypeRequirementDefault ValueDescription
questionstringOptional-The question part of the Agent ReAct template
thought1stringOptional-The thought1 part of the Agent ReAct template
observationstringOptional-The observation part of the Agent ReAct template
thought2stringOptional-The thought2 part of the Agent ReAct template

Usage Example

Configuration Information

  1. llm:
  2. apiKey: xxxxxxxxxxxxxxxxxx
  3. domain: dashscope.aliyuncs.com
  4. serviceName: dashscope.dns
  5. servicePort: 443
  6. path: /compatible-mode/v1/chat/completions
  7. model: qwen-max-0403
  8. maxIterations: 2
  9. promptTemplate:
  10. language: CH
  11. apis:
  12. - apiProvider:
  13. domain: restapi.amap.com
  14. serviceName: geo.dns
  15. servicePort: 80
  16. apiKey:
  17. in: query
  18. name: key
  19. value: xxxxxxxxxxxxxxx
  20. api: |
  21. openapi: 3.1.0
  22. info:
  23. title: Amap
  24. description: Get related information of POI
  25. version: v1.0.0
  26. servers:
  27. paths:
  28. /v5/place/text:
  29. get:
  30. description: Get latitude and longitude coordinates based on POI name
  31. operationId: get_location_coordinate
  32. parameters:
  33. - name: keywords
  34. in: query
  35. description: POI name, must be in Chinese
  36. required: true
  37. schema:
  38. type: string
  39. - name: region
  40. in: query
  41. description: The name of the region where the POI is located, must be in Chinese
  42. required: true
  43. schema:
  44. type: string
  45. deprecated: false
  46. /v5/place/around:
  47. get:
  48. description: Search for POI near the given coordinates
  49. operationId: search_nearby_pois
  50. parameters:
  51. - name: keywords
  52. in: query
  53. description: Keywords for the target POI
  54. required: true
  55. schema:
  56. type: string
  57. - name: location
  58. in: query
  59. description: Latitude and longitude of the center point, separated by a comma
  60. required: true
  61. schema:
  62. type: string
  63. deprecated: false
  64. components:
  65. schemas: {}
  66. - apiProvider:
  67. domain: api.seniverse.com
  68. serviceName: seniverse.dns
  69. servicePort: 80
  70. apiKey:
  71. in: query
  72. name: key
  73. value: xxxxxxxxxxxxxxx
  74. api: |
  75. openapi: 3.1.0
  76. info:
  77. title: XZWeather
  78. description: Get weather related information
  79. version: v1.0.0
  80. servers:
  81. paths:
  82. /v3/weather/now.json:
  83. get:
  84. description: Get weather conditions for a specified city
  85. operationId: get_weather_now
  86. parameters:
  87. - name: location
  88. in: query
  89. description: The city to query
  90. required: true
  91. schema:
  92. type: string
  93. - name: language
  94. in: query
  95. description: Language used for the weather query results
  96. required: true
  97. schema:
  98. type: string
  99. default: zh-Hans
  100. enum:
  101. - zh-Hans
  102. - en
  103. - ja
  104. - name: unit
  105. in: query
  106. description: Units of temperature, available in Celsius and Fahrenheit
  107. required: true
  108. schema:
  109. type: string
  110. default: c
  111. enum:
  112. - c
  113. - f
  114. deprecated: false
  115. components:
  116. schemas: {}
  117. - apiProvider:
  118. apiKey:
  119. in: header
  120. name: DeepL-Auth-Key
  121. value: 73xxxxxxxxxxxxxxx:fx
  122. domain: api-free.deepl.com
  123. serviceName: deepl.dns
  124. servicePort: 443
  125. api: |
  126. openapi: 3.1.0
  127. info:
  128. title: DeepL API Documentation
  129. description: The DeepL API provides programmatic access to DeepLs machine translation technology.
  130. version: v1.0.0
  131. servers:
  132. paths:
  133. /translate:
  134. post:
  135. summary: Request Translation
  136. operationId: translateText
  137. requestBody:
  138. required: true
  139. content:
  140. application/json:
  141. schema:
  142. type: object
  143. required:
  144. - text
  145. - target_lang
  146. properties:
  147. text:
  148. description: |
  149. Text to be translated. Only UTF-8-encoded plain text is supported.
  150. The parameter may be specified up to 50 times in a single request.
  151. Translations are returned in the same order as they are requested.
  152. type: array
  153. maxItems: 50
  154. items:
  155. type: string
  156. example: Hello, World!
  157. target_lang:
  158. description: The language into which the text should be translated.
  159. type: string
  160. enum:
  161. - BG
  162. - CS
  163. - DA
  164. - DE
  165. - EL
  166. - EN-GB
  167. - EN-US
  168. - ES
  169. - ET
  170. - FI
  171. - FR
  172. - HU
  173. - ID
  174. - IT
  175. - JA
  176. - KO
  177. - LT
  178. - LV
  179. - NB
  180. - NL
  181. - PL
  182. - PT-BR
  183. - PT-PT
  184. - RO
  185. - RU
  186. - SK
  187. - SL
  188. - SV
  189. - TR
  190. - UK
  191. - ZH
  192. - ZH-HANS
  193. example: DE
  194. components:
  195. schemas: {}

This example configures three services demonstrating both GET and POST types of tools. The GET type tools include Amap and XZWeather, while the POST type tool is the DeepL translation. All three services need to be properly configured in the Higress service with DNS domain names and should be healthy.
Amap provides two tools, one for obtaining the coordinates of a specified location and the other for searching for points of interest near the coordinates. Document: https://lbs.amap.com/api/webservice/guide/api-advanced/newpoisearch
XZWeather provides one tool to get real-time weather conditions for a specified city, supporting results in Chinese, English, and Japanese, as well as representations in Celsius and Fahrenheit. Document: https://seniverse.yuque.com/hyper_data/api_v3/nyiu3t
DeepL provides one tool for translating given sentences, supporting multiple languages. Document: https://developers.deepl.com/docs/v/zh/api-reference/translate?fallback=true

Below are test cases. For stability, it is recommended to maintain a stable version of the large model. The example used here is qwen-max-0403:
Request Example

  1. curl http://<replace with gateway public IP>/api/openai/v1/chat/completions’ \
  2. -H Accept: application/json, text/event-stream \
  3. -H Content-Type: application/json \
  4. data-raw ‘{“model”:”qwen”,”frequency_penalty”:0,”max_tokens”:800,”stream”:false,”messages”:[{“role”:”user”,”content”:”I want to have coffee near the Xinshi Building in Jinan, please recommend a few.”}],”presence_penalty”:0,”temperature”:0,”top_p”:0}’

Response Example

  1. {“id”:”139487e7-96a0-9b13-91b4-290fb79ac992”,”choices”:[{“index”:0,”message”:{“role”:”assistant”,”content”:” Near the Xinshi Building in Jinan, you can choose from the following coffee shops:\n1. luckin coffee 瑞幸咖啡(鑫盛大厦店), located in the lobby of Xinshi Building, No. 1299 Xinluo Avenue;\n2. 三庆齐盛广场挪瓦咖啡(三庆·齐盛广场店), located 60 meters southwest of the intersection of Xinluo Avenue and Yingxiu Road;\n3. luckin coffee 瑞幸咖啡(三庆·齐盛广场店), located at No. 1267 Yingxiu Road;\n4. 库迪咖啡(齐鲁软件园店), located in the commercial space of Building 4, Sanqing Qisheng Plaza, Xinluo Avenue;\n5. 库迪咖啡(美莲广场店), located at L117, Meilian Plaza, No. 1166 Xinluo Avenue, High-tech Zone; and a few other options. I hope these suggestions help!”},”finish_reason”:”stop”}],”created”:1723172296,”model”:”qwen-max-0403”,”object”:”chat.completion”,”usage”:{“prompt_tokens”:886,”completion_tokens”:50,”total_tokens”:936}}

Request Example

  1. curl http://<replace with gateway public IP>/api/openai/v1/chat/completions’ \
  2. -H Accept: application/json, text/event-stream \
  3. -H Content-Type: application/json \
  4. data-raw ‘{“model”:”qwen”,”frequency_penalty”:0,”max_tokens”:800,”stream”:false,”messages”:[{“role”:”user”,”content”:”What is the current weather in Jinan?”}],”presence_penalty”:0,”temperature”:0,”top_p”:0}’

Response Example

  1. {“id”:”ebd6ea91-8e38-9e14-9a5b-90178d2edea4”,”choices”:[{“index”:0,”message”:{“role”:”assistant”,”content”:” The current weather condition in Jinan is overcast, with a temperature of 31°C. This information was last updated on August 9, 2024, at 15:12 (Beijing time).”},”finish_reason”:”stop”}],”created”:1723187991,”model”:”qwen-max-0403”,”object”:”chat.completion”,”usage”:{“prompt_tokens”:890,”completion_tokens”:56,”total_tokens”:946}}

Request Example

  1. curl http://<replace with gateway public IP>/api/openai/v1/chat/completions’ \
  2. -H Accept: application/json, text/event-stream \
  3. -H Content-Type: application/json \
  4. data-raw ‘{“model”:”qwen”,”frequency_penalty”:0,”max_tokens”:800,”stream”:false,”messages”:[{“role”:”user”,”content”:”What is the current weather in Jinan?”},{“role”:”assistant”,”content”:” The current weather condition in Jinan is overcast, with a temperature of 31°C. This information was last updated on August 9, 2024, at 15:12 (Beijing time).”},{“role”:”user”,”content”:”BeiJing?”}],”presence_penalty”:0,”temperature”:0,”top_p”:0}’

Response Example

  1. {“id”:”ebd6ea91-8e38-9e14-9a5b-90178d2edea4”,”choices”:[{“index”:0,”message”:{“role”:”assistant”,”content”:” The current weather condition in Beijing is overcast, with a temperature of 19°C. This information was last updated on Sep 12, 2024, at 22:17 (Beijing time).”},”finish_reason”:”stop”}],”created”:1723187991,”model”:”qwen-max-0403”,”object”:”chat.completion”,”usage”:{“prompt_tokens”:999,”completion_tokens”:76,”total_tokens”:1075}}

Request Example

  1. curl http://<replace with gateway public IP>/api/openai/v1/chat/completions’ \
  2. -H Accept: application/json, text/event-stream \
  3. -H Content-Type: application/json \
  4. data-raw ‘{“model”:”qwen”,”frequency_penalty”:0,”max_tokens”:800,”stream”:false,”messages”:[{“role”:”user”,”content”:”What is the current weather in Jinan? Please indicate in Fahrenheit and respond in Japanese.”}],”presence_penalty”:0,”temperature”:0,”top_p”:0}’

Response Example

  1. {“id”:”ebd6ea91-8e38-9e14-9a5b-90178d2edea4”,”choices”:[{“index”:0,”message”:{“role”:”assistant”,”content”:” 現在の济南の天気は曇りで、気温は88°Fです。この情報は2024891512分(東京時間)に更新されました。”},”finish_reason”:”stop”}],”created”:1723187991,”model”:”qwen-max-0403”,”object”:”chat.completion”,”usage”:{“prompt_tokens”:890,”completion_tokens”:56,”total_tokens”:946}}

Request Example

  1. curl http://<replace with gateway public IP>/api/openai/v1/chat/completions’ \
  2. -H Accept: application/json, text/event-stream \
  3. -H Content-Type: application/json \
  4. data-raw ‘{“model”:”qwen”,”frequency_penalty”:0,”max_tokens”:800,”stream”:false,”messages”:[{“role”:”user”,”content”:”Help me translate the following sentence into German: \”Hail Hydra!\””}],”presence_penalty”:0,”temperature”:0,”top_p”:0}’

Response Example

  1. {“id”:”65dcf12c-61ff-9e68-bffa-44fc9e6070d5”,”choices”:[{“index”:0,”message”:{“role”:”assistant”,”content”:” The German translation of \”Hail Hydra!\” is \”Hoch lebe Hydra!\”.”},”finish_reason”:”stop”}],”created”:1724043865,”model”:”qwen-max-0403”,”object”:”chat.completion”,”usage”:{“prompt_tokens”:908,”completion_tokens”:52,”total_tokens”:960}}