跳到正文
Skillpedia
分析与电子表格7.8k · #13010

spreadsheet-validated-execution

它能做什么

这项技能指导智能体先检查源数据,再用 openpyxl 或 pandas 运行 Python 处理表格。适合需要处理复杂 Excel 多步任务、并且要仔细检查输入的人。

适用场景

  • ✓当表格任务要读写包含多个工作表的复杂 Excel 文件时。
  • ✓当需要对工作簿应用格式、公式或数据转换的时候。
  • ✓当多步任务可能超出智能体的步数上限,需要保存为脚本的时候。

技能链接

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/spreadsheet-direct-python-enhanced-enhanced/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

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

可以这样问 AI

“请帮我把格式和公式应用到销售工作簿上,但先确认源文件存在且完整。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体先确认源文件可以访问,并且结构符合预期。然后它把 Python 处理代码写成脚本文件并运行;如果主要来源失败,就使用事先指定的备用来源。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Direct Python Execution for Spreadsheet Tasks

When to Use This Skill

Use this skill for spreadsheet operations that require verified source data:

  • Before processing: Verify data sources are accessible and contain expected data
  • Reading or writing complex Excel files with multiple sheets
  • Applying formulas, formatting, or data transformations
  • Working with openpyxl, pandas, 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

Critical: Data Source Validation First

Always validate data availability before attempting spreadsheet operations. This prevents wasted iterations on unavailable data.

Pre-Execution Validation Checklist

  1. Verify source accessibility: Test connection to data URLs/files before building processing scripts
  2. Confirm data format: Ensure source data matches expected structure (columns, sheets, file type)
  3. Check data completeness: Validate required fields/rows are present
  4. Identify fallback sources: Document alternative data sources if primary is unavailable

Validation Script Pattern

import sys
import os
from pathlib import Path

def validate_source(source_path, required_fields=None):
    """Validate data source before processing"""
    if not Path(source_path).exists():
        return False, f"Source file not found: {source_path}"
    
    try:
        # Check file is readable and non-empty
        if os.path.getsize(source_path) == 0:
            return False, "Source file is empty"
        
        if required_fields:
            # Validate structure using pandas
            import pandas as pd
            df = pd.read_excel(source_path, nrows=1)
            missing = set(required_fields) - set(df.columns)
            if missing:
                return False, f"Missing required columns: {missing}"
        
        return True, "Source validated"
    except Exception as e:
        return False, f"Validation error: {str(e)}"

# Usage
valid, message = validate_source('input.xlsx', ['ID', 'Date', 'Value'])
if not valid:
    print(f"ABORT: {message}", file=sys.stderr)
    sys.exit(1)
print(f"OK: {message}")

Handling Inaccessible Data Sources

When primary data sources are unavailable:

  1. Report clearly: Document the specific error (SSL, timeout, file not found)
  2. Attempt fallbacks: Check alternative sources in priority order:
    • Local cached copies of the data
    • Alternative API endpoints or URLs
    • Different file formats from the same source
    • Contact information for data provider
  3. Graceful degradation: If partial data is available, document what's missing
  4. Escalation protocol: For persistent failures, provide:
    • Exact error messages and timestamps
    • URLs/paths that were attempted
    • Workarounds already tried
    • Recommended next steps for human intervention

Example: Multi-Source Fallback Pattern

import sys
from pathlib import Path

sources = [
    'data/wells_current.xlsx',           # Primary: latest data
    'data/wells_backup.xlsx',            # Fallback 1: backup copy
    'data/wells_archive.xlsx',           # Fallback 2: archived version
    '/cached/wells_data.xlsx',           # Fallback 3: system cache
]

selected_source = None
for source in sources:
    if Path(source).exists():
        selected_source = source
        print(f"Using fallback source: {source}")
        break

if not selected_source:
    print("CRITICAL: No data sources available", file=sys.stderr)
    print("Attempted sources:", file=sys.stderr)
    for s in sources:
        print(f"  - {s}", file=sys.stderr)
    sys.exit(1)

# Proceed with selected_source
  • Reading or writing complex Excel files with multiple sheets
  • Applying formulas, formatting, or data transformations
  • Working with openpyxl, pandas, 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 spreadsheet reads/writes due to iterative parsing
  • Fail to parse heredoc syntax correctly,
常见问题

为什么要把任务保存为脚本?

技能指出,对复杂的多步工作来说,保存的脚本文件更可靠。

它使用哪些库?

它把 openpyxl 和 pandas 列为表格处理的主要库。

如果无法访问某个来源怎么办?

智能体会记录失败情况,并在已确定备用来源时使用它。

详情

作者的原始描述

Execute Python scripts with prerequisite data validation and fallback strategies for inaccessible sources

repo: HKUDS/AgentPilot

热度

GitHub 星标
7.8k
排名
#13010
许可证
MIT
更新时间
2026/11/1

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能