跳到主要内容

API Request

当前默认 builtin tool registry 不注册 api_request。保留此页面是为了兼容旧文档链接;HTTP 工具边界仍在向当前能力收敛。

当前版本中:

  • 抓取网页或 HTTP 响应内容使用 web_fetch
  • 网络搜索使用 web_search
  • 其他应用调用 MushroomAgent 时,使用服务 API(httpwebsocketfunc
  • 查看本地实际可用工具,请运行 mushroom-agent tools list

当前替代方式

需求使用
抓取 URL 并返回内容web_fetch
搜索网页web_search
从其他服务调用 MushroomAgentHTTP /v1/chat、WebSocket chat/realtime,或 Func communication
运行本地集成脚本execprocess

历史形态

旧文档曾描述一个带 API-style 字段的 api_request 工具。除非 mushroom-agent tools list 在你的 runtime 中显示了 api_request,否则不要假设这些字段可用。

必填字段

参数说明
base_urlAPI 根地址,例如 http://api.internal:8080
methodGETPOSTPUTPATCHDELETE
path相对 API 路径,例如 /v1/users

可选字段

  • query
  • headers
  • body
  • timeout

如果 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" }
}