mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-08 23:33:16 +08:00
Add write_xlsx tool so agents export Excel via structured data instead of fragile openpyxl scripts.
Generation returns attachment_id only; channel delivery still requires save_deliverable_attachment. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
c31625d05b
commit
dbba8cafbf
6 changed files with 448 additions and 21 deletions
|
|
@ -12,7 +12,7 @@ description: "在 WhatsApp/微信等渠道会话中,把生成的附件发回
|
|||
## 关键规则(统一)
|
||||
|
||||
1. **生成工具不会自动发送附件**
|
||||
`write_file`、`run_command`、`cloudflare_image_generate` 等只产生内容,渠道出站看不到。
|
||||
`write_xlsx`、`write_file`、`run_command`、`cloudflare_image_generate` 等只产生内容,渠道出站看不到。
|
||||
|
||||
2. **必须调用 `save_deliverable_attachment`**
|
||||
生成完成后用该工具标记 `deliverable`,系统才会随回复发送。
|
||||
|
|
@ -22,24 +22,32 @@ description: "在 WhatsApp/微信等渠道会话中,把生成的附件发回
|
|||
|
||||
| 生成方式 | `save_deliverable_attachment` 参数 |
|
||||
|----------|--------------------------------------|
|
||||
| workspace 文件(csv/txt/xlsx) | `path="data/workspace/..."` |
|
||||
| 生图/生视频(已有 attachment_id) | `attachment_id="..."` |
|
||||
| `write_xlsx` / 生图等(已有 attachment_id) | `attachment_id="..."` |
|
||||
| workspace 文件(csv/txt 等) | `path="data/workspace/..."` |
|
||||
|
||||
**用户上传的文件不要回传**;那是分析输入,不是生成输出。
|
||||
|
||||
## 工具选择(文本 vs 二进制)
|
||||
## 工具选择(文本 vs Excel vs 二进制)
|
||||
|
||||
| 目标格式 | 用哪个工具 | 说明 |
|
||||
|----------|------------|------|
|
||||
| `.xlsx` Excel | **`write_xlsx`** | 传 sheets/headers/rows;返回 `attachment_id`;**禁止**再用 `run_command`+openpyxl |
|
||||
| `.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`,不要只写 CSV 代替。
|
||||
**不要声称没有 `write_xlsx`。** 用户要真 `.xlsx` 时必须用 `write_xlsx`,不要只写 CSV 代替。
|
||||
|
||||
## 推荐流程
|
||||
|
||||
**Excel(xlsx)— 优先:**
|
||||
|
||||
```text
|
||||
1. write_xlsx(sheets=[...], name="report.xlsx") → 得到 attachment_id
|
||||
2. 若用户要求发文件:save_deliverable_attachment(attachment_id="...")
|
||||
3. 文字回复摘要
|
||||
```
|
||||
|
||||
**文本文件(CSV/TXT):**
|
||||
|
||||
```text
|
||||
|
|
@ -48,14 +56,6 @@ description: "在 WhatsApp/微信等渠道会话中,把生成的附件发回
|
|||
3. 文字回复
|
||||
```
|
||||
|
||||
**Excel(xlsx):**
|
||||
|
||||
```text
|
||||
1. run_command → python 写入 data/workspace/tmp/report.xlsx
|
||||
2. save_deliverable_attachment(path="data/workspace/tmp/report.xlsx", name="report.xlsx")
|
||||
3. 文字回复
|
||||
```
|
||||
|
||||
**图片:**
|
||||
|
||||
```text
|
||||
|
|
@ -70,12 +70,19 @@ description: "在 WhatsApp/微信等渠道会话中,把生成的附件发回
|
|||
用户:帮我把统计结果导出 Excel 发我
|
||||
|
||||
步骤:
|
||||
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")
|
||||
1. write_xlsx:
|
||||
name="summary.xlsx"
|
||||
sheets=[{
|
||||
"name": "汇总",
|
||||
"headers": ["姓名", "数量"],
|
||||
"rows": [["A", 10], ["B", 3]]
|
||||
}]
|
||||
2. save_deliverable_attachment(attachment_id=<上一步返回的 attachment_id>)
|
||||
3. 回复摘要
|
||||
```
|
||||
|
||||
若只需在 workspace 留一份副本(不投递),可额外传 `path="data/workspace/tmp/summary.xlsx"`;**是否发给渠道仍由你决定是否调用 save_deliverable_attachment**。
|
||||
|
||||
## 限制
|
||||
|
||||
- 每轮回复通常只发送**第一个** deliverable 附件(约 8MB 上限)。
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue