@kenhkl/agent-gate 0.2.2 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +138 -2
- package/dist/cli.js +28930 -172
- package/dist/cli.js.map +1 -1
- package/package.json +13 -9
package/README.md
CHANGED
|
@@ -41,7 +41,123 @@ npm run build
|
|
|
41
41
|
|
|
42
42
|
## 2. 启动服务
|
|
43
43
|
|
|
44
|
-
AgentGate
|
|
44
|
+
AgentGate 是一个**独立常驻服务**,支持以下运行方式:
|
|
45
|
+
|
|
46
|
+
### 2.1 前台运行(测试/开发)
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# 方式 1: 直接运行(占用终端)
|
|
50
|
+
agent-gate gateway --config config/agent_gate.yaml
|
|
51
|
+
|
|
52
|
+
# 方式 2: 使用 npm script
|
|
53
|
+
npm run dev:gateway
|
|
54
|
+
|
|
55
|
+
# 方式 3: 使用 tsx(开发模式,自动重启)
|
|
56
|
+
npx tsx src/cli.ts gateway --config config/agent_gate.yaml
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 2.2 后台运行(日常使用)
|
|
60
|
+
|
|
61
|
+
#### 方式 1: nohup(简单)
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# 后台运行,日志输出到文件
|
|
65
|
+
nohup agent-gate gateway --config config/agent_gate.yaml > logs/gateway_ts.log 2>&1 &
|
|
66
|
+
|
|
67
|
+
# 查看进程 ID
|
|
68
|
+
echo $!
|
|
69
|
+
|
|
70
|
+
# 查看日志
|
|
71
|
+
tail -f logs/gateway_ts.log
|
|
72
|
+
|
|
73
|
+
# 停止服务
|
|
74
|
+
pkill -f "agent-gate gateway"
|
|
75
|
+
# 或使用进程 ID
|
|
76
|
+
kill <PID>
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
#### 方式 2: screen/tmux(推荐)
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# 使用 screen
|
|
83
|
+
screen -S agentgate-ts
|
|
84
|
+
agent-gate gateway --config config/agent_gate.yaml
|
|
85
|
+
|
|
86
|
+
# 按 Ctrl+A+D 分离会话(服务继续运行)
|
|
87
|
+
# 重新连接: screen -r agentgate-ts
|
|
88
|
+
|
|
89
|
+
# 使用 tmux
|
|
90
|
+
tmux new -s agentgate-ts
|
|
91
|
+
agent-gate gateway --config config/agent_gate.yaml
|
|
92
|
+
|
|
93
|
+
# 按 Ctrl+B+D 分离会话(服务继续运行)
|
|
94
|
+
# 重新连接: tmux attach -t agentgate-ts
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### 2.3 systemd 服务(生产环境)
|
|
98
|
+
|
|
99
|
+
**适用于长期部署、开机自启动场景。**
|
|
100
|
+
|
|
101
|
+
#### 安装 systemd 服务
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
# 使用安装脚本
|
|
105
|
+
bash scripts/install-systemd-ts.sh
|
|
106
|
+
|
|
107
|
+
# 或手动安装(需要 sudo)
|
|
108
|
+
sudo cp deploy/agentgate-ts.service.template /etc/systemd/system/agentgate-ts.service
|
|
109
|
+
sudo systemctl daemon-reload
|
|
110
|
+
sudo systemctl start agentgate-ts
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
#### 服务管理命令
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
# 启动服务
|
|
117
|
+
sudo systemctl start agentgate-ts
|
|
118
|
+
|
|
119
|
+
# 停止服务
|
|
120
|
+
sudo systemctl stop agentgate-ts
|
|
121
|
+
|
|
122
|
+
# 重启服务
|
|
123
|
+
sudo systemctl restart agentgate-ts
|
|
124
|
+
|
|
125
|
+
# 查看状态
|
|
126
|
+
sudo systemctl status agentgate-ts
|
|
127
|
+
|
|
128
|
+
# 查看日志
|
|
129
|
+
tail -f logs/gateway_ts.log
|
|
130
|
+
|
|
131
|
+
# 开机自启动
|
|
132
|
+
sudo systemctl enable agentgate-ts
|
|
133
|
+
|
|
134
|
+
# 禁用开机自启动
|
|
135
|
+
sudo systemctl disable agentgate-ts
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
#### 卸载 systemd 服务
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
# 使用卸载脚本
|
|
142
|
+
bash scripts/uninstall-systemd-ts.sh
|
|
143
|
+
|
|
144
|
+
# 或手动卸载
|
|
145
|
+
sudo systemctl stop agentgate-ts
|
|
146
|
+
sudo systemctl disable agentgate-ts
|
|
147
|
+
sudo rm /etc/systemd/system/agentgate-ts.service
|
|
148
|
+
sudo systemctl daemon-reload
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### 2.4 检查服务状态
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
# 使用状态检查脚本
|
|
155
|
+
bash scripts/status-agentgate-ts.sh
|
|
156
|
+
|
|
157
|
+
# 或手动检查
|
|
158
|
+
curl http://127.0.0.1:9110/health
|
|
159
|
+
curl http://127.0.0.1:9110/api/stats
|
|
160
|
+
```
|
|
45
161
|
|
|
46
162
|
### 2.1 启动 AgentMoss
|
|
47
163
|
|
|
@@ -222,7 +338,27 @@ Dashboard 为自包含 HTML 文件(内联 CSS + JS),浏览器直接打开
|
|
|
222
338
|
|
|
223
339
|
---
|
|
224
340
|
|
|
225
|
-
## 6.
|
|
341
|
+
## 6. 采集层对比
|
|
342
|
+
|
|
343
|
+
AgentGate 提供三层递进采集,TypeScript 版当前实现了 L1 和 L2:
|
|
344
|
+
|
|
345
|
+
| 维度 | L1 API Gateway | L2 PTY 拦截 | L3 eBPF(仅 Python) |
|
|
346
|
+
|------|---------------|------------|---------------------|
|
|
347
|
+
| **技术方案** | HTTP 代理拦截 LLM API 请求/响应 | 伪终端包装,捕获终端 I/O | 内核 eBPF tracepoint |
|
|
348
|
+
| **捕获内容** | tool_call JSON(工具名、参数、prompt) | 终端命令原文 + 输出结果 | syscall 元数据 |
|
|
349
|
+
| **能否捕获 prompt** | ✅ | ❌ | ❌ |
|
|
350
|
+
| **能否捕获 tool_call 参数** | ✅ LLM 返回的 JSON | ✅ 终端命令原文 | ✅ execve argv |
|
|
351
|
+
| **能否捕获执行结果** | ✅ tool_response | ✅ 终端输出 | ❌ |
|
|
352
|
+
| **LLM 建议 vs 实际执行** | LLM **建议**的操作 | Agent **实际**执行的操作 | syscall **真实落地**的操作 |
|
|
353
|
+
| **能否拦截** | ✅ 响应返回前拦截 | ✅ 信号中断 | ❌ |
|
|
354
|
+
| **跨平台** | ✅ 全平台 | ❌ 仅 Linux/macOS | ❌ 仅 Linux |
|
|
355
|
+
| **TS 实现** | ✅ `src/v3/gateway/` | ✅ `src/v3/pty/` | ❌ 未实现 |
|
|
356
|
+
|
|
357
|
+
> **一句话**:L1 知道 LLM **建议** Agent 做什么,L2 知道 Agent **实际**做了什么。
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
## 7. 关键设计
|
|
226
362
|
|
|
227
363
|
| 特性 | 说明 |
|
|
228
364
|
|------|------|
|