fallback-file-creation
Fallback pattern for reliable file creation when code execution tools fail
- License 许可
- MIT
- 所属仓库
- HKUDS/AgentPilot
- 最近更新
- 2026-11-12
- Stars
- ★ 8.0k
- Forks
- 944
01 前言 Front Matter
- name
- fallback-file-creation
- description
- Fallback pattern for reliable file creation when code execution tools fail
02 资源文件 1
- 其他.skill_id36 B
03 SKILL.md 正文
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 |
04 同仓库更多 Skills
agentpilot
Set up AgentPilot and use its single entry to prepare missing inputs and run configured RSI experiments. Use when the user requests AgentPilot installation or work with AgentPilot.
remember
Review auto-memory entries and propose promotions to OPENSPACE.md, OPENSPACE.local.md, or retained auto-memory topics; detect duplicates, stale facts, conflicts, and ambiguous entries before making changes.
skill-discovery
Search reusable OpenSpace skills locally, and browse cloud packages step by step when a cloud skill may help. Reusing proven skills saves tokens, improves reliability, and extends your capabilities beyond built-in tools.
delegate-task
Delegate tasks to OpenSpace — a full-stack autonomous worker for coding, DevOps, web research, and desktop automation, backed by an extensive MCP tool and skill library. Skills auto-improve through use, reducing token consumption over time. A cloud community lets agents share and collectively evolve reusable skills.
write-special-chars-ts-check
Workaround for write_file failures caused by special characters (apostrophes, backticks, template literals) using a Python heredoc script, plus a reliable TypeScript type-checking step that filters output to only the newly-written files to avoid being misled by pre-existing errors.
write-special-chars-readback
Workaround for write_file failures caused by special characters (apostrophes, backticks, template literals) using a Python heredoc script, with mandatory post-write verification via read_file and cleanup of /tmp helper scripts.