document-gen-resilient-workflow
它能做什么
这项技能指导 AI 制作 Word、PDF 或 HTML 等文档,并在工具出错时提供备用方案。它适合需要可靠文档的人,尤其是包含特殊字符的文档。
适用场景
- ✓当 PDF 制作因缺少 LaTeX 或编码错误而失败的时候。
- ✓当同一份内容需要以多种格式输出的时候。
- ✓当文本中的符号或非英文字符导致转换出错的时候。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/document-gen-fallback-enhanced-enhanced-2794b4/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我需要把我的笔记转换成 Word 文件和 PDF 文件,并且要确保带重音符号的字符能正确显示。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会先用 Markdown 撰写内容,必要时清理特殊字符,然后依次尝试各个 PDF 引擎,直到有一个成功,并检查输出文件是否有效。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Resilient Document Generation Workflow (Multi-Engine Fallback)
When to Use
Use this skill when document generation tasks fail or when shell_agent returns unknown errors, especially for:
- Generating documents in multiple formats (
.docx,.pdf,.html) - PDF generation fails due to missing LaTeX, encoding issues, or tool errors
- Documents contain special characters, symbols, or non-ASCII text
- You need maximum reliability with automatic fallback options
Core Technique
Split document generation into discrete, observable steps with cascading fallbacks for PDF generation:
- Content creation → Use
write_fileto create source Markdown - Unicode sanitization → Use Python script for reliable character replacement
- Format conversion → Try multiple PDF engines in sequence until one succeeds
- Verification → Check file exists, has non-zero size, and is valid
⚠️ Unicode & PDF Engine Guide
Different PDF engines have different Unicode support:
| Engine | Unicode Support | Best For | Fallback Position |
|---|---|---|---|
pdflatex |
Limited (ASCII-focused) | Simple documents | 1st (fastest) |
xelatex |
Full Unicode | Documents with non-ASCII | 2nd |
wkhtmltopdf |
Good Unicode | Web-style documents | 3rd |
reportlab (Python) |
Full control | Programmatic PDFs | 4th |
fpdf2 (Python) |
Full control | Simple text PDFs | 5th (last resort) |
Character Replacement Table
| Character | Issue | Safe Replacement |
|---|---|---|
— (em dash) |
LaTeX incompatibility | -- |
– (en dash) |
LaTeX incompatibility | - |
" " (curly quotes) |
Encoding errors | " " (straight) |
' ' (curly apostrophe) |
Encoding errors | ' (straight) |
… (ellipsis) |
May not render | ... |
→ ← ↑ ↓ |
LaTeX incompatibility | -> <- ^ v |
✓ ✗ |
May not render | [x] [ ] |
★ ● |
May not render | * - |
© ® ™ |
May require packages | (c) (r) (tm) |
é ñ ü |
Font-dependent | Keep for xelatex, replace for pdflatex |
Step-by-Step Workflow
Step 1: Create Source Content with write_file
Write your document content as Markdown to a source file:
write_file
path: /tmp/document_source.md
content: |
# Document Title
## Section 1
Content here...
## Section 2
More content...
Step 2: Sanitize Unicode with Python Script
Create a reusable Python sanitizer for reliable character replacement:
write_file
path: /tmp/sanitize_unicode.py
content: |
#!/usr/bin/env python3
import sys
import re
if len(sys.argv) < 2:
print("Usage: sanitize_unicode.py <input.md> [output.md]")
sys.exit(1)
input_file = sys.argv[1]
output_file = sys.argv[2] if len(sys.argv) > 2 else input_file.replace('.md', '_sanitized.md')
replacements = {
'—': '--', # em dash
'–': '-', # en dash
'"': '"', # left curly quote
'"': '"', # right curly quote
"'": "'", # left curly apostrophe
"'": "'", # right curly apostrophe
'…': '...', # ellipsis
'→': '->', # right arrow
'←': '<-', # left arrow
'↑': '^', # up arrow
'↓': 'v', # down arrow
'✓': '[x]', # checkmark
'✗': '[ ]', # cross
'★': '*', # star
'●': '-', # bullet
'©': '(c)', # copyright
'®': '(r)', # registered
'™': '(tm)', # trademark
}
with open(input_file, 'r', encoding='utf-8') as f:
content = f.read()
for old, new in replacements.items():
content = content.replace(old, new)
with open(output_file, 'w', encoding='utf-8') as f:
f.write(content)
print(f"Sanitized: {input_file} -> {output_file}")
Apply sanitization for PDF:
run_shell
command: python3 /tmp/sanitize_unicode.py /tmp/document_source.md /tmp/document_source_sanitized.md
Note: Keep original for DOCX/HTML (these formats handle Unicode well).
Step 3: Convert to Target Formats with Cascading Fallbacks
For DOCX (from original, no sanitization needed):
run_shell
command: pandoc /tmp/document_source.md -o output.docx
For PDF (try multiple engines in sequence):
Attempt 1: pdflatex (fastest, limited Unicode)
run_shell
command: pandoc /tmp/document_source_sanitized.md -o output.pdf --pdf-engine=pdflatex
*If pdflatex fails, Attempt 2: xelatex (full Unicode)
常见问题
它会尝试哪些 PDF 引擎?
指南按固定顺序列出了 pdflatex、xelatex、wkhtmltopdf、reportlab 和 fpdf2 作为选项。
为什么 Unicode 支持很重要?
有些 PDF 引擎处理非 ASCII 字符的能力较差,因此指南说明了应使用哪个引擎。
它会检查结果吗?
会。指南要求确认文件存在、有内容且有效。
详情
作者的原始描述
Multi-engine document generation with cascading PDF fallbacks and robust Unicode handling
repo: HKUDS/AgentPilot
热度
- GitHub 星标
- 7.8k
- 排名
- #12856
- 许可证
- 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帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。