Python: Add samples syntax checking with pyright#3710
Python: Add samples syntax checking with pyright#3710eavanvalkenburg wants to merge 1 commit intomicrosoft:mainfrom
Conversation
- Add pyrightconfig.samples.json with relaxed type checking but import validation - Add samples-syntax poe task to check samples for syntax and import errors - Add samples-syntax to check and pre-commit-check tasks - Fix 78 sample errors: - Update workflow builder imports to use agent_framework_orchestrations - Change content type isinstance checks to content.type comparisons - Use Content factory methods instead of removed content type classes - Fix TypedDict access patterns for Annotation - Fix various API mismatches (normalize_messages, ChatMessage.text, role)
There was a problem hiding this comment.
Pull request overview
This PR adds syntax checking for Python samples using pyright with a relaxed configuration that validates imports and attribute access without strict type checking. The PR includes the pyright configuration, build task integration, and fixes to 78 sample errors related to import reorganization and API changes.
Changes:
- Added
pyrightconfig.samples.jsonwith relaxed type checking configuration - Added
samples-syntaxpoe task and integrated it intocheckandpre-commit-checkworkflows - Updated samples to import workflow builders from
agent_framework_orchestrationspackage - Changed content type checking from
isinstance()to.typeproperty comparisons - Updated API usage for
normalize_messages,ChatMessage.text,Role,Annotationaccess patterns, andContentfactory methods
Reviewed changes
Copilot reviewed 45 out of 45 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| python/pyrightconfig.samples.json | New pyright configuration for sample validation with import/attribute checking |
| python/pyproject.toml | Added samples-syntax task and integrated into check/pre-commit workflows |
| python/AGENTS.md | Documentation for samples syntax checking process and exclusions |
| python/samples/getting_started/workflows/*/*.py | Updated imports from agent_framework to agent_framework_orchestrations for builders |
| python/samples/getting_started/tools/*.py | Changed isinstance checks to content.type comparisons |
| python/samples/getting_started/orchestrations/*.py | Updated imports and role access patterns |
| python/samples/getting_started/agents/*/*.py | Updated Content factory method usage and annotation access patterns |
| python/samples/getting_started/context_providers/*.py | Changed msg.content to msg.text |
| python/samples/demos/*/*.py | Updated to use ExecutorEvent instead of AgentRunUpdateEvent |
| python/samples/autogen-migration/*/*.py | Updated imports and content type checking patterns |
| { | ||
| "include": ["samples"], | ||
| "exclude": [ | ||
| "**/autogen/**", | ||
| "**/autogen-migration/**", | ||
| "**/semantic-kernel-migration/**", | ||
| "**/demos/**", | ||
| "**/agent_with_foundry_tracing.py" | ||
| ], | ||
| "typeCheckingMode": "off", | ||
| "reportMissingImports": "error", | ||
| "reportAttributeAccessIssue": "error" | ||
| } |
There was a problem hiding this comment.
Two sample files that are not excluded by this configuration still reference the nonexistent AgentRunUpdateEvent class and should have been updated to use ExecutorEvent instead:
python/samples/getting_started/workflows/agents/azure_chat_agents_tool_calls_with_feedback.py(lines 12, 197, 294)python/samples/getting_started/workflows/orchestration/magentic_human_plan_review.py(lines 8, 94)
These files import AgentRunUpdateEvent from agent_framework, but this class no longer exists - it should be ExecutorEvent based on the changes made in python/samples/demos/workflow_evaluation/create_workflow.py.
| { | ||
| "include": ["samples"], | ||
| "exclude": [ | ||
| "**/autogen/**", | ||
| "**/autogen-migration/**", | ||
| "**/semantic-kernel-migration/**", | ||
| "**/demos/**", | ||
| "**/agent_with_foundry_tracing.py" | ||
| ], | ||
| "typeCheckingMode": "off", | ||
| "reportMissingImports": "error", | ||
| "reportAttributeAccessIssue": "error" | ||
| } |
There was a problem hiding this comment.
This sample file imports several classes that have been moved to the agent_framework_orchestrations package but the imports have not been updated:
MagenticBuilder- should be imported fromagent_framework_orchestrationsMagenticPlanReviewRequest- should be imported fromagent_framework_orchestrationsAgentRunUpdateEvent- no longer exists, should be changed toExecutorEvent
The imports should be split into two statements similar to the pattern used in other updated samples.
| { | ||
| "include": ["samples"], | ||
| "exclude": [ | ||
| "**/autogen/**", | ||
| "**/autogen-migration/**", | ||
| "**/semantic-kernel-migration/**", | ||
| "**/demos/**", | ||
| "**/agent_with_foundry_tracing.py" | ||
| ], | ||
| "typeCheckingMode": "off", | ||
| "reportMissingImports": "error", | ||
| "reportAttributeAccessIssue": "error" | ||
| } |
There was a problem hiding this comment.
This sample file has multiple issues that need to be fixed to align with the API changes:
AgentRunUpdateEvent(line 12) - no longer exists, should be changed toExecutorEventFunctionCallContentandFunctionResultContent(lines 16-17) - these classes are no longer exported. The code should be updated to usecontent.type == "function_call"andcontent.type == "function_result"instead ofisinstance()checks (lines 204-205)- The
display_agent_run_updatefunction signature and isinstance checks need to be updated to useExecutorEventinstead ofAgentRunUpdateEvent
| import asyncio | ||
|
|
||
| from agent_framework import HostedMCPTool, HostedWebSearchTool, TextReasoningContent, UsageContent | ||
| from agent_framework import Content, HostedMCPTool, HostedWebSearchTool |
There was a problem hiding this comment.
Import of 'Content' is not used.
| from agent_framework import Content, HostedMCPTool, HostedWebSearchTool | |
| from agent_framework import HostedMCPTool, HostedWebSearchTool |
| import asyncio | ||
|
|
||
| from agent_framework import HostedMCPTool, HostedWebSearchTool, TextReasoningContent, UsageContent | ||
| from agent_framework import Content, HostedMCPTool, HostedWebSearchTool |
There was a problem hiding this comment.
Import of 'Content' is not used.
| from agent_framework import Content, HostedMCPTool, HostedWebSearchTool | |
| from agent_framework import HostedMCPTool, HostedWebSearchTool |
| from typing import Annotated | ||
|
|
||
| from agent_framework import FunctionCallContent, FunctionResultContent, tool | ||
| from agent_framework import Content, tool |
There was a problem hiding this comment.
Import of 'Content' is not used.
| from agent_framework import Content, tool | |
| from agent_framework import tool |
| from typing import Annotated | ||
|
|
||
| from agent_framework import FunctionCallContent, FunctionResultContent, tool | ||
| from agent_framework import Content, tool |
There was a problem hiding this comment.
Import of 'Content' is not used.
| from agent_framework import Content, tool | |
| from agent_framework import tool |
| from typing import Annotated | ||
|
|
||
| from agent_framework import FunctionCallContent, FunctionResultContent, tool | ||
| from agent_framework import Content, tool |
There was a problem hiding this comment.
Import of 'Content' is not used.
| from agent_framework import Content, tool | |
| from agent_framework import tool |
There was a problem hiding this comment.
Please back out any workflow/orchestration samples. I am fixing them in #3690. I do not want to deal with any more merge conflicts.
Motivation and Context
Description
Contribution Checklist