Python: Add samples syntax checking with pyright (#3710)

* Add samples syntax checking with pyright

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

* fixed a bunch of samples and tweaks to pre-commit

* updated lock

* updated lock

* fixes

* added lint to samples
This commit is contained in:
Eduard van Valkenburg
2026-02-07 08:10:47 +01:00
committed by GitHub
Unverified
parent 74ac470a56
commit 390f93344c
83 changed files with 606 additions and 498 deletions
@@ -25,10 +25,9 @@ def add(
async def main():
client = OpenAIResponsesClient()
if client.function_invocation_configuration is not None:
client.function_invocation_configuration.include_detailed_errors = True
client.function_invocation_configuration.max_iterations = 40
print(f"Function invocation configured as: \n{client.function_invocation_configuration.to_json(indent=2)}")
client.function_invocation_configuration["include_detailed_errors"] = True
client.function_invocation_configuration["max_iterations"] = 40
print(f"Function invocation configured as: \n{client.function_invocation_configuration}")
agent = client.as_agent(name="ToolAgent", instructions="Use the provided tools.", tools=add)
@@ -1,5 +1,7 @@
# Copyright (c) Microsoft. All rights reserved.
import asyncio
from agent_framework import FunctionTool
from agent_framework.openai import OpenAIResponsesClient
@@ -70,6 +72,5 @@ Result: {
if __name__ == "__main__":
import asyncio
asyncio.run(main())
@@ -3,7 +3,7 @@
import asyncio
from typing import Annotated
from agent_framework import FunctionCallContent, FunctionResultContent, tool
from agent_framework import tool
from agent_framework.openai import OpenAIResponsesClient
"""
@@ -21,7 +21,6 @@ def greet(name: Annotated[str, "Name to greet"]) -> str:
return f"Hello, {name}!"
@tool(approval_mode="never_require")
# we trick the AI into calling this function with 0 as denominator to trigger the exception
@tool(approval_mode="never_require")
def safe_divide(
@@ -62,11 +61,11 @@ async def main():
if msg.text:
print(f"{idx + 1} {msg.author_name or msg.role}: {msg.text} ")
for content in msg.contents:
if isinstance(content, FunctionCallContent):
if content.type == "function_call":
print(
f"{idx + 1} {msg.author_name}: calling function: {content.name} with arguments: {content.arguments}"
)
if isinstance(content, FunctionResultContent):
if content.type == "function_result":
print(f"{idx + 1} {msg.role}: {content.result if content.result else content.exception}")
@@ -3,7 +3,7 @@
import asyncio
from typing import Annotated
from agent_framework import FunctionCallContent, FunctionResultContent, tool
from agent_framework import tool
from agent_framework.openai import OpenAIResponsesClient
"""
@@ -55,11 +55,11 @@ async def main():
if msg.text:
print(f"{idx + 1} {msg.author_name or msg.role}: {msg.text} ")
for content in msg.contents:
if isinstance(content, FunctionCallContent):
if content.type == "function_call":
print(
f"{idx + 1} {msg.author_name}: calling function: {content.name} with arguments: {content.arguments}"
)
if isinstance(content, FunctionResultContent):
if content.type == "function_result":
print(f"{idx + 1} {msg.role}: {content.result if content.result else content.exception}")
@@ -3,7 +3,7 @@
import asyncio
from typing import Annotated
from agent_framework import FunctionCallContent, FunctionResultContent, tool
from agent_framework import tool
from agent_framework.openai import OpenAIResponsesClient
"""
@@ -44,11 +44,11 @@ async def main():
if msg.text:
print(f"{idx + 1} {msg.author_name or msg.role}: {msg.text} ")
for content in msg.contents:
if isinstance(content, FunctionCallContent):
if content.type == "function_call":
print(
f"{idx + 1} {msg.author_name}: calling function: {content.name} with arguments: {content.arguments}"
)
if isinstance(content, FunctionResultContent):
if content.type == "function_result":
print(f"{idx + 1} {msg.role}: {content.result if content.result else content.exception}")