Files
enterprise-ai-agent-gateway/README.md
T

7.8 KiB

Enterprise AI Agent Gateway (企业级 AI 智能体网关)

🌍 English Version Below

Enterprise AI Agent Gateway 是一个定位于大模型(LLM/AI Agent)与企业老旧业务系统(Legacy Systems)之间的安全中间件与协议转换枢纽。

在企业内部署 AI Agent 时,直接让 LLM 调用复杂的企业内网 API 存在极大的数据泄露风险、越权风险以及由于老旧系统返回冗余数据而导致的 LLM Token 灾难消耗问题。本项目通过提供轻量级的前端控制面与高性能的后端数据面,完美解决了这些痛点。


🌟 核心特性 (Key Features)

  • 🛡️ 纯粹的数据洗涤沙箱 (GraalVM Data Washing):内置安全隔离的 GraalVM Polyglot 引擎,允许管理员为主机 API 配置动态 JavaScript 洗涤脚本,在网关层将数百 KB 的冗余老旧 JSON 裁剪为只剩核心业务字段的极致精简 Payload,大幅节省 LLM Token。
  • ⛓️ 高扩展责任链架构 (Filter Chain):采用标准的 GatewayContext 穿透全链路,内置鉴权防刷 (Redis)、权限穿透 (Identity OBO)、危险动作人工挂起 (HITL Suspender) 以及全异步数据审计 (Async Audit)。
  • 🔌 多协议执行策略 (Protocol Strategy):不仅支持基础的 HTTP 代理透传,底层执行器已完全抽象为 ExecutionStrategy 策略模式,未来从 HTTP 无缝切换/并存至 Dubbo、Spring Cloud Feign 毫无架构包袱。
  • ⚡ 极速内存直读 (Caffeine Local Cache):数据面网关对 API 配置信息的读取不会疯狂查询 DB,而是通过 Caffeine 提供带 TTL 的本地高速缓存。
  • 🎨 开箱即用的控制台 (Control Plane):内置 Vue3 + Vite + Element Plus 编写的现代化管理后台,可以实现租户鉴权发放、工具注册配置、清洗脚本在线测试及全生命周期审计日志的可视化检索。

🛠️ 技术栈 (Tech Stack)

  • 后端 (Data Plane & Control Plane API)
    • Java 17 / 21
    • Spring Boot 3.2.x
    • GraalVM Polyglot (JavaScript Sandbox)
    • MyBatis-Plus (MySQL 8.0)
    • Caffeine & Redis
    • OkHttp3 (HTTP Execution Proxy)
  • 前端 (Control Plane UI)
    • Vue 3 (Composition API)
    • Vite 5
    • Element Plus
    • Axios & Vue Router

📁 项目结构 (Monorepo Structure)

enterprise-ai-agent-gateway/
├── backend/                  # Java Spring Boot 后端工程
│   ├── pom.xml
│   └── src/main/
│       ├── java/.../gateway/
│       │   ├── controller/   # 管理台 CRUD API & 代理网关入口 API
│       │   ├── engine/       # GraalVM / Cache 引擎组件
│       │   ├── filter/       # 核心责任链路拦截器
│       │   ├── model/        # 数据库实体
│       │   └── service/      # 业务逻辑与执行策略抽象
│       └── resources/
│           ├── application.yml # 配置文件
│           └── schema.sql      # 数据库初始化建表脚本
│
└── frontend/                 # Vue 3 管理台前端工程
    ├── package.json
    ├── vite.config.js
    └── src/
        ├── api/              # 后端接口 Axios 封装
        ├── views/            # 管理台视图 (Tenant, Tool, Script, Audit)
        └── App.vue           # 侧边栏整体布局

🚀 快速开始 (Quick Start)

1. 数据库准备

  • 运行 MySQL 8.x 服务。
  • 创建数据库 db_agent_gateway。
  • 执行 backend/src/main/resources/schema.sql 完成表结构与测试数据的初始化。

2. 启动后端 (Backend)

  • 修改 backend/src/main/resources/application.yml 中的数据库账号密码及 Redis 配置(支持无 Redis 本地优雅降级)。
  • 通过 IDE 或 Maven 启动应用:
cd backend
mvn spring-boot:run
  • 后端服务默认运行于 http://localhost:8080。

3. 启动管理后台 (Frontend)

需要 Node.js 环境 (推荐 v18+)。

cd frontend
npm install
npm run dev
  • 浏览器访问 http://localhost:5173 进入 AI Gateway 管理控制台。

4. 链路测试 (API Invocation Test)

通过终端向网关数据面发起 API 请求验证洗涤链路(确保请求头携带控制台分配的对应 X-App-Key):

curl -X GET 'http://localhost:8080/api/v1/gw/invoke/get_time' \
  -H "X-App-Key: test_key" --noproxy '*'

随后你可以在控制台的「审计日志」页面看到刚刚这笔调用的清洗前后比对!



Enterprise AI Agent Gateway

Enterprise AI Agent Gateway is a secure middleware and protocol conversion hub positioned between Large Language Models (LLM / AI Agents) and legacy enterprise systems.

When deploying AI Agents within an enterprise, allowing LLMs to directly invoke complex intranet APIs poses significant data leakage risks, unauthorized access risks, and catastrophic LLM Token consumption caused by redundant data returned by outdated systems. This project perfectly solves these pain points by providing a lightweight frontend Control Plane and a high-performance backend Data Plane.


🌟 Key Features

  • 🛡️ GraalVM Data Washing Sandbox: Built-in securely isolated GraalVM Polyglot engine, allowing administrators to configure dynamic JavaScript washing scripts for host APIs. At the gateway layer, hundreds of KBs of redundant legacy JSON can be trimmed down to a minimal payload containing only core business fields, drastically saving LLM Tokens.
  • ⛓️ Highly Extensible Context Filter Chain: Utilizes a standard GatewayContext penetrating the entire traffic chain, with built-in configurations for auth & rate limiting (Redis), Identity OBO (On-Behalf-Of), Human-In-The-Loop Suspender (for WRITE risky actions), and fully asynchronous data auditing.
  • 🔌 Multi-Protocol Execution Strategy: Not only supports basic HTTP proxy passthrough; the underlying executor is fully abstracted into an ExecutionStrategy pattern. Seamless switching or coexisting with Dubbo or Spring Cloud Feign in the future requires zero architectural burden.
  • ⚡ Lightning-Fast Memory Read: Configuration fetching on the high-concurrency Data Plane does not bombard the DB. Instead, it relies on Caffeine to provide TTL-based local high-speed caching.
  • 🎨 Out-of-the-Box Control Panel: A modern admin backend written in Vue3 + Vite + Element Plus is included, offering visual management for tenant auth, tool registry, online wash script testing, and full-lifecycle audit log retrieval.

🛠️ Tech Stack

  • Backend (Data Plane & Control Plane API): Java 21, Spring Boot 3.2.x, GraalVM Polyglot (JS Sandbox), MyBatis-Plus (MySQL 8), Caffeine cache, OkHttp3.
  • Frontend (Control Plane UI): Vue 3 (Composition API), Vite 5, Element Plus, Axios, Vue Router.

🚀 Quick Start

1. Database Setup

  • Run MySQL 8.x.
  • Create a database named db_agent_gateway.
  • Execute backend/src/main/resources/schema.sql to initialize tables and test data.

2. Start Backend

  • Update DB and Redis credentials in backend/src/main/resources/application.yml (supports graceful degradation if local Redis is down).
  • Run the application:
cd backend
mvn spring-boot:run
  • The backend runs on http://localhost:8080 by default.

3. Start Frontend Console

Requires Node.js (v18+ recommended).

cd frontend
npm install
npm run dev
  • Access http://localhost:5173 in your browser to view the admin console.

4. End-to-End Test

Send a request to the Data Plane to verify the washing chain (ensure to include the valid X-App-Key allocated in the console):

curl -X GET 'http://localhost:8080/api/v1/gw/invoke/get_time' \
  -H "X-App-Key: test_key" --noproxy '*'

You can instantly view the before-and-after payload contrast of this transaction in the "Audit Log" page of the Admin Console!