Files
awesome-copilot/cookbook/copilot-sdk/python/recipe
Anthony Shaw d8fc473383 Add RALPH-loop recipe to Copilot SDK cookbook
Add iterative RALPH-loop (Read, Act, Log, Persist, Halt) pattern
implementations for all four supported languages:

- C#/.NET: ralph-loop.cs with documentation
- Node.js/TypeScript: ralph-loop.ts with documentation
- Python: ralph_loop.py with documentation (async API)
- Go: ralph-loop.go with documentation

Each recipe demonstrates:
- Self-referential iteration where AI reviews its own output
- Completion promise detection to halt the loop
- Max iteration safety limits
- File persistence between iterations

Verified against real Copilot SDK APIs:
- Python: fully verified end-to-end with github-copilot-sdk
- Node.js: fully verified end-to-end with @github/copilot-sdk
- C#: compiles and runs successfully with GitHub.Copilot.SDK
- Go: compiles against github.com/github/copilot-sdk/go v0.1.23
2026-02-11 04:59:20 -08:00
..

Runnable Recipe Examples

This folder contains standalone, executable Python examples for each cookbook recipe. Each file can be run directly as a Python script.

Prerequisites

  • Python 3.8 or later
  • Install dependencies (this installs the SDK from PyPI):
pip install -r requirements.txt

Running Examples

Each .py file is a complete, runnable program with executable permissions:

python <filename>.py
# or on Unix-like systems:
./<filename>.py

Available Recipes

Recipe Command Description
Error Handling python error_handling.py Demonstrates error handling patterns
Multiple Sessions python multiple_sessions.py Manages multiple independent conversations
Managing Local Files python managing_local_files.py Organizes files using AI grouping
PR Visualization python pr_visualization.py Generates PR age charts
Persisting Sessions python persisting_sessions.py Save and resume sessions across restarts

Examples with Arguments

PR Visualization with specific repo:

python pr_visualization.py --repo github/copilot-sdk

Managing Local Files (edit the file to change target folder):

# Edit the target_folder variable in managing_local_files.py first
python managing_local_files.py

Local SDK Development

The requirements.txt installs the Copilot SDK package from PyPI. This means:

  • You get the latest stable release of the SDK
  • No need to build from source
  • Perfect for using the SDK in your projects

If you want to use a local development version, edit requirements.txt to use -e ../.. for editable mode development.

Python Best Practices

These examples follow Python conventions:

  • PEP 8 naming (snake_case for functions and variables)
  • Shebang line for direct execution
  • Proper exception handling
  • Type hints where appropriate
  • Standard library usage

For isolated development:

# Create virtual environment
python -m venv venv

# Activate it
# Windows:
venv\Scripts\activate
# Unix/macOS:
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

Learning Resources