API Request
api_request 是面向接口调用的 HTTP 工具。和 web_fetch 相比,它不强调正文提取,而是强调“按 API 的方式请求并返回结构化结果”。
必填字段
| 参数 | 说明 |
|---|---|
base_url | API 根地址,例如 http://api.internal:8080 |
method | GET、POST、PUT、PATCH、DELETE |
path | 相对 API 路径,例如 /v1/users |
可选字段
queryheadersbodytimeout
如果 body 是对象或数组,实现会自动转 JSON,并补上 Content-Type: application/json。
返回格式
结果会统一收敛成:
{
"ok": true,
"status": 200,
"result": {},
"error": null
}
失败时 ok=false,并带上 HTTP 状态或异常信息。
配置
tools:
api_request:
enabled: true
timeout: 20
max_bytes: 200000
follow_redirects: true
user_agent: "MushroomAgent api_request/1.0"
使用场景
- 内网服务
- 结构化 REST API
- 需要自定义 header、body、query 的接口
- 比
web_fetch更接近业务 API 的调用
示例
{
"tool": "api_request",
"base_url": "http://api.internal:8080",
"method": "POST",
"path": "/v1/jobs",
"body": { "name": "sync" }
}