feat(channel): unify deliverable outbound and WeChat attachments

Require deliverable:true for all channel attachments including images; extend save_deliverable_attachment with attachment_id; add WeChat proactive attachment delivery; inject channel file rules via system prompt instead of repeating on every user message.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-07-13 15:56:50 +08:00
parent dc5da21f5a
commit cbe68a54cd
14 changed files with 440 additions and 125 deletions

View file

@ -1,34 +1,42 @@
---
name: channel-file-delivery
description: "在 WhatsApp/微信等渠道会话中,把生成的文件作为附件发回用户。区分:write_file 仅文本(csv/txt);xlsx 等二进制用 run_command + save_deliverable_attachment。"
description: "在 WhatsApp/微信等渠道会话中,把生成的附件发回用户。所有类型(文档/图片/视频)均需 save_deliverable_attachment(path 或 attachment_id)。"
---
# 渠道文件发送 — Channel File Delivery
## 何时使用
用户在 **WhatsApp / 微信** 等渠道对话中,要求你生成并**把文件发给他**(不仅是文字说明路径)。
用户在 **WhatsApp / 微信(wechat/weixin)** 等渠道对话中,要求你生成并**把附件发给他**(文档、图片、视频等,不仅是文字说明路径)。渠道附件规则在系统提示中已注入,无需在每轮用户消息里重复。
## 关键规则
## 关键规则(统一)
1. **`write_file` / `run_command` 不会自动发送附件**
文件只会落在 workspace 磁盘上,渠道出站看不到。
1. **生成工具不会自动发送附件**
`write_file`、`run_command`、`cloudflare_image_generate` 等只产生内容,渠道出站看不到。
2. **必须调用 `save_deliverable_attachment`**
在文件生成完成后,用该工具把 workspace 文件注册到 attachment store,并标记 `deliverable`。
生成完成后用该工具标记 `deliverable`,系统才会随回复发送。
3. **再用简短文字回复**
说明文件名与要点;系统会把标记为 deliverable 的附件随本条回复发到渠道。
说明文件名或要点。
| 生成方式 | `save_deliverable_attachment` 参数 |
|----------|--------------------------------------|
| workspace 文件(csv/txt/xlsx) | `path="data/workspace/..."` |
| 生图/生视频(已有 attachment_id) | `attachment_id="..."` |
**用户上传的文件不要回传**;那是分析输入,不是生成输出。
## 工具选择(文本 vs 二进制)
| 目标格式 | 用哪个工具 | 说明 |
|----------|------------|------|
| `.csv`、`.txt`、`.md`、`.json` 等纯文本 | `write_file` | 只能写文本内容,不能生成二进制 |
| `.xlsx`、`.xls` 等 Excel | `run_command` | 用 Python(`openpyxl` 已安装)在 workspace 里生成 |
| 其他需脚本/命令产出的文件 | `run_command` | 生成后再走 deliverable 流程 |
| `.csv`、`.txt`、`.md`、`.json` 等纯文本 | `write_file` | 只能写文本内容 |
| `.xlsx`、`.xls` 等 Excel | `run_command` | 用 Python(`openpyxl` 已安装) |
| 图片 | `cloudflare_image_generate` 等 | 生成后用 `attachment_id` 标记 |
| 视频 | 对应生成工具 | 生成后用 `attachment_id` 标记 |
**不要声称没有 `run_command`。** 若用户要真 `.xlsx`,优先用 `run_command` 生成,不要只用 `write_file` 写 CSV 再说是「限制」。
**不要声称没有 `run_command`。** 用户要真 `.xlsx` 时优先用 `run_command`,不要只写 CSV 代替。
## 推荐流程
@ -37,7 +45,7 @@ description: "在 WhatsApp/微信等渠道会话中,把生成的文件作为
```text
1. write_file → data/workspace/tmp/report.csv
2. save_deliverable_attachment(path="data/workspace/tmp/report.csv", name="report.csv")
3. 文字回复:「已附上 report.csv…」
3. 文字回复
```
**Excel(xlsx):**
@ -45,7 +53,15 @@ description: "在 WhatsApp/微信等渠道会话中,把生成的文件作为
```text
1. run_command → python 写入 data/workspace/tmp/report.xlsx
2. save_deliverable_attachment(path="data/workspace/tmp/report.xlsx", name="report.xlsx")
3. 文字回复:「已附上 report.xlsx…」
3. 文字回复
```
**图片:**
```text
1. cloudflare_image_generate → 得到 attachment_id
2. save_deliverable_attachment(attachment_id="...")
3. 文字回复
```
## Excel 示例
@ -57,16 +73,13 @@ description: "在 WhatsApp/微信等渠道会话中,把生成的文件作为
1. run_command(示例):
python -c "from openpyxl import Workbook; wb=Workbook(); ws=wb.active; ws.append(['姓名','数量']); ws.append(['A',10]); wb.save('data/workspace/tmp/summary.xlsx')"
2. save_deliverable_attachment(path="data/workspace/tmp/summary.xlsx", name="summary.xlsx")
3. 回复摘要(行数、主要结论)
3. 回复摘要
```
用户明确要 `.xlsx` 时,不要退化成只发 CSV,除非用户同意用 CSV 代替。
## 限制
- 每轮回复通常只发送**第一个**附件(约 8MB 上限)。
- 每轮回复通常只发送**第一个** deliverable 附件(约 8MB 上限)。
- 超大文件应压缩、抽样或只发摘要。
- 用户**上传**的文件不要用 `save_deliverable_attachment` 回传;那是分析输入,不是生成输出。
## 相关