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
+1 -2
View File
@@ -40,7 +40,6 @@ add_agent_framework_fastapi_endpoint(app, agent, "/")
```python
import asyncio
from agent_framework import TextContent
from agent_framework.ag_ui import AGUIChatClient
async def main():
@@ -48,7 +47,7 @@ async def main():
# Stream responses
async for update in client.get_response("Hello!", stream=True):
for content in update.contents:
if isinstance(content, TextContent):
if content.type == "text" and content.text:
print(content.text, end="", flush=True)
print()
@@ -2,6 +2,8 @@
"""AG-UI Chat Client implementation."""
from __future__ import annotations
import json
import logging
import sys
@@ -216,7 +218,7 @@ class AGUIChatClient(
http_client: httpx.AsyncClient | None = None,
timeout: float = 60.0,
additional_properties: dict[str, Any] | None = None,
middleware: Sequence["ChatAndFunctionMiddlewareTypes"] | None = None,
middleware: Sequence[ChatAndFunctionMiddlewareTypes] | None = None,
function_invocation_configuration: FunctionInvocationConfiguration | None = None,
**kwargs: Any,
) -> None:
@@ -2,6 +2,8 @@
"""FastAPI endpoint creation for AG-UI agents."""
from __future__ import annotations
import copy
import logging
from collections.abc import AsyncGenerator, Sequence
@@ -77,7 +79,7 @@ def add_agent_framework_fastapi_endpoint(
)
logger.info(f"Received request at {path}: {input_data.get('run_id', 'no-run-id')}")
async def event_generator() -> AsyncGenerator[str, None]:
async def event_generator() -> AsyncGenerator[str]:
encoder = EventEncoder()
event_count = 0
async for event in wrapped_agent.run_agent(input_data):
@@ -2,6 +2,8 @@
"""Event converter for AG-UI protocol events to Agent Framework types."""
from __future__ import annotations
from typing import Any
from agent_framework import (
@@ -2,6 +2,8 @@
"""HTTP service for AG-UI protocol communication."""
from __future__ import annotations
import json
import logging
from collections.abc import AsyncIterable
@@ -148,7 +150,7 @@ class AGUIHttpService:
if self._owns_client and self.http_client:
await self.http_client.aclose()
async def __aenter__(self) -> "AGUIHttpService":
async def __aenter__(self) -> AGUIHttpService:
"""Enter async context manager."""
return self
@@ -2,6 +2,8 @@
"""Message format conversion between AG-UI and Agent Framework."""
from __future__ import annotations
import json
import logging
from typing import Any, cast
@@ -6,6 +6,8 @@ Most orchestration helpers have been moved inline to _run.py.
This module retains utilities that may be useful for testing or extensions.
"""
from __future__ import annotations
import json
import logging
from typing import Any
@@ -2,6 +2,8 @@
"""Predictive state handling utilities."""
from __future__ import annotations
import json
import logging
import re
@@ -2,6 +2,8 @@
"""Tool handling helpers."""
from __future__ import annotations
import logging
from typing import TYPE_CHECKING, Any
@@ -29,7 +31,7 @@ def _collect_mcp_tool_functions(mcp_tools: list[Any]) -> list[Any]:
return functions
def collect_server_tools(agent: "SupportsAgentRun") -> list[Any]:
def collect_server_tools(agent: SupportsAgentRun) -> list[Any]:
"""Collect server tools from an agent.
This includes both regular tools from default_options and MCP tools.
@@ -64,7 +66,7 @@ def collect_server_tools(agent: "SupportsAgentRun") -> list[Any]:
return server_tools
def register_additional_client_tools(agent: "SupportsAgentRun", client_tools: list[Any] | None) -> None:
def register_additional_client_tools(agent: SupportsAgentRun, client_tools: list[Any] | None) -> None:
"""Register client tools as additional declaration-only tools to avoid server execution.
Args:
@@ -2,6 +2,8 @@
"""Simplified AG-UI orchestration - single linear flow."""
from __future__ import annotations
import json
import logging
import uuid
@@ -742,8 +744,8 @@ def _build_messages_snapshot(
async def run_agent_stream(
input_data: dict[str, Any],
agent: SupportsAgentRun,
config: "AgentConfig",
) -> "AsyncGenerator[BaseEvent, None]":
config: AgentConfig,
) -> AsyncGenerator[BaseEvent]:
"""Run agent and yield AG-UI events.
This is the single entry point for all AG-UI agent runs. It follows a simple
@@ -2,6 +2,8 @@
"""Utility functions for AG-UI integration."""
from __future__ import annotations
import copy
import json
import uuid
@@ -2,6 +2,8 @@
"""Example agent demonstrating predictive state updates with document writing."""
from __future__ import annotations
from agent_framework import ChatAgent, ChatClientProtocol, tool
from agent_framework.ag_ui import AgentFrameworkAgent
@@ -2,6 +2,8 @@
"""Recipe agent example demonstrating shared state management (Feature 3)."""
from __future__ import annotations
from enum import Enum
from typing import Any
@@ -2,6 +2,8 @@
"""Task steps agent demonstrating agentic generative UI (Feature 6)."""
from __future__ import annotations
import asyncio
from collections.abc import AsyncGenerator
from enum import Enum
@@ -128,7 +130,7 @@ class TaskStepsAgentWithExecution:
"""Delegate all other attribute access to base agent."""
return getattr(self._base_agent, name)
async def run_agent(self, input_data: dict[str, Any]) -> AsyncGenerator[Any, None]:
async def run_agent(self, input_data: dict[str, Any]) -> AsyncGenerator[Any]:
"""Run the agent and then simulate step execution."""
import logging
import uuid
@@ -2,6 +2,8 @@
"""Example agent demonstrating Tool-based Generative UI (Feature 5)."""
from __future__ import annotations
import sys
from typing import TYPE_CHECKING, Any, TypedDict
@@ -2,6 +2,8 @@
"""Weather agent example demonstrating backend tool rendering."""
from __future__ import annotations
from typing import Any
from agent_framework import ChatAgent, ChatClientProtocol, tool
@@ -2,6 +2,8 @@
"""Example FastAPI server with AG-UI endpoints."""
from __future__ import annotations
import logging
import os
from typing import cast
@@ -292,7 +292,6 @@ Create a file named `client.py`:
import asyncio
import os
from agent_framework import TextContent
from agent_framework.ag_ui import AGUIChatClient
@@ -333,7 +332,7 @@ async def main():
# Stream text content as it arrives
for content in update.contents:
if isinstance(content, TextContent) and content.text:
if content.type == "text" and content.text:
print(content.text, end="", flush=True)
print() # New line after response
@@ -9,6 +9,8 @@ This example demonstrates advanced AGUIChatClient features including:
- Error handling
"""
from __future__ import annotations
import asyncio
import os
from typing import cast
@@ -18,6 +18,8 @@ This demonstrates the HYBRID pattern matching .NET AGUIClient implementation:
This matches .NET pattern: thread maintains state, tools execute on appropriate side.
"""
from __future__ import annotations
import asyncio
import logging
import os
@@ -2,6 +2,8 @@
"""AG-UI server example with server-side tools."""
from __future__ import annotations
import logging
import os
+1 -1
View File
@@ -22,7 +22,7 @@ classifiers = [
"Typing :: Typed",
]
dependencies = [
"agent-framework-core",
"agent-framework-core>=1.0.0b260130",
"ag-ui-protocol>=0.1.9",
"fastapi>=0.115.0",
"uvicorn>=0.30.0"