Python: replace pre-commit with prek, add PEP 723 script deps, clean up dev dependencies (#3748)

* python: replace pre-commit with prek, add PEP 723 script deps, clean up dev dependencies

- Replace pre-commit with prek (Rust-native, faster pre-commit alternative)
- Move supported hooks to repo: builtin for zero-clone speed
- Add new builtin hooks: trailing-whitespace, check-merge-conflict, detect-private-key, check-added-large-files
- Update all hook versions to latest (pre-commit-hooks v6, pyupgrade v3.21.2, bandit 1.9.3, uv-pre-commit 0.10.0)
- Add PEP 723 inline script metadata to 34 samples with external deps
- Remove autogen-agentchat/autogen-ext from dev deps (now declared per-sample)
- Remove unused dev deps: pytest-env, tomli-w
- Add agent-framework-core>=1.0.0b260130 lower bound to all 21 packages
- Update CI workflow to use j178/prek-action
- Update docs: DEV_SETUP.md, AGENTS.md, CODING_STANDARD.md, SAMPLE_GUIDELINES.md

* updated lock

* python: fix prek config paths for local execution and CI workflow

Remove global 'files: ^python/' filter and strip python/ prefix from all path patterns in .pre-commit-config.yaml so prek finds files when run from the python/ directory. Update CI workflow to use --cd python instead of --config path. Include trailing whitespace fixes and dev dependency cleanup.

* python: move helper scripts to scripts/ folder and exclude from checks

* python: exclude AGENTS.md from prek markdown code lint

* python: exclude AGENTS.md and azure_ai_search sample from markdown lint

* fix m365 sample

* python: ignore CPY rule for samples with PEP 723 headers

* fix in dev_setup

* python: replace aiofiles with regular open in samples

* python: suppress reportUnusedImport in markdown code block checker

* python: use samples pyright config for markdown code block checker

Write a temp pyrightconfig.json matching pyrightconfig.samples.json rules (typeCheckingMode=off, only reportMissingImports and reportAttributeAccessIssue). Filter output to only fail on these rules since syntax-level errors (top-level await, undefined vars) are expected in README documentation snippets.

* python: use markdown-code-lint with fixed globs instead of prek file list

The prek-markdown-code-lint task received all changed files including non-README markdown and files with pre-existing broken imports. Replace with the standard markdown-code-lint task which uses the correct glob patterns (README.md, packages/**/README.md, samples/**/*.md).

* python: exclude READMEs with pre-existing broken imports from markdown lint

* python: fix broken README code snippets instead of excluding them

- ag-ui: replace TextContent (removed) with content.type == 'text'
- durabletask: fix import path to durabletask.worker.TaskHubGrpcWorker
- orchestrations: use constructor params instead of .participants() method
- observability: mark deprecated code blocks as plain text, filter
  reportMissingImports to agent_framework modules only
- remove README excludes from markdown-code-lint task

* add revision to gaia download

* feat(python): parallelize checks across packages

Run (package × task) cross-product in parallel using ThreadPoolExecutor
and subprocesses. Key changes:

- Add scripts/task_runner.py with shared parallel execution engine
- Update run_tasks_in_packages_if_exists.py to accept multiple tasks
- Update run_tasks_in_changed_packages.py with --files flag and parallel support
- Add check-packages poe task (fmt+lint+pyright+mypy in parallel)
- Add prek-markdown-code-lint and prek-samples-check with change detection
- Split CI code quality workflow into parallel prek and mypy jobs
- Update DEV_SETUP.md to document new parallel behavior

Core package changes still trigger checks on all packages.

* feat(ci): split code quality into 4 parallel jobs

Split the single prek job into parallel jobs:
- pre-commit-hooks: lightweight hooks (SKIP=poe-check)
- package-checks: fmt/lint/pyright/mypy via check-packages
- samples-markdown: samples-lint, samples-syntax, markdown-code-lint
- mypy: change-detected mypy checks

All 4 jobs run concurrently (×2 Python versions = 8 runners).

* feat(ci): use only Python 3.10 for code quality checks

* refactor(python): add future annotations and remove quoted types

Add `from __future__ import annotations` to 93 package files that
used quoted string annotations, then run pyupgrade --py310-plus to
remove the now-unnecessary quotes.

Fixes https://github.com/microsoft/agent-framework/issues/3578
This commit is contained in:
Eduard van Valkenburg
2026-02-09 18:51:01 +01:00
committed by GitHub
Unverified
parent ad0dac3c86
commit 977c3adfb2
177 changed files with 1373 additions and 1010 deletions
@@ -5,7 +5,6 @@ import tempfile
from pathlib import Path
from urllib import request as urllib_request
import aiofiles
from agent_framework import HostedImageGenerationTool
from agent_framework.azure import AzureAIProjectAgentProvider
from azure.identity.aio import AzureCliCredential
@@ -89,8 +88,8 @@ async def main() -> None:
if data_bytes is None:
raise RuntimeError("Image output present but could not retrieve bytes.")
async with aiofiles.open(file_path, "wb") as f:
await f.write(data_bytes)
with open(file_path, "wb") as f:
f.write(data_bytes)
print(f"Image downloaded and saved to: {file_path}")
else:
@@ -3,7 +3,6 @@ import asyncio
import json
from pathlib import Path
import aiofiles
from agent_framework.azure import AzureAIProjectAgentProvider
from azure.identity.aio import AzureCliCredential
@@ -23,9 +22,8 @@ async def main() -> None:
# Load the OpenAPI specification
resources_path = Path(__file__).parent.parent / "resources" / "countries.json"
async with aiofiles.open(resources_path, "r") as f:
content = await f.read()
openapi_countries = json.loads(content)
with open(resources_path) as f:
openapi_countries = json.load(f)
async with (
AzureCliCredential() as credential,
@@ -1,3 +1,12 @@
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "microsoft-agents",
# ]
# ///
# Run with any PEP 723 compatible runner, e.g.:
# uv run samples/getting_started/agents/copilotstudio/copilotstudio_with_explicit_settings.py
# Copyright (c) Microsoft. All rights reserved.
import asyncio
@@ -8,7 +8,7 @@ All of these samples are set up to run in Azure Functions. Azure Functions has a
### 1. Install dependencies and create appropriate services
- Install [Azure Functions Core Tools 4.x](https://learn.microsoft.com/azure/azure-functions/functions-run-local?tabs=windows%2Cpython%2Cv2&pivots=programming-language-python#install-the-azure-functions-core-tools)
- Install [Azurite storage emulator](https://learn.microsoft.com/en-us/azure/storage/common/storage-install-azurite?toc=%2Fazure%2Fstorage%2Fblobs%2Ftoc.json&bc=%2Fazure%2Fstorage%2Fblobs%2Fbreadcrumb%2Ftoc.json&tabs=visual-studio%2Cblob-storage)
- Create an [Azure OpenAI](https://azure.microsoft.com/en-us/products/ai-foundry/models/openai) resource. Note the Azure OpenAI endpoint, deployment name, and the key (or ensure you can authenticate with `AzureCliCredential`).
@@ -29,17 +29,17 @@ python -m venv .venv
```bash
python -m venv .venv
source .venv/bin/activate
```
```
### 3. Running the samples
### 3. Running the samples
- [Start the Azurite emulator](https://learn.microsoft.com/en-us/azure/storage/common/storage-install-azurite?tabs=npm%2Cblob-storage#run-azurite)
- Inside each sample:
- Inside each sample:
- Install Python dependencies from the sample directory, run `pip install -r requirements.txt` (or the equivalent in your active virtual environment).
- Copy `local.settings.json.template` to `local.settings.json`, then update `AZURE_OPENAI_ENDPOINT` and `AZURE_OPENAI_CHAT_DEPLOYMENT_NAME` for Azure OpenAI authentication. The samples use `AzureCliCredential` by default, so ensure you're logged in via `az login`.
- Copy `local.settings.json.template` to `local.settings.json`, then update `AZURE_OPENAI_ENDPOINT` and `AZURE_OPENAI_CHAT_DEPLOYMENT_NAME` for Azure OpenAI authentication. The samples use `AzureCliCredential` by default, so ensure you're logged in via `az login`.
- Alternatively, you can use API key authentication by setting `AZURE_OPENAI_API_KEY` and updating the code to use `AzureOpenAIChatClient()` without the credential parameter.
- Keep `TASKHUB_NAME` set to `default` unless you plan to change the durable task hub name.
@@ -31,7 +31,7 @@ A focused sample demonstrating Azure AI's RedTeam functionality to assess the sa
### Python Environment
```bash
pip install agent-framework azure-ai-evaluation pyrit duckdb azure-identity aiofiles
pip install agent-framework azure-ai-evaluation pyrit duckdb azure-identity
```
Note: The sample uses `python-dotenv` to load environment variables from a `.env` file.
@@ -23,7 +23,7 @@ Prerequisites:
- Environment variables set in .env file or environment
Installation:
pip install agent-framework azure-ai-evaluation pyrit duckdb azure-identity aiofiles
pip install agent-framework azure-ai-evaluation pyrit duckdb azure-identity
Reference:
Azure AI Red Teaming: https://github.com/Azure-Samples/azureai-samples/blob/main/scenarios/evaluate/AI_RedTeaming/AI_RedTeaming.ipynb
@@ -1,3 +1,12 @@
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "pandas",
# ]
# ///
# Run with any PEP 723 compatible runner, e.g.:
# uv run samples/getting_started/evaluation/self_reflection/self_reflection.py
# Copyright (c) Microsoft. All rights reserved.
# type: ignore
import argparse
@@ -273,7 +273,7 @@ If you're updating from a previous version of the Agent Framework, here are the
### OTLP Configuration
**Before (Deprecated):**
```python
```
from agent_framework.observability import setup_observability
# Via parameter
setup_observability(otlp_endpoint="http://localhost:4317")
@@ -305,7 +305,7 @@ configure_otel_providers(exporters=[
### Azure Monitor Configuration
**Before (Deprecated):**
```python
```
from agent_framework.observability import setup_observability
setup_observability(
@@ -341,7 +341,7 @@ enable_instrumentation()
### Console Output
**Before (Deprecated):**
```python
```
from agent_framework.observability import setup_observability
# Console was used as automatic fallback
@@ -1,3 +1,12 @@
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "azure-monitor-opentelemetry",
# ]
# ///
# Run with any PEP 723 compatible runner, e.g.:
# uv run samples/getting_started/observability/agent_with_foundry_tracing.py
# Copyright (c) Microsoft. All rights reserved.
import asyncio
@@ -40,7 +40,7 @@ actions:
- kind: SetValue
path: turn.greeting
value: Hello, World!
- kind: SendActivity
activity:
text: =turn.greeting
@@ -2,7 +2,7 @@
# This workflow demonstrates using multiple agents to provide automated
# troubleshooting steps to resolve common issues with escalation options.
#
# Example input:
# Example input:
# My PC keeps rebooting and I can't use it.
#
kind: Workflow
@@ -12,7 +12,7 @@ trigger:
id: workflow_demo
actions:
# Interact with user until the issue has been resolved or
# Interact with user until the issue has been resolved or
# a determination is made that a ticket is required.
- kind: InvokeAzureAgent
id: service_agent
@@ -23,7 +23,7 @@ trigger:
externalLoop:
when: |-
=Not(Local.ServiceParameters.IsResolved)
And
And
Not(Local.ServiceParameters.NeedsTicket)
output:
responseObject: Local.ServiceParameters
@@ -32,14 +32,14 @@ trigger:
- kind: ConditionGroup
id: check_if_resolved
conditions:
- condition: =Local.ServiceParameters.IsResolved
id: test_if_resolved
actions:
- kind: GotoAction
id: end_when_resolved
actionId: all_done
# Create the ticket.
- kind: InvokeAzureAgent
id: ticket_agent
@@ -103,7 +103,7 @@ trigger:
externalLoop:
when: |-
=Not(Local.SupportParameters.IsResolved)
And
And
Not(Local.SupportParameters.NeedsEscalation)
output:
autoSend: true
@@ -124,7 +124,7 @@ trigger:
- condition: =Local.SupportParameters.IsResolved
id: handle_if_resolved
actions:
- kind: InvokeAzureAgent
id: resolution_agent
agent:
@@ -6,7 +6,6 @@ import os
from collections import defaultdict
from dataclasses import dataclass
import aiofiles
from agent_framework import (
Executor, # Base class for custom workflow steps
WorkflowBuilder, # Fluent builder for executors and edges
@@ -33,13 +32,12 @@ Show how to:
Prerequisites:
- Familiarity with WorkflowBuilder, executors, fan out and fan in edges, events, and streaming runs.
- aiofiles installed for async file I/O.
- Write access to a tmp directory next to this script.
- A source text at resources/long_text.txt.
- Optional for SVG export: install graphviz.
Installation:
pip install agent-framework aiofiles graphviz
pip install agent-framework graphviz
"""
# Define the temporary directory for storing intermediate results
@@ -128,8 +126,8 @@ class Map(Executor):
# Write this mapper's results as simple text lines for easy debugging.
file_path = os.path.join(TEMP_DIR, f"map_results_{self.id}.txt")
async with aiofiles.open(file_path, "w") as f:
await f.writelines([f"{item}: {count}\n" for item, count in results])
with open(file_path, "w") as f:
f.writelines([f"{item}: {count}\n" for item, count in results])
await ctx.send_message(MapCompleted(file_path))
@@ -163,8 +161,8 @@ class Shuffle(Executor):
async def _process_chunk(chunk: list[tuple[str, list[int]]], index: int) -> None:
"""Write one grouped partition for reducer index and notify that reducer."""
file_path = os.path.join(TEMP_DIR, f"shuffle_results_{index}.txt")
async with aiofiles.open(file_path, "w") as f:
await f.writelines([f"{key}: {value}\n" for key, value in chunk])
with open(file_path, "w") as f:
f.writelines([f"{key}: {value}\n" for key, value in chunk])
await ctx.send_message(ShuffleCompleted(file_path, self._reducer_ids[index]))
tasks = [asyncio.create_task(_process_chunk(chunk, i)) for i, chunk in enumerate(chunks)]
@@ -179,9 +177,9 @@ class Shuffle(Executor):
# Load all intermediate pairs.
map_results: list[tuple[str, int]] = []
for result in data:
async with aiofiles.open(result.file_path, "r") as f:
with open(result.file_path) as f:
map_results.extend([
(line.strip().split(": ")[0], int(line.strip().split(": ")[1])) for line in await f.readlines()
(line.strip().split(": ")[0], int(line.strip().split(": ")[1])) for line in f.readlines()
])
# Group values by token.
@@ -230,8 +228,8 @@ class Reduce(Executor):
return
# Read grouped values from the shuffle output.
async with aiofiles.open(data.file_path, "r") as f:
lines = await f.readlines()
with open(data.file_path) as f:
lines = f.readlines()
# Sum values per key. Values are serialized Python lists like [1, 1, ...].
reduced_results: dict[str, int] = defaultdict(int)
@@ -241,8 +239,8 @@ class Reduce(Executor):
# Persist our partition totals.
file_path = os.path.join(TEMP_DIR, f"reduced_results_{self.id}.txt")
async with aiofiles.open(file_path, "w") as f:
await f.writelines([f"{key}: {value}\n" for key, value in reduced_results.items()])
with open(file_path, "w") as f:
f.writelines([f"{key}: {value}\n" for key, value in reduced_results.items()])
await ctx.send_message(ReduceCompleted(file_path))
@@ -324,8 +322,8 @@ async def main():
print("Tip: Install 'viz' extra to export workflow visualization: pip install agent-framework[viz] --pre")
# Step 3: Open the text file and read its content.
async with aiofiles.open(os.path.join(DIR, "../resources", "long_text.txt"), "r") as f:
raw_text = await f.read()
with open(os.path.join(DIR, "../resources", "long_text.txt")) as f:
raw_text = f.read()
# Step 4: Run the workflow with the raw text as input.
async for event in workflow.run(raw_text, stream=True):