Implementation:Microsoft Agent framework Run All Samples Script
| Knowledge Sources | |
|---|---|
| Domains | Testing, CI_CD, Sample_Validation |
| Last Updated | 2026-02-11 17:00 GMT |
Overview
Concurrent sample runner script that discovers and executes all Python sample files in the samples directory, reporting categorized pass/fail results.
Description
The _run_all_samples.py script uses ThreadPoolExecutor to run Python samples in parallel (up to 16 workers by default). Each sample is executed as a subprocess with stdin piped (sending empty input to trigger EOFError for interactive samples) and a 60-second timeout. It classifies failures into four categories: timeout, input_hang, execution_error, and exception. The script supports --direct mode (run without uv), --subdir filtering (run only a subset of samples), and --max-workers configuration.
Usage
Run this script when validating that all Python samples compile and execute without errors, particularly during CI/CD to catch regressions in sample code.
Code Reference
Source Location
- Repository: Microsoft_Agent_framework
- File: python/samples/_run_all_samples.py
- Lines: 1-304
Signature
def find_python_samples(samples_dir: Path, subdir: str | None = None) -> list[Path]:
"""Find all Python sample files in the samples directory or a subdirectory."""
...
def run_sample(
sample_path: Path,
use_uv: bool = True,
python_root: Path | None = None,
) -> tuple[bool, str, str, str]:
"""
Run a single sample file using subprocess.
Args:
sample_path: Path to the sample file
use_uv: Whether to use uv run
python_root: Root directory for uv run
Returns:
Tuple of (success, output, error_info, error_type)
error_type can be: "timeout", "input_hang", "execution_error", "exception"
"""
...
def parse_arguments() -> argparse.Namespace:
"""Parse command line arguments."""
...
def main() -> None:
"""Main function to run all samples concurrently."""
...
Import
# Run via uv (default)
python python/samples/_run_all_samples.py
# Or as a module
uv run python python/samples/_run_all_samples.py
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| --direct | flag | No | Run samples directly with python instead of uv run |
| --subdir | string | No | Run samples only in a specific subdirectory relative to samples/ |
| --max-workers | int | No | Maximum concurrent workers (default: 16) |
Outputs
| Name | Type | Description |
|---|---|---|
| stdout | text | Progress indicators and detailed results for each sample |
| exit code | int | 0 if all samples pass, 1 if any sample fails |
| categorized report | text | Breakdown of failures by type: timeout, input_hang, execution_error, exception |
Usage Examples
Run All Samples
# Run all samples using uv run (concurrent)
python python/samples/_run_all_samples.py
# Run all samples directly (assumes environment is set up)
python python/samples/_run_all_samples.py --direct
# Run samples only in a specific subdirectory
python python/samples/_run_all_samples.py --subdir getting_started/workflows
# Run with custom concurrency
python python/samples/_run_all_samples.py --max-workers 8