python-debug-execution
できること
このスキルは、AIエージェントがPythonのコードを、分かりやすいエラーの出力とともに実行してデバッグする単純な方法を説明します。AIを通してPythonのスクリプトを実行する人向けです。
使う場面
- ✓Pythonのスクリプトが止まり、理由が分からないとき。
- ✓スクリプト内のファイル操作が失敗し、フォルダが間違っているかもしれないとき。
- ✓AIにフォルダの内容を一覧にさせ、ファイルが正しい場所にあるかを確認させたいとき。
スキルのリンク
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/python-debug-execution/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“スクリプトがファイルのパスで失敗し続けています。デバッグを手伝ってください。また、どのフォルダで実行されているかも見せてください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは、エラーの出力を取り込んでスクリプトを実行し、終了コードを表示します。スクリプトが読み書きする前に、作業ディレクトリとその中のファイルを表示する確認を加えます。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Python Debug Execution Pattern
When executing Python scripts that may fail, use this pattern to surface clear error information and diagnose issues effectively.
Core Technique
1. Execute with Full Error Output
Always run Python scripts with stderr redirected to stdout and echo the exit code:
python3 script.py 2>&1 ; echo Exit code: $?
Why this works:
2>&1captures both stdout and stderr, ensuring tracebacks are visibleecho Exit code: $?reveals the actual exit status for debugging- Avoids opaque "command failed" errors that hide the real cause
2. Verify Working Directory in Script
Before any file operations in Python scripts, add working directory verification:
import os
# At the start of your script or before file operations
print(f"Current working directory: {os.getcwd()}")
# For debugging, also list directory contents
print(f"Directory contents: {os.listdir('.')}")
Why this works:
- File not found errors often stem from incorrect working directory assumptions
- Makes path-related failures immediately diagnosable
- Confirms the execution context matches expectations
Complete Debugging Workflow
Step 1: Add Diagnostic Code to Script
#!/usr/bin/env python3
import os
import sys
def main():
# Diagnostic: verify execution context
print(f"Working directory: {os.getcwd()}")
print(f"Python version: {sys.version}")
print(f"Directory listing: {os.listdir('.')}")
# Your actual logic here
# ...
if __name__ == "__main__":
main()
Step 2: Execute with Full Error Capture
python3 script.py 2>&1 ; echo Exit code: $?
Step 3: Analyze Output
Look for:
- Traceback messages (indicate code errors)
- Exit code (0 = success, non-zero = failure)
- Working directory confirmation
- Missing file/directory errors
Common Failure Patterns
| Symptom | Likely Cause | Debug Clue |
|---|---|---|
| FileNotFoundError | Wrong working directory | Check os.getcwd() output |
| ModuleNotFoundError | Missing dependencies | Traceback shows import path |
| PermissionError | File access issues | Traceback shows file path |
| Silent failure (exit 0, no output) | Logic bug, not crash | Add print statements |
When to Use This Pattern
- Running Python scripts in automated/agent contexts
- Debugging scripts that interact with files
- Troubleshooting CI/CD pipeline failures
- Any scenario where script output may be truncated or hidden
よくある質問
なぜフォルダの内容を一覧にするのですか?
どのファイルがあるかを見ると、ファイルが見つからない理由が分かることが多いからです。
特定の種類のスクリプトだけに使えますか?
いいえ。ファイルを読み書きするどのPythonのスクリプトにも当てはまります。
Pythonを知っている必要がありますか?
いいえ。エージェントがコマンドを扱い、各出力の意味を説明します。
詳細
作者による元の説明
Debug Python scripts with proper error surfacing and working directory verification
repo: HKUDS/AgentPilot
人気
- GitHubのスター
- 7.8k
- ランキング
- #12956
- ライセンス
- MIT
- 更新日
- 2026/11/1
コメント
- …
このリポジトリの他のスキル
agentpilot
7.8kエージェントが、作業を準備し、変更案を提案してテストし、評価するAgentPilotのループを実行することで、プロジェクトを段階的に改善できるよう支援します。
openspace
7.8kエージェントが、スキルを保存し取り出すツールであるOpenSpaceをセットアップし、MCPを通じてAIアプリに接続できるよう支援します。
rsi-arena
7.8kエージェントが、AIMEやTerminal-Benchなどの標準的なAIベンチマークテストをセットアップして実行し、異なる改善方法を比較できるよう支援します。
experiment-guide
7.8kエージェントが、プログラムを改善する方法を調べる間に、小さな実験を計画し、その結果を読み、発見を記録できるよう支援します。
似ているスキル
diffs
394k編集内容の実際の共有可能な差分を、手書きの要約ではなく、ビューアーのリンクや画像ファイルとして作成するようエージェントを支援します。
coding-agent
394kCodex、Claude Code、OpenCodeに大きめのコーディング作業をバックグラウンドのワーカーとして渡し、その進捗を確認するようエージェントを支援します。
gh-issues
394kGitHubのイシューを探し、取り組むものを選び、修正を含むプルリクエストを開くようエージェントを支援します。レビューコメントへの対応も含みます。