Files
api_health/agent/infra/skills/baidu-ai-map/references/agent-plan-api.md
T
2026-10-28 11:15:29 +08:00

195 lines
4.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Agent Plan API 参考
所有接口统一使用 `https://api.map.baidu.com`,鉴权由 `http_get` 工具自动注入:
`Authorization: Bearer <BAIDU_MAP_AUTH_TOKEN>`
调用时不要把 token 写进 URL、headers 或回答。查询参数放在 `params` 对象中,工具会统一做 URL 编码。
## 目录
- [Place](#place)
- [Direction](#direction)
- [Geocoding](#geocoding)
- [Reverse Geocoding](#reverse-geocoding)
- [Weather](#weather)
- [响应与排错](#响应与排错)
## Place
`GET /agent_plan/v1/place`
必填参数:
- `user_raw_request`:完整保留用户原始需求和约束词,不压缩成关键词。
- `region`:城市或区域限制。
可选参数:
- `center`:检索中心和排序参考点,格式为 `lat,lng`,坐标系为 `gcj02`。
- `sort`:`distance` 或 `relevance`,默认为 `relevance`。
规则:
- `sort=distance` 时必须传 `center`。
- `center` 必须来自用户或可信接口结果,不得推测;经纬度至少保留 6 位小数。
示例:
```text
http_get({
url: "https://api.map.baidu.com/agent_plan/v1/place",
params: {
user_raw_request: "帮我查一下八达岭长城附近的五星级酒店",
region: "延庆区",
sort: "relevance"
}
})
```
按距离排序:
```text
http_get({
url: "https://api.map.baidu.com/agent_plan/v1/place",
params: {
user_raw_request: "离我最近的火锅店",
region: "北京市",
center: "40.056800,116.308300",
sort: "distance"
}
})
```
## Direction
`GET /agent_plan/v1/direction`
必填参数:
- `user_raw_request`:包含起终点并保留完整路线约束。接口仅支持驾车、步行、骑行、公交,其他交通方式需改写为其中一种。
- `location`:用户当前位置,格式为 `lat,lng`,坐标系为 `gcj02`;用于推理模糊或同名起点。
可选参数:
- `refer_pois`:地点精确映射,格式 `地点名称:uid,纬度,经度;地点名称:uid,纬度,经度`。仅在明确存在同名地点或别名消歧时传入。
规则:
- `location` 与 `refer_pois` 的坐标必须来自用户或可信接口结果,经纬度至少保留 6 位小数。
- 响应可能是路线,也可能是起终点候选;无法根据用户需求唯一消歧时,再请用户选择。
示例:
```text
http_get({
url: "https://api.map.baidu.com/agent_plan/v1/direction",
params: {
user_raw_request: "从故宫驾车到颐和园",
location: "39.914590,116.403770"
}
})
```
别名精确映射:
```text
http_get({
url: "https://api.map.baidu.com/agent_plan/v1/direction",
params: {
user_raw_request: "步行去我家附近最近的中餐厅",
location: "40.056800,116.308300",
refer_pois: "我家:fbc88a21464370106e3e1b52,40.092180,116.345310"
}
})
```
## Geocoding
`GET /agent_plan/v1/geocoding`
- 必填 `address`:尽量完整的地址。
- 可选 `region`:城市或区域提示,用于减少歧义。
示例:
```text
http_get({
url: "https://api.map.baidu.com/agent_plan/v1/geocoding",
params: {
address: "北京市海淀区上地十街10号百度大厦",
region: "北京市"
}
})
```
## Reverse Geocoding
`GET /agent_plan/v1/reverse_geocoding`
必填 `location`,格式为 `lat,lng`,坐标系为 `gcj02`,经纬度至少保留 6 位小数。
示例:
```text
http_get({
url: "https://api.map.baidu.com/agent_plan/v1/reverse_geocoding",
params: {
location: "40.056800,116.308300"
}
})
```
## Weather
`GET /agent_plan/v1/weather`
- `region`:行政区划名称。
- `location`:`lat,lng` 格式的 gcj02 坐标。
两者至少传一个。传坐标时,经纬度至少保留 6 位小数。
按行政区划:
```text
http_get({
url: "https://api.map.baidu.com/agent_plan/v1/weather",
params: {
region: "北京市"
}
})
```
按坐标:
```text
http_get({
url: "https://api.map.baidu.com/agent_plan/v1/weather",
params: {
location: "38.766230,116.432130"
}
})
```
## 响应与排错
`http_get` 返回结构:
```json
{
"success": true,
"status": 200,
"body": {},
"truncated": false
}
```
- 业务数据在 `body` 中;`body` 可能是字符串,也可能是已解析的 JSON 对象,按实际类型读取。
- `success: false`:网络、DNS、超时或出网策略拦截,查看 `error` 字段并向用户说明。
- `401` / `403`:服务端未配置 `BAIDU_MAP_AUTH_TOKEN`,或 token 已失效;告知普通用户地图服务暂不可用,管理员侧检查 `conf.json` 的 `agent.baiduMap.authToken` / 环境变量,不要索要明文 token。
- `400`:参数错误;检查必填项、坐标格式、`sort=distance` 是否带 `center`。
- `429`:频控;提示用户稍后重试。
- `5xx`:百度地图服务异常;提示用户稍后重试。
- `truncated: true`:响应超过 2MB 被截断;缩小检索范围或改查更具体的接口。
- 不要用正则从响应文本中猜测字段;直接读取 JSON 结构。