Chuyển đến nội dung
Skillpedia
Lập trình chung7.8k · #12884

fallback-script-execution

Skill này làm gì

Skill này là phương pháp lặp lại được để chạy script Python theo hai bước, cho thông báo lỗi rõ hơn. Dành cho người gỡ lỗi code không chạy qua các công cụ thông thường.

Khi nào nên dùng

  • ✓Khi trợ lý agent liên tục thất bại với thông báo không rõ khi chạy code.
  • ✓Khi sandbox hết thời gian hoặc báo lỗi với cùng một code.
  • ✓Khi tôi muốn sửa và chạy lại một script mà không phải viết lại mỗi lần.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/fallback-script-execution/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Trợ lý liên tục thất bại khi chạy script của tôi. Hãy lưu script thành tệp và chạy, để tôi thấy toàn bộ lỗi.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

AI viết một script tự đủ, có xử lý lỗi, vào tệp, rồi chạy bằng lệnh shell để thấy đầy đủ stack trace và đầu ra.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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
Câu hỏi thường gặp

Vì sao tệp tốt hơn khi gỡ lỗi?

Script vẫn nằm trên đĩa, nên có thể kiểm tra và chạy lại sau khi thay đổi.

Điều gì làm thông báo lỗi rõ hơn?

Stack trace đầy đủ xuất hiện trong đầu ra shell thay vì bị ẩn.

Script nên có những gì?

Các import, logic chính, khối try và except, cùng thông báo tiến trình in ra.

Chi tiết

Mô tả gốc của tác giả

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

repo: HKUDS/AgentPilot

Độ phổ biến

Sao GitHub
7.8k
Vị trí xếp hạng
#12884
Giấy phép
MIT
Cập nhật
1/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự