Zero‑Code AI Agent with Higress: Build, Deploy, and Understand ReAct
This article explains the AI Agent concept, introduces the AI Gateway plugin architecture, walks through zero‑code deployment of an AI Agent using Higress with AMap and Seniverse services, and details the ReAct‑based reasoning and tool‑calling implementation with code examples and workflow diagrams.
What is an AI Agent
The rapid development of large‑model technology has revealed limitations such as insufficient domain knowledge and hallucinations, prompting the industry to propose the AI Agent concept (intelligent agent) that enables large models to think step‑by‑step, observe outcomes, and invoke tools to achieve a given goal.
What is an AI Gateway
An AI Gateway is an AI‑native API Gateway that extends traditional API‑gateway capabilities to meet AI requirements, such as token‑based rate limiting, multi‑model vendor support, A/B testing, and tracing.
Higress, an open‑source AI Gateway from Alibaba Cloud, builds on API Gateway and adds numerous AI‑related Wasm plugins to satisfy all AI‑native needs.
The author developed an AI Agent plugin on Higress, leveraging the gateway’s API management to enable zero‑code construction of an AI Agent that can call external services such as AMap (maps) and Seniverse (weather).
Using the AI Agent Plugin
API key acquisition – Register on the official sites of AMap and Seniverse, obtain free daily API keys, and reference the official documentation links.
Higress service configuration – In Higress route management, add DNS‑type services for the large‑model endpoint, AMap, and Seniverse.
Plugin Parameter Configuration
dashscope:
# 通义千问大模型客户端配置
apiKey: sk-xxxxxxxxxxxxxxxxxxxxxxx
domain: dashscope.aliyuncs.com
serviceName: dashscope
servicePort: 443
promptTemplate:
language: CH
apis:
- apiProvider:
domain: restapi.amap.com
serviceName: geo
servicePort: 80
apiKey:
in: query
name: key
value: fcxxxxxxxxxxxxxxxxxx
api: |
openapi: 3.1.0
info:
title: 高德地图
description: 获取 POI 的相关信息
version: v1.0.0
servers:
- url: https://restapi.amap.com
paths:
/v5/place/text:
get:
description: 根据POI名称,获得POI的经纬度坐标
operationId: get_location_coordinate
parameters:
- name: keywords
in: query
description: POI名称,必须是中文
required: true
schema:
type: string
- name: region
in: query
description: POI所在的区域名,必须是中文
required: true
schema:
type: string
/v5/place/around:
get:
description: 搜索给定坐标附近的POI
operationId: search_nearby_pois
parameters:
- name: keywords
in: query
description: 目标POI的关键字
required: true
schema:
type: string
- name: location
in: query
description: 中心点的经度和纬度,用逗号隔开
required: true
schema:
type: string
- apiProvider:
domain: api.seniverse.com
serviceName: seniverse
servicePort: 80
apiKey:
in: query
name: key
value: SMxxxxxxxxxxxxxx
api: |
openapi: 3.1.0
info:
title: 心知天气
description: 获取天气预报相关信息
version: v1.0.0
servers:
- url: https://api.seniverse.com
paths:
/v3/weather/now.json:
get:
description: 获取指定城市的天气实况
operationId: get_weather_now
parameters:
- name: location
in: query
description: 所查询的城市
required: true
schema:
type: string
- name: language
in: query
description: 返回天气查询结果所使用的语言
required: true
schema:
type: string
default: zh-Hans
enum: [zh-Hans, en, ja]
- name: unit
in: query
description: 表示温度的单位,有摄氏度和华氏度两种
required: true
schema:
type: string
default: c
enum: [c, f]The configuration consists of three parts: dashscope (large‑model service), promptTemplate (custom ReAct template), and apis (external API definitions with OpenAPI specifications). The apis section is crucial for enabling the agent to call external tools.
Plugin Effects
Example curl requests to the gateway and the corresponding JSON responses illustrate map search and weather queries.
curl 'http://<gateway_ip>/api/openai/v1/chat/completions' \
-H 'Accept: application/json, text/event-stream' \
-H 'Content-Type: application/json' \
--data-raw '{"messages":[{"role":"user","content":"我想在济南市鑫盛大厦附近喝咖啡,给我推荐几个"}],"model":"qwen","stream":false}' {"content":" 在济南市鑫盛大厦附近,您可以选择以下咖啡店:
1. luckin coffee ..."} curl 'http://<gateway_ip>/api/openai/v1/chat/completions' \
-H 'Accept: application/json, text/event-stream' \
-H 'Content-Type: application/json' \
--data-raw '{"messages":[{"role":"user","content":"济南市现在的天气情况如何?"}],"model":"qwen","stream":false}' {"content":" 济南市现在的天气状况为阴天,温度为31℃。"}ReAct Principle
ReAct (Reasoning and Acting) combines chain‑of‑thought reasoning with tool‑calling actions and observations, as described in the paper “ReAct: Synergizing Reasoning and Acting in Language Models”. The model iteratively produces Thought, Action, Action Input, and Observation until a Final Answer is reached.
Plugin Implementation Logic
During the onHttpRequestBody stage, the original user query is replaced by a prompt that includes the tool definitions ({tools}, {tools_name}) and the custom ReAct template. The modified request is sent to the large‑model via ai‑proxy.
During the onHttpResponseBody stage, the model’s output is captured, stored in messageStore, and parsed with regular expressions to extract Action and Action Input. The corresponding external API is invoked (e.g., AMap location lookup), the result is appended as an Observation, and the updated conversation is sent back to the model. This loop repeats until the model emits a Final Answer, at which point proxywasm.ReplaceHttpResponseBody replaces the response body with the final answer.
Summary
The article introduced the background and concept of AI Agents, demonstrated how to use the AI Agent gateway plugin with Higress, showed its practical effects through example requests, and detailed the ReAct‑based implementation that enables zero‑code AI Agent construction.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Alibaba Cloud Developer
Alibaba's official tech channel, featuring all of its technology innovations.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
