document-python-direct-exec
它能做什么
这项技能让智能体直接运行 Python,完成表格、PDF 和文档任务。适合文档任务在 shell 智能体中遇到步数限制或错误不清楚的人。
适用场景
- ✓当文档任务需要很多步骤,可能超出 shell 智能体步数限制的时候。
- ✓当你需要对版式有精确控制的 PDF 清单、报告或表单时。
- ✓当你希望立即看到清楚的错误信息的时候。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/spreadsheet-direct-python-merged-343937/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“帮我为新员工入职做一份 PDF 清单和一个 Excel 跟踪表。请直接运行 Python,这样如果出错,我能看到清楚的提示。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体把 Python 脚本写入文件,然后在一个 shell 步骤中运行它。由于不受 shell 智能体的迭代限制,脚本可以一次完成整个任务,并立即显示错误。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Direct Python Execution for Spreadsheet and Document Tasks
When to Use This Skill
Use direct run_shell with Python scripts for structured document operations when:
- Spreadsheets: Reading or writing complex Excel files with multiple sheets, applying formulas, formatting, or data transformations
- PDFs: Generating PDF checklists, reports, invoices, or forms with precise layout control
- Documents: Creating Word documents, HTML reports, or other structured output formats
- Complex Operations: The task involves multiple steps that could exceed agent step limits
- Precision Needed: You need precise control over error handling, debugging, and library imports
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 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
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 > process_document.py << 'EOF'
# Your document/spreadsheet code here
EOF
# Step 2: Execute the script
python3 process_document.py
Alternative Pattern: Inline Heredoc (Simple Scripts Only)
For short, simple scripts when NOT using shell_agent as the executor:
python3 << 'EOF'
# Your code here
EOF
Spreadsheet Examples
Example 1: Read and Transform Excel Data
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')
Example 3: Complex Formatting Operations
from openpyxl import load_workbook
from openpyxl.styles import Font, PatternFill, Alignment
wb = load_workbook('report.xlsx')
ws = wb.active
# Apply header styling
header_fill = PatternFill(start_color='4472C4', fill_type='solid')
header_font = Font(bold=True, color='FFFFFF')
for cell in ws[1]:
cell.fill = header_fill
cell.font = header_font
cell.alignment = Alignment(horizontal='center')
wb.save('report_formatted.xlsx')
PDF Generation Examples
Example 4: Generate PDF Checklist with ReportLab
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
from reportlab.lib.units import inch
def create_checklist(pdf_path, items):
c = canvas.Canvas(pdf_path, pagesize=letter)
width, height = letter
# Title
c.setFont("Helvetica-Bold", 16)
c.drawString(1*inch, height - 1*inch, "Safety Checklist")
# Checklist items
c.setFont("Helvetica", 12)
y_position = height - 1.5*inch
for i, item in enumerate(items, 1):
checkbox_x = 1*inch
text_x = 1.3*inch
c.drawString(checkbox_x, y_position, "☐") # Empty checkbox
c.drawString(text_x, y_position, f"{i}. {item}")
y_position -= 0.3*inch
# New page if needed
if y_position < 1*inch:
c.showPage()
y_position = height - 1*inch
c.save()
print(f"Created checklist: {pdf_path}")
# Usage
items = [
"Verify equipment is powered off",
"Check safety gear is available",
"Inspect work area for hazards",
"Confirm emergency contacts are posted"
]
create_checklist('safety_checklist.pdf', items)
Example 5: Generate PDF Report with Tables
from reportlab.lib import colors
from reportlab.lib.pagesizes import letter
from reportlab.
常见问题
它涵盖哪些文件类型?
技能列出了表格、PDF 清单、报告,以及 Word 或 HTML 文档。
为什么这里要避开 shell 智能体?
技能指出,shell 智能体可能达到步数上限,或在解析 heredoc 时失败。
智能体还会检查输出吗?
会的,技能要求智能体阅读打印的输出,以确认任务成功。
详情
作者的原始描述
Use direct Python execution for reliable spreadsheet and document/PDF generation operations
repo: HKUDS/AgentPilot
热度
- GitHub 星标
- 7.8k
- 排名
- #13012
- 许可证
- 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帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。