document-gen-dual-backend
它能做什么
这项技能告诉 AI,大多数文档任务直接使用命令完成,只在复杂情况下才保留辅助智能体。它适合需要把 Markdown 制作成 Word、PDF 或 HTML 文件的人。
适用场景
- ✓当我需要把 Markdown 制作成一份简单的 Word、PDF 或 HTML 文档的时候。
- ✓当内容很简单,AI 已经知道该用哪条转换命令的时候。
- ✓当文档任务在出错后需要在不同后端之间自动切换的时候。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/document-gen-fallback-enhanced-enhanced-9f3b1f/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请把这份 Markdown 转换为 PDF 和 Word 文件。保持简单,只有出错时才使用备用方案。”
每周 5 个新技能,1 分钟读完。
工作原理
对于大多数任务,AI 会撰写内容,并直接运行 pandoc 或 ReportLab。对于复杂情况,它会使用两条 PDF 路径,一条用 pandoc,一条用 ReportLab,并检查每个输出结果。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Document Generation: Dual-Backend Workflow (Unicode-Safe)
When to Use
Default Approach: Lightweight Direct Execution (Recommended for 90% of tasks)
For most document generation tasks, use direct write_file + run_shell without shell_agent:
- Generating documents in standard formats (
.docx,.pdf,.html) from Markdown - Content is straightforward with minimal special characters
- You already know the pandoc/ReportLab commands needed
- Quick single-format or multi-format output is needed
Fallback Approach: shell_agent Delegation (For Complex Scenarios Only)
Use shell_agent delegation only when:
- Automated fallback handling between backends requires complex logic
- Dynamic content generation needs programmatic decision-making
- You need to capture and analyze error messages for intelligent retry logic
When shell_agent May Be Useful (Optional)
Only consider shell_agent delegation for:
- Complex error recovery requiring automated backend switching
- Dynamic workflows with conditional branching based on generation results
Core Technique
For simple tasks (default): Use direct write_file + run_shell with pandoc or ReportLab (no shell_agent needed)
For complex tasks requiring fallback logic: Split the workflow into discrete, observable steps with two PDF generation paths:
Path A (Pandoc): Best for Markdown-to-PDF conversion with rich text formatting Path B (ReportLab): Best for programmatic PDF generation without LaTeX dependencies
Workflow steps:
- Content creation → Use
write_fileto create source document (Markdown) - Choose PDF backend → Decide between pandoc (rich formatting) or ReportLab (programmatic control)
- Unicode handling → Apply sanitization for pandoc; ReportLab handles Unicode natively
- Format conversion → Use
run_shellwith appropriate commands for each format - Verification → Check output files exist and are valid
⚠️ Backend Selection Guide
| Requirement | Recommended Backend | Rationale |
|---|---|---|
| Markdown source with headers, lists, tables | Pandoc | Native Markdown parsing |
| Heavy Unicode/special characters | ReportLab | Native UTF-8 support, no sanitization needed |
| LaTeX not available | ReportLab | Pure Python, no external dependencies |
| Precise layout control (positions, graphics) | ReportLab | Programmatic canvas control |
| Quick DOCX + PDF + HTML batch | Pandoc | Single tool, multiple outputs |
| Tables with complex formatting | Pandoc | Better table rendering |
| Dynamic/charts/graphs in PDF | ReportLab | Drawing operations support |
Unicode & LaTeX Compatibility Warning
Critical for Pandoc Path: PDF generation via pandoc typically uses LaTeX (pdflatex or xelatex), which has limited Unicode support. Common problematic characters include:
| Character | Issue | Safe Replacement |
|---|---|---|
— (em dash) |
May not render | -- or - |
– (en dash) |
May not render | - |
" " (curly quotes) |
Encoding errors | " " (straight quotes) |
' ' (curly apostrophe) |
Encoding errors | ' (straight apostrophe) |
… (ellipsis) |
May not render | ... |
→ ← ↑ ↓ (arrows) |
LaTeX incompatibility | -> <- ^ v |
✓ ✗ (checkmarks) |
May not render | [x] [ ] |
★ ● (symbols) |
May not render | * - |
© ® ™ |
May require packages | (c) (r) (tm) |
| Non-ASCII letters (é, ñ, ü) | Font-dependent | Use xeLaTeX or replace |
ReportLab Path: Handles Unicode natively. Pass content as UTF-8 strings; no character sanitization required.
Step-by-Step Workflow
Quick Start: Lightweight Direct Execution (Default for Most Tasks)
This is the recommended approach for most document generation tasks. No shell_agent delegation needed:
# Step 1: Write Markdown content
write_file
path: /tmp/doc.md
content: |
# My Document
Simple content here.
# Step 2: Convert with pandoc (direct)
run_shell
command: pandoc /tmp/doc.md -o output.docx
# Step 3: Verify
run_shell
command: ls -lh output.docx
For PDF with potential Unicode issues:
# Create sanitized version if needed
write_file
path: /tmp/doc_sanitized.md
content: |
# My Document
Content with safe ASCII characters only.
run_shell
command: pandoc /tmp/doc_sanitized.md -o output.pdf
For Unicode-heavy content (use ReportLab directly):
write
常见问题
主要方法是什么?
直接运行命令是默认方法,因为它能满足大多数文档需求。
什么时候需要辅助智能体?
只在需要自动处理错误或在不同后端之间切换的复杂情况下才需要。
它会检查输出吗?
会。指南要求验证每一个生成的文件。
详情
作者的原始描述
Document generation with direct pandoc/ReportLab execution (lightweight default) and optional shell_agent fallback for complex scenarios
repo: HKUDS/AgentPilot
热度
- GitHub 星标
- 7.8k
- 排名
- #12860
- 许可证
- MIT
- 更新时间
- 2026/11/1
评论
- …
同一仓库的更多技能
agentpilot
7.8k帮你的智能体准备任务并运行 AgentPilot 循环,逐步改进项目:循环会提出修改、测试修改并为其打分。
openspace
7.8k帮你的智能体设置 OpenSpace,这是一个用于存储和获取智能体技能的工具,并通过 MCP 将其连接到你的 AI 应用。
rsi-arena
7.8k帮你的智能体设置并运行标准 AI 基准测试,例如 AIME 和 Terminal-Bench,用来比较不同的改进方法。
experiment-guide
7.8k帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。