移除对 copilot 的兼容。更新示例和文档,统一使用 session_id 代替 conversationId
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
# 示例(基于 chat/stream 工具调用链)
|
||||
# 示例(基于 opencode Agent chat/stream 工具调用链)
|
||||
|
||||
## 示例 1:前端发起对话,LLM 触发工具调用
|
||||
## 示例 1:前端发起对话,opencode agent 触发工具调用
|
||||
|
||||
用户意图:查询设备 `170490` 在时间范围内的 `monitored_value`。
|
||||
|
||||
前端调用 `POST /api/v1/copilot/chat/stream`:
|
||||
前端调用 `POST /api/v1/agent/chat/stream`:
|
||||
|
||||
```json
|
||||
{
|
||||
"message": "请查询设备170490在最近24小时的monitored_value历史数据",
|
||||
"conversationId": "conv-demo-001"
|
||||
"session_id": "agent-demo-001"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
- `x-project-id: <project-id>`
|
||||
|
||||
服务端内部行为:
|
||||
- LLM 选择工具 `dynamic_http_call`
|
||||
- opencode agent 选择工具 `dynamic_http_call`
|
||||
- 工具参数示例:
|
||||
```json
|
||||
{
|
||||
@@ -33,7 +33,7 @@
|
||||
}
|
||||
```
|
||||
|
||||
## 示例 2:LLM 多步规划 + 多次工具调用
|
||||
## 示例 2:opencode agent 多步规划 + 多次工具调用
|
||||
|
||||
用户消息:
|
||||
- “先查这个设备历史数据,再给我异常点摘要。”
|
||||
@@ -41,14 +41,14 @@
|
||||
典型链路:
|
||||
- 第一步工具调用:查询历史数据接口。
|
||||
- 第二步(可选)工具调用:查询补充数据接口。
|
||||
- LLM 汇总工具结果,持续通过 SSE 输出 token,最终返回 `done`。
|
||||
- opencode agent 汇总工具结果,持续通过 SSE 输出 token,最终返回 `done`。
|
||||
|
||||
## 示例 3:前端工具 — 定位要素
|
||||
|
||||
用户消息:
|
||||
- "帮我找到管道 P-001 和 P-002"
|
||||
|
||||
LLM 调用工具 `locate_features`:
|
||||
opencode agent 调用工具 `locate_features`:
|
||||
```json
|
||||
{
|
||||
"ids": ["P-001", "P-002"],
|
||||
@@ -56,7 +56,7 @@ LLM 调用工具 `locate_features`:
|
||||
}
|
||||
```
|
||||
|
||||
前端收到 SSE 事件后缩放地图并高亮管道。LLM 回复文字:"已在地图上定位到管道 P-001 和 P-002。"
|
||||
前端收到 SSE 事件后缩放地图并高亮管道。opencode agent 回复文字:"已在地图上定位到管道 P-001 和 P-002。"
|
||||
|
||||
## 示例 4:前端工具 — 对话内图表
|
||||
|
||||
@@ -64,10 +64,10 @@ LLM 调用工具 `locate_features`:
|
||||
- "展示节点 J-001 最近一天的压力变化曲线"
|
||||
|
||||
典型链路:
|
||||
1. LLM 先调用 `dynamic_http_call` 查询数据
|
||||
1. opencode agent 先调用 `dynamic_http_call` 查询数据
|
||||
2. 拿到数据后,调用 `show_chart` 将处理好的数据传给前端渲染
|
||||
|
||||
第一步 — LLM 调用 `dynamic_http_call`:
|
||||
第一步 — opencode agent 调用 `dynamic_http_call`:
|
||||
```json
|
||||
{
|
||||
"path": "/api/v1/composite/element-simulation",
|
||||
@@ -80,7 +80,7 @@ LLM 调用工具 `locate_features`:
|
||||
}
|
||||
```
|
||||
|
||||
第二步 — LLM 处理数据后调用 `show_chart`:
|
||||
第二步 — opencode agent 处理数据后调用 `show_chart`:
|
||||
```json
|
||||
{
|
||||
"title": "节点 J-001 压力变化",
|
||||
@@ -103,7 +103,7 @@ LLM 调用工具 `locate_features`:
|
||||
用户消息:
|
||||
- "我想看看 J-001 的监测数据"
|
||||
|
||||
LLM 调用工具 `view_scada`:
|
||||
opencode agent 调用工具 `view_scada`:
|
||||
```json
|
||||
{
|
||||
"device_ids": ["J-001"],
|
||||
|
||||
+11
-11
@@ -3,17 +3,17 @@
|
||||
## 1) 总体原则
|
||||
|
||||
- Skills 负责“告诉模型可做什么”。
|
||||
- `chat/stream` 内部启动 LLM 会话,并注册工具 `dynamic_http_call`。
|
||||
- LLM 通过工具调用后端能力,不直接发 HTTP。
|
||||
- Sidecar 执行器负责“代表当前用户调真实后端 API”(动态路径,无白名单)。
|
||||
- `chat/stream` 内部启动 opencode 会话,并注册工具 `dynamic_http_call`。
|
||||
- opencode agent 通过工具调用后端能力,不直接发 HTTP。
|
||||
- TJWaterAgent 执行器负责“代表当前用户调真实后端 API”(动态路径,无白名单)。
|
||||
|
||||
## 2) 请求入口(前端)
|
||||
|
||||
- `POST /api/v1/copilot/chat/stream`(唯一前端入口)
|
||||
- `POST /api/v1/agent/chat/stream`(唯一前端入口)
|
||||
|
||||
不提供 `/execute` 对外调用路径,统一通过 `chat/stream` + 工具调用链执行。
|
||||
|
||||
## 3) 工具参数约定(LLM 调用工具时)
|
||||
## 3) 工具参数约定(opencode agent 调用工具时)
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -53,18 +53,18 @@
|
||||
前端工具(`locate_features`, `view_history`, `view_scada`, `show_chart`)的调用链与 `dynamic_http_call` 不同:
|
||||
|
||||
```
|
||||
用户消息 → LLM → function calling → 调用前端工具 (如 locate_features)
|
||||
用户消息 → opencode agent → tool calling → 调用前端工具 (如 locate_features)
|
||||
↓
|
||||
tool handler:
|
||||
1) 推送 SSE tool_call 事件到前端
|
||||
2) 返回简短确认给 LLM("已定位到管道")
|
||||
2) 返回简短确认给 opencode agent("已定位到管道")
|
||||
↓
|
||||
前端同时收到:
|
||||
- SSE event: tool_call → 前端执行操作(定位地图/打开面板/渲染图表)
|
||||
- SSE event: token → 渲染 LLM 文字回复
|
||||
- SSE event: token → 渲染 opencode agent 文字回复
|
||||
```
|
||||
|
||||
关键区别:
|
||||
- `dynamic_http_call`:Sidecar 代理 HTTP 请求,结果返回给 LLM 做后续分析。
|
||||
- 前端工具:Sidecar 仅推送 SSE 事件,前端直接执行,结果不返回 LLM。
|
||||
- `show_chart`:LLM 先通过 `dynamic_http_call` 查询数据,处理为 x_data + series 格式后调用 `show_chart`,前端直接渲染图表,不再请求后端。
|
||||
- `dynamic_http_call`:TJWaterAgent 代理 HTTP 请求,结果返回给 opencode agent 做后续分析。
|
||||
- 前端工具:TJWaterAgent 仅推送 SSE 事件,前端直接执行,结果不返回 opencode agent。
|
||||
- `show_chart`:opencode agent 先通过 `dynamic_http_call` 查询数据,处理为 x_data + series 格式后调用 `show_chart`,前端直接渲染图表,不再请求后端。
|
||||
|
||||
Reference in New Issue
Block a user