document-direct-python
它能做什么
这项技能指导智能体通过直接运行 Python,制作 Excel 工作簿、PDF 报告和表单等文件。适合需要快速完成这些文件、又不想受 shell 智能体拖累的人。
适用场景
- ✓当你需要用 Python 制作 PDF 文档、清单或报告的时候。
- ✓当文档任务包含多个步骤,可能超出智能体限制的时候。
- ✓当 shell 智能体在格式设置或读取工作簿时失败的时候。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/spreadsheet-direct-python-merged/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“根据我的数据,用 reportlab 制作一份 PDF 报告,用 openpyxl 制作一个 Excel 工作簿。请直接运行代码。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体把 Python 代码写入文件,并通过 shell 用 python3 运行。代码使用文档库生成文件,智能体检查打印出的输出是否有错误。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Direct Python Execution for Document Generation Tasks
When to Use This Skill
Use direct run_shell with Python scripts for document operations when:
- Reading or writing complex Excel files with multiple sheets
- Generating PDF documents, checklists, or reports
- Applying formulas, formatting, or data transformations
- Working with
openpyxl,pandas,reportlab,FPDF, or similar libraries - The operation involves multiple steps that could exceed agent step limits
- You need precise control over error handling and debugging
- Complex scripts benefit from file-based execution for better reliability
Why Direct Execution?
The shell_agent tool can:
- Hit maximum step limits on complex multi-step operations
- Produce unexplained errors on formatting operations
- Fail on intricate document reads/writes due to iterative parsing
- Fail to parse heredoc syntax correctly, causing 'unknown error' failures
Direct run_shell with Python is more reliable because it:
- Executes in a single step with no iteration limits
- Provides clearer, immediate error messages
- Handles complex operations without step constraints
- Gives full control over library imports and execution flow
- Writing scripts to
.pyfiles first avoids shell_agent parsing issues with heredocs
How to Use
Handling Web Research Failures
When web research tools (search_web, read_webpage) fail or return 'unknown error':
- Assess what you need: Determine if the information is from well-documented regulatory frameworks, standards, or common knowledge that you can provide from internal knowledge.
- Proceed with available knowledge: For pharmacy compliance, OSHA standards, GDPR requirements, and similar well-established frameworks, generate documents using your training knowledge rather than waiting for web access.
- Document assumptions: Clearly note that materials were generated based on standard practices when source verification was unavailable.
- Use direct Python execution: Continue with the recommended
run_shellpattern to generate documents even without web-sourced content.
Example contingency workflow for pharmacy compliance:
# When web research fails, proceed with established regulatory knowledge
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
checklist_items = [
"Verify pharmacist license is current and displayed",
"Maintain controlled substance inventory logs",
"Ensure proper storage temperatures for medications",
"Keep patient counseling records for controlled substances",
"Display required pharmacy signage and notices"
]
# Generate PDF using these standard compliance items
This approach was successfully used in task 045aba2e-4093-42aa-ab7f-159cc538278c_phase2 where all web tools failed but pharmacy compliance PDFs were still created successfully.
Recommended Pattern: Write Script to File First
For complex multi-line scripts, especially when using shell_agent as executor:
# Step 1: Write the Python script to a file
cat > generate_document.py << 'EOF'
import openpyxl
from openpyxl import Workbook
# Your document code here
wb = openpyxl.load_workbook('file.xlsx')
# ... operations ...
wb.save('output.xlsx')
print('Success')
EOF
# Step 2: Execute the script
python3 generate_document.py
Alternative Pattern: Inline Heredoc (Simple Scripts Only)
For short, simple scripts when NOT using shell_agent as the executor:
python3 << 'EOF'
import pandas as pd
df = pd.read_excel('input.xlsx')
df.to_excel('output.xlsx', index=False)
print('Done')
EOF
Spreadsheet Examples
Example 1: Read and Transform Excel Data
Write to file first, then execute:
import pandas as pd
# Load data from specific sheet
df = pd.read_excel('input.xlsx', sheet_name='Revenue')
# Apply transformations
df['Net_Revenue'] = df['Gross_Revenue'] * (1 - df['Tax_Rate'])
# Save results
df.to_excel('output.xlsx', index=False, sheet_name='Processed')
Example 2: Multi-Sheet Operations with openpyxl
from openpyxl import load_workbook
wb = load_workbook('tour_data.xlsx')
# Iterate through sheets
for sheet_name in wb.sheetnames:
ws = wb[sheet_name]
# Apply formatting or calculations
for row in ws.iter_rows(min_row=2, max_col=5):
# Process cells
pass
wb.save('tour_data_processed.xlsx')
PDF Generation Examples
Example 3: Generate PDF Checklist with reportla
常见问题
直接运行的主要好处是什么?
技能指出,它可以一步执行完成,并立即给出清楚的错误信息。
它能处理 Word 文件吗?
技能把 Word 文档列为支持的输出类型之一。
智能体是否总是先使用文件?
对于复杂的多行代码,技能建议先把脚本写入文件。
详情
作者的原始描述
Use direct Python execution for reliable document creation including spreadsheets, PDFs, and structured reports
repo: HKUDS/AgentPilot
热度
- GitHub 星标
- 7.8k
- 排名
- #13014
- 许可证
- 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帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。