Skip to content

Commit e352740

Browse files
authored
Merge pull request #4 from AgentR1/blackbox_dev
[docs] add docs
2 parents d1f8142 + e8127a4 commit e352740

19 files changed

Lines changed: 1254 additions & 1236 deletions

docs/Installation.md

Lines changed: 0 additions & 36 deletions
This file was deleted.

docs/api/gateway.md

Lines changed: 168 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
# Gateway API
22

3-
The Gateway exposes an HTTP API on port `8000` (default). All endpoints accept and return JSON.
3+
Gateway 默认监听端口 **8100**(通过 `--port` 配置)。所有端点均接受和返回 JSON
44

55
## Base URL
66

77
```
8-
http://<gateway-host>:8000
8+
http://<gateway-host>:8100
99
```
1010

1111
---
1212

13-
## `POST /generate`
13+
## White-box 端点
1414

15-
Forward a generation request to vLLM and return the response with token IDs.
15+
这些端点由 `AgentFlowBase` 的白盒 Agent 调用。
1616

17-
**Used by**: `AgentFlowBase.gateway_generate()`
17+
### `POST /generate`
1818

19-
### Request
19+
将生成请求转发到 vLLM 并返回带 token ID 的响应。
20+
21+
**调用方**: `AgentFlowBase.gateway_generate()`
22+
23+
#### Request
2024

2125
```json
2226
{
@@ -31,16 +35,16 @@ Forward a generation request to vLLM and return the response with token IDs.
3135
}
3236
```
3337

34-
| Field | Type | Required | Description |
38+
| 字段 | 类型 | 必填 | 说明 |
3539
|---|---|---|---|
36-
| `trajectory_uid` | string | Yes | Unique ID for this conversation |
37-
| `prompt_uid` | string | Yes | Unique ID for the prompt group (GRPO grouping) |
38-
| `messages` | array | Yes | OpenAI-format chat messages |
39-
| `max_tokens` | int | No | Max response length (default: from `--response-length`) |
40-
| `temperature` | float | No | Sampling temperature (default: 1.0) |
41-
| `top_p` | float | No | Top-p sampling (default: 1.0) |
40+
| `trajectory_uid` | string | | 当前对话的唯一 ID |
41+
| `prompt_uid` | string | | Prompt 组 ID(用于 GRPO 分组) |
42+
| `messages` | array | | OpenAI 格式的聊天消息 |
43+
| `max_tokens` | int | | 最大响应长度(默认取 `--response-length` |
44+
| `temperature` | float | | 采样温度(默认 1.0 |
45+
| `top_p` | float | | Top-p 采样(默认 1.0 |
4246

43-
### Response
47+
#### Response
4448

4549
```json
4650
{
@@ -50,21 +54,15 @@ Forward a generation request to vLLM and return the response with token IDs.
5054
}
5155
```
5256

53-
| Field | Type | Description |
54-
|---|---|---|
55-
| `response_text` | string | Generated text |
56-
| `response_ids` | int[] | Token IDs of the generated response |
57-
| `prompt_ids` | int[] | Full context token IDs (prompt + prior turns) |
58-
5957
---
6058

61-
## `POST /submit_steps`
59+
### `POST /submit_steps`
6260

63-
Submit one or more `Step` objects to the DataPool.
61+
提交一个或多个 `Step` 对象到 DataPool
6462

65-
**Used by**: `AgentFlowBase.gateway_submit_steps()`
63+
**调用方**: `AgentFlowBase.gateway_submit_steps()`
6664

67-
### Request
65+
#### Request
6866

6967
```json
7068
{
@@ -84,22 +82,21 @@ Submit one or more `Step` objects to the DataPool.
8482
}
8583
```
8684

87-
### Response
85+
#### Response
8886

8987
```json
9088
{
91-
"submitted": 1,
92-
"status": "ok"
89+
"accepted": 1
9390
}
9491
```
9592

9693
---
9794

98-
## `POST /compute_reward`
95+
### `POST /compute_reward`
9996

100-
Compute a reward score for a step (called by Trainer, not by agents).
97+
为一个 step 计算 reward(由 Trainer 调用,不由 Agent 调用)。
10198

102-
### Request
99+
#### Request
103100

104101
```json
105102
{
@@ -112,7 +109,7 @@ Compute a reward score for a step (called by Trainer, not by agents).
112109
}
113110
```
114111

115-
### Response
112+
#### Response
116113

117114
```json
118115
{
@@ -122,47 +119,169 @@ Compute a reward score for a step (called by Trainer, not by agents).
122119

123120
---
124121

125-
## `POST /{trajectory_uid}/{prompt_uid}/v1/chat/completions` *(reserved)*
122+
## Black-box 端点
123+
124+
这些端点供黑盒 Agent 使用。黑盒 Agent 只需要知道一个 `base_url`,所有交互都通过该 URL 完成。
125+
126+
`base_url` 的格式为 `http://<host>:<port>/<trajectory_uid>/<prompt_uid>`,由 `POST /init_trajectory` 返回。
126127

127-
OpenAI-compatible endpoint for black-box agents. The `trajectory_uid` and `prompt_uid` are embedded in the URL path.
128+
### `POST /init_trajectory`
128129

129-
### Request
130+
分配一条新的 trajectory 并返回 `base_url`
130131

131-
Standard OpenAI `chat/completions` request body.
132+
#### Request
132133

133-
### Response
134+
无请求体。
134135

135-
Standard OpenAI `chat/completions` response.
136+
#### Response
136137

137-
!!! info "Status: Reserved"
138-
This endpoint is designed and stubbed. It will be the primary integration point for black-box online agents in a future release.
138+
```json
139+
{
140+
"trajectory_uid": "a1b2c3d4e5f6...",
141+
"base_url": "http://0.0.0.0:8100/a1b2c3d4e5f6.../1"
142+
}
143+
```
139144

140145
---
141146

142-
## `POST /complete_trajectory/{trajectory_uid}` *(reserved)*
147+
### `POST {base_url}/v1/register_trajectory`
148+
149+
注册 trajectory 的 channel 和 metadata。在 Agent 开始交互之前调用。
143150

144-
Signal that a trajectory is complete. Used in black-box mode when the agent manages conversation boundaries.
151+
`trajectory_uid` 从 URL path 中提取,无需在 body 中传递。
145152

146-
### Request
153+
#### Request
147154

148155
```json
149156
{
150-
"trajectory_uid": "string",
151-
"final_reward": 0.9
157+
"channel": "train",
158+
"metadata": {
159+
"data_source": "gsm8k",
160+
"ground_truth": "42"
161+
}
152162
}
153163
```
154164

155-
### Response
165+
所有字段均为可选。`channel` 默认为 `"train"`
166+
167+
#### Response
156168

157169
```json
158170
{ "status": "ok" }
159171
```
160172

161173
---
162174

163-
## Health Check
175+
### `POST {base_url}/v1/chat/completions`
176+
177+
OpenAI 兼容的聊天补全端点。黑盒 Agent 只需将 `base_url` 设为 OpenAI SDK 的 `base_url`,即可透明接入训练系统。
178+
179+
Gateway 会:
164180

165-
```bash
166-
curl http://localhost:8000/health
167-
# {"status": "ok"}
181+
1. 将请求转发到 vLLM 服务器
182+
2. 对 prompt 和 response 进行 tokenize
183+
3. 自动构建 `Step` 并提交到 DataPool
184+
4. 返回标准 OpenAI 格式的响应
185+
186+
#### Request
187+
188+
标准 OpenAI `chat/completions` 请求体。
189+
190+
```json
191+
{
192+
"model": "qwen",
193+
"messages": [
194+
{ "role": "user", "content": "What is 2+2?" }
195+
],
196+
"temperature": 0.7
197+
}
168198
```
199+
200+
#### Response
201+
202+
标准 OpenAI `chat/completions` 响应体。
203+
204+
```json
205+
{
206+
"id": "chatcmpl-...",
207+
"object": "chat.completion",
208+
"choices": [
209+
{
210+
"index": 0,
211+
"message": {
212+
"role": "assistant",
213+
"content": "4"
214+
},
215+
"finish_reason": "stop"
216+
}
217+
],
218+
"usage": {
219+
"prompt_tokens": 10,
220+
"completion_tokens": 1,
221+
"total_tokens": 11
222+
}
223+
}
224+
```
225+
226+
---
227+
228+
### `POST {base_url}/v1/complete_trajectory`
229+
230+
标记一条 trajectory 完成。Agent 完成所有交互后调用。
231+
232+
#### Request
233+
234+
无请求体。
235+
236+
#### Response
237+
238+
```json
239+
{ "status": "ok" }
240+
```
241+
242+
---
243+
244+
### `POST /complete_trajectory/{trajectory_uid}`
245+
246+
内部端点,通过 trajectory_uid 直接标记完成。可选传入 reward 和 channel。
247+
248+
#### Request
249+
250+
```json
251+
{
252+
"channel": "train",
253+
"reward": 0.9
254+
}
255+
```
256+
257+
#### Response
258+
259+
```json
260+
{ "status": "ok" }
261+
```
262+
263+
---
264+
265+
## 就绪检查
266+
267+
### `GET /ready`
268+
269+
当 Gateway 完全初始化(包括 tokenizer 加载完成)后返回 200。用于 Rollouter 启动时的健康检查。
270+
271+
#### Response (200)
272+
273+
```json
274+
{ "status": "ready" }
275+
```
276+
277+
#### Response (503)
278+
279+
```json
280+
{ "detail": "Gateway not ready (tokenizer still loading)" }
281+
```
282+
283+
---
284+
285+
## `GET /docs`
286+
287+
FastAPI 自动生成的 Swagger UI 文档页面。

0 commit comments

Comments
 (0)