跳到正文
Skillpedia
PDF、Word 与幻灯片7.8k · #13014

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/spreadsheet-direct-python-merged/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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 .py files 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':

  1. 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.
  2. 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.
  3. Document assumptions: Clearly note that materials were generated based on standard practices when source verification was unavailable.
  4. Use direct Python execution: Continue with the recommended run_shell pattern 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能