Skip to content

Python: Add samples syntax checking with pyright#3710

Open
eavanvalkenburg wants to merge 1 commit intomicrosoft:mainfrom
eavanvalkenburg:check_samples
Open

Python: Add samples syntax checking with pyright#3710
eavanvalkenburg wants to merge 1 commit intomicrosoft:mainfrom
eavanvalkenburg:check_samples

Conversation

@eavanvalkenburg
Copy link
Member

Motivation and Context

  • 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)

Description

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

- 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)
Copilot AI review requested due to automatic review settings February 5, 2026 20:43
@markwallace-microsoft markwallace-microsoft added documentation Improvements or additions to documentation python labels Feb 5, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.json with relaxed type checking configuration
  • Added samples-syntax poe task and integrated it into check and pre-commit-check workflows
  • Updated samples to import workflow builders from agent_framework_orchestrations package
  • Changed content type checking from isinstance() to .type property comparisons
  • Updated API usage for normalize_messages, ChatMessage.text, Role, Annotation access patterns, and Content factory 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

Comment on lines +1 to +13
{
"include": ["samples"],
"exclude": [
"**/autogen/**",
"**/autogen-migration/**",
"**/semantic-kernel-migration/**",
"**/demos/**",
"**/agent_with_foundry_tracing.py"
],
"typeCheckingMode": "off",
"reportMissingImports": "error",
"reportAttributeAccessIssue": "error"
}
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. python/samples/getting_started/workflows/agents/azure_chat_agents_tool_calls_with_feedback.py (lines 12, 197, 294)
  2. 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.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +13
{
"include": ["samples"],
"exclude": [
"**/autogen/**",
"**/autogen-migration/**",
"**/semantic-kernel-migration/**",
"**/demos/**",
"**/agent_with_foundry_tracing.py"
],
"typeCheckingMode": "off",
"reportMissingImports": "error",
"reportAttributeAccessIssue": "error"
}
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sample file imports several classes that have been moved to the agent_framework_orchestrations package but the imports have not been updated:

  1. MagenticBuilder - should be imported from agent_framework_orchestrations
  2. MagenticPlanReviewRequest - should be imported from agent_framework_orchestrations
  3. AgentRunUpdateEvent - no longer exists, should be changed to ExecutorEvent

The imports should be split into two statements similar to the pattern used in other updated samples.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +13
{
"include": ["samples"],
"exclude": [
"**/autogen/**",
"**/autogen-migration/**",
"**/semantic-kernel-migration/**",
"**/demos/**",
"**/agent_with_foundry_tracing.py"
],
"typeCheckingMode": "off",
"reportMissingImports": "error",
"reportAttributeAccessIssue": "error"
}
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sample file has multiple issues that need to be fixed to align with the API changes:

  1. AgentRunUpdateEvent (line 12) - no longer exists, should be changed to ExecutorEvent
  2. FunctionCallContent and FunctionResultContent (lines 16-17) - these classes are no longer exported. The code should be updated to use content.type == "function_call" and content.type == "function_result" instead of isinstance() checks (lines 204-205)
  3. The display_agent_run_update function signature and isinstance checks need to be updated to use ExecutorEvent instead of AgentRunUpdateEvent

Copilot uses AI. Check for mistakes.
import asyncio

from agent_framework import HostedMCPTool, HostedWebSearchTool, TextReasoningContent, UsageContent
from agent_framework import Content, HostedMCPTool, HostedWebSearchTool
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'Content' is not used.

Suggested change
from agent_framework import Content, HostedMCPTool, HostedWebSearchTool
from agent_framework import HostedMCPTool, HostedWebSearchTool

Copilot uses AI. Check for mistakes.
import asyncio

from agent_framework import HostedMCPTool, HostedWebSearchTool, TextReasoningContent, UsageContent
from agent_framework import Content, HostedMCPTool, HostedWebSearchTool
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'Content' is not used.

Suggested change
from agent_framework import Content, HostedMCPTool, HostedWebSearchTool
from agent_framework import HostedMCPTool, HostedWebSearchTool

Copilot uses AI. Check for mistakes.
from typing import Annotated

from agent_framework import FunctionCallContent, FunctionResultContent, tool
from agent_framework import Content, tool
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'Content' is not used.

Suggested change
from agent_framework import Content, tool
from agent_framework import tool

Copilot uses AI. Check for mistakes.
from typing import Annotated

from agent_framework import FunctionCallContent, FunctionResultContent, tool
from agent_framework import Content, tool
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'Content' is not used.

Suggested change
from agent_framework import Content, tool
from agent_framework import tool

Copilot uses AI. Check for mistakes.
from typing import Annotated

from agent_framework import FunctionCallContent, FunctionResultContent, tool
from agent_framework import Content, tool
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'Content' is not used.

Suggested change
from agent_framework import Content, tool
from agent_framework import tool

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please back out any workflow/orchestration samples. I am fixing them in #3690. I do not want to deal with any more merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants