fallback-file-creation
它能做什么
这项技能为 AI 提供一种手动的、基于 shell 的方法,用于在代码执行工具持续失败时创建并检查文件。它适合需要可靠地制作特定文件格式的人。
适用场景
- ✓当代码执行或 shell 辅助工具在某个文件任务上多次失败的时候。
- ✓当我需要创建 PDF 或 Word 文件,而常用工具无法使用的时候。
- ✓当我希望每个文件在写入后都得到检查的时候。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/fallback-file-creation/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“代码工具一直在处理我的文件时失败。请检查文件夹,在 shell 中编写脚本,并确认文件确实存在。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会确认工作文件夹,用 shell heredoc 编写脚本,使用明确的路径运行它们,并检查每个输出文件是否存在。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Fallback File Creation Workflow
Use this skill when execute_code_sandbox or shell_agent fails repeatedly for file creation tasks. This pattern provides a manual but reliable approach to create and verify files.
When to Use
- Code execution tools fail after multiple retries
- You need to create specific file formats (PDF, DOCX, etc.)
- Direct shell commands are more reliable than generated scripts
- You need explicit verification of file outputs
Step-by-Step Instructions
Step 1: Verify Working Directory
Before any file operations, confirm your current location:
pwd
ls -la
This ensures you're creating files in the correct workspace directory.
Step 2: Create Scripts via Heredoc
Use shell heredocs to create scripts with properly escaped syntax:
cat > /path/to/script.sh << 'EOF'
#!/bin/bash
# Your script content here
# Variables are NOT expanded inside 'EOF' (quoted)
echo "Creating file..."
# Commands to generate output
EOF
Key escaping rules:
- Use
'EOF'(quoted) to prevent variable expansion inside the heredoc - Use
EOF(unquoted) if you want shell variables to expand - Escape any
$, backticks, or special characters if using unquoted EOF
Step 3: Execute with Explicit Path
Always run scripts with their full or explicit relative path:
chmod +x /path/to/script.sh
/path/to/script.sh
# or
bash /path/to/script.sh
Avoid relying on . or implicit paths.
Step 4: Verify Output
After execution, verify files were created correctly:
# Check file exists and size
ls -lh /path/to/output.file
# For PDFs: inspect metadata
pdfinfo /path/to/output.pdf
# For DOCX: check structure
unzip -l /path/to/output.docx | head -20
# For any file: check content preview
file /path/to/output.file
head -c 500 /path/to/output.file
Step 5: Iterative Debugging
If verification fails:
- Check error messages from script execution
- Verify all dependencies are available (
which command) - Test individual commands from the script manually
- Re-run with verbose output (
bash -x script.sh)
Example: Creating a PDF Document
# Step 1: Verify directory
pwd
ls -la
# Step 2: Create conversion script
cat > /workspace/create_pdf.sh << 'EOF'
#!/bin/bash
cd /workspace
libreoffice --headless --convert-to pdf checklist.odt --outdir .
EOF
# Step 3: Execute
chmod +x /workspace/create_pdf.sh
/workspace/create_pdf.sh
# Step 4: Verify
ls -lh /workspace/checklist.pdf
pdfinfo /workspace/checklist.pdf
Example: Creating a DOCX Document
# Step 1: Verify directory
pwd
ls -la
# Step 2: Create document script
cat > /workspace/create_docx.sh << 'EOF'
#!/bin/bash
cd /workspace
pandoc -f markdown -t docx action_tracker.md -o action_tracker.docx
EOF
# Step 3: Execute
chmod +x /workspace/create_docx.sh
/workspace/create_docx.sh
# Step 4: Verify
ls -lh /workspace/action_tracker.docx
unzip -l /workspace/action_tracker.docx | head -20
Best Practices
- Always verify before and after - Check directory state before starting and after completion
- Use absolute or explicit paths - Avoid ambiguity in file locations
- Quote heredoc delimiters - Use
'EOF'to prevent unwanted variable expansion - Make scripts executable - Always
chmod +xbefore running - Inspect file metadata - Use format-specific tools (pdfinfo, unzip -l, file) to verify content
- Keep scripts simple - Each script should do one thing well
- Clean up temporary files - Remove intermediate files after successful completion
Troubleshooting
| Issue | Solution |
|---|---|
| Script not found | Use full path: /workspace/script.sh |
| Permission denied | Run chmod +x script.sh |
| File not created | Check script output, verify working directory in script |
| Wrong file format | Verify conversion tool supports target format |
| Corrupted output | Re-run with verbose mode, check intermediate files |
常见问题
为什么要用 heredoc?
它让 AI 可以用一条 shell 命令把整个脚本写入文件。
为什么要先检查工作文件夹?
这样可以确保文件被创建在正确的工作区中。
脚本中的变量会被展开吗?
使用带引号的 EOF 标记时不会展开,从而保证脚本文本与所写的完全一致。
详情
作者的原始描述
Fallback pattern for reliable file creation when code execution tools fail
repo: HKUDS/AgentPilot
热度
- GitHub 星标
- 7.8k
- 排名
- #12880
- 许可证
- 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帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。