跳到正文
Skillpedia
通用编程7.8k · #12884

fallback-script-execution

它能做什么

这项技能是一种可重复使用的两步法运行 Python 脚本的方法,能给出更清晰的错误信息。它适合调试那些无法通过常用工具运行的代码的人。

适用场景

  • ✓当辅助智能体在运行代码时反复失败并给出含糊信息的时候。
  • ✓当沙箱对同一段代码超时或报错的时候。
  • ✓当我希望修改并重新运行脚本,而不必每次重写的时候。

技能链接

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/fallback-script-execution/SKILL.md

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“辅助智能体在运行我的脚本时一直失败。请把脚本保存为文件并运行,让我能看到完整的错误。”

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

工作原理

AI 会把一个包含错误处理的独立脚本写入文件,然后用 shell 命令运行它,使完整的堆栈跟踪和输出都可见。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Fallback Script Execution with write_file + run_shell

When to Use This Skill

Use this pattern when:

  • shell_agent fails repeatedly with unclear error messages
  • execute_code_sandbox consistently errors or times out
  • You need better visibility into what's happening during execution
  • Debugging inline code or delegated agents proves difficult

Core Pattern

Instead of delegating execution to an agent or running inline code, use this two-step approach:

  1. Write script to file using write_file
  2. Execute script using run_shell with python script.py

This provides:

  • Clearer error messages (full stack traces visible in run_shell output)
  • Easier debugging (script persists for inspection)
  • Better control over execution environment
  • Ability to modify and re-run without rewriting code

Step-by-Step Instructions

Step 1: Write the Script File

Use write_file to create a self-contained Python script:

write_file with:
  path: "path/to/script_name.py"
  content: |
    #!/usr/bin/env python3
    # Your complete script here
    # Include imports, logic, and error handling

Best Practices:

  • Include descriptive comments
  • Add try/except blocks for error handling
  • Print intermediate results for debugging
  • Use absolute or clear relative paths

Step 2: Execute the Script

Use run_shell to execute the script:

run_shell with:
  command: "python path/to/script_name.py"

Best Practices:

  • Capture and examine full output
  • If errors occur, the script file is still available for inspection
  • You can re-run with modifications without starting over

Example: Data Processing Task

❌ Problematic Approach (shell_agent fails repeatedly)

shell_agent with:
  task: "Load Excel file, calculate correlations, save results"

Result: Agent struggles with path handling, unclear errors

✅ Recommended Approach (write_file + run_shell)

# Step 1: Write script
write_file with:
  path: "correlation_analysis.py"
  content: |
    import pandas as pd
    import sys
    
    try:
        # Load data
        df = pd.read_excel('data.xlsx', sheet_name='Returns')
        print(f"Loaded {len(df)} rows")
        
        # Calculate correlation
        corr = df.corr()
        print(f"Correlation matrix shape: {corr.shape}")
        
        # Save results
        with pd.ExcelWriter('output.xlsx') as writer:
            df.to_excel(writer, sheet_name='Returns')
            corr.to_excel(writer, sheet_name='Correlation')
        
        print("SUCCESS: output.xlsx created")
    except Exception as e:
        print(f"ERROR: {type(e).__name__}: {e}", file=sys.stderr)
        sys.exit(1)

# Step 2: Execute script
run_shell with:
  command: "python correlation_analysis.py"

Debugging Tips

  1. Add print statements at key points to trace execution
  2. Check file paths - use run_shell with ls -la path/ to verify files exist
  3. Inspect errors - run_shell output shows full Python stack traces
  4. Modify and re-run - edit the script file and execute again without rewriting

When to Escalate

If this pattern also fails:

  • Verify Python is available: run_shell with which python or python --version
  • Check file permissions: run_shell with ls -la script.py
  • Try explicit Python path: run_shell with /usr/bin/python script.py
  • Consider task complexity - may need to break into smaller scripts
常见问题

为什么文件更利于调试?

脚本保存在磁盘上,修改后可以检查并再次运行。

什么让错误输出更清晰?

完整的堆栈跟踪会显示在 shell 输出中,而不是被隐藏。

脚本应包含什么?

导入、主要逻辑、try 和 except 代码块,以及打印的进度信息。

详情

作者的原始描述

Two-step script execution workflow for debugging when shell_agent and execute_code_sandbox consistently fail

repo: HKUDS/AgentPilot

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能