Files
TJWaterAgent/.opencode/skills/examples.md
T

116 lines
2.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.
# 示例(基于 chat/stream 工具调用链)
## 示例 1:前端发起对话,LLM 触发工具调用
用户意图:查询设备 `170490` 在时间范围内的 `monitored_value`
前端调用 `POST /api/v1/copilot/chat/stream`
```json
{
"message": "请查询设备170490在最近24小时的monitored_value历史数据",
"conversationId": "conv-demo-001"
}
```
请求头至少包含(由前端传入):
- `Authorization: Bearer <token>`
- `x-project-id: <project-id>`
服务端内部行为:
- LLM 选择工具 `dynamic_http_call`
- 工具参数示例:
```json
{
"path": "/api/v1/scada/by-ids-field-time-range",
"method": "GET",
"arguments": {
"device_ids": "170490",
"field": "monitored_value",
"start_time": "2026-03-29T07:57:47.338Z",
"end_time": "2026-03-30T07:57:47.338Z"
}
}
```
## 示例 2:LLM 多步规划 + 多次工具调用
用户消息:
- “先查这个设备历史数据,再给我异常点摘要。”
典型链路:
- 第一步工具调用:查询历史数据接口。
- 第二步(可选)工具调用:查询补充数据接口。
- LLM 汇总工具结果,持续通过 SSE 输出 token,最终返回 `done`
## 示例 3:前端工具 — 定位要素
用户消息:
- "帮我找到管道 P-001 和 P-002"
LLM 调用工具 `locate_features`
```json
{
"ids": ["P-001", "P-002"],
"feature_type": "pipe"
}
```
前端收到 SSE 事件后缩放地图并高亮管道。LLM 回复文字:"已在地图上定位到管道 P-001 和 P-002。"
## 示例 4:前端工具 — 对话内图表
用户消息:
- "展示节点 J-001 最近一天的压力变化曲线"
典型链路:
1. LLM 先调用 `dynamic_http_call` 查询数据
2. 拿到数据后,调用 `show_chart` 将处理好的数据传给前端渲染
第一步 — LLM 调用 `dynamic_http_call`
```json
{
"path": "/api/v1/composite/element-simulation",
"method": "GET",
"arguments": {
"feature_infos": "[\"J-001\", \"node\"]",
"start_time": "2026-03-29T00:00:00Z",
"end_time": "2026-03-30T00:00:00Z"
}
}
```
第二步 — LLM 处理数据后调用 `show_chart`
```json
{
"title": "节点 J-001 压力变化",
"chart_type": "line",
"x_data": ["03-29 00:00", "03-29 01:00", "03-29 02:00", "..."],
"series": [
{
"name": "J-001 压力",
"data": [32.5, 31.8, 30.2, "..."]
}
],
"y_axis_name": "压力 (m)"
}
```
前端直接用 AI 提供的数据渲染 ECharts 图表,不再请求后端。
## 示例 5:前端工具 — 查看 SCADA 监测面板
用户消息:
- "我想看看 J-001 的监测数据"
LLM 调用工具 `view_scada`
```json
{
"device_ids": ["J-001"],
"start_time": "2026-03-29T00:00:00Z",
"end_time": "2026-03-30T00:00:00Z"
}
```
前端打开 SCADA 监测面板,展示该节点的历史监测曲线。