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
@@ -5,7 +5,15 @@ from collections.abc import Awaitable, Callable
from random import randint
from typing import Annotated
from agent_framework import ChatAgent, ChatContext, ChatMessage, ChatResponse, Role, chat_middleware, tool
from agent_framework import (
ChatAgent,
ChatContext,
ChatMessage,
ChatResponse,
MiddlewareTermination,
chat_middleware,
tool,
)
from agent_framework.openai import OpenAIResponsesClient
from pydantic import Field
@@ -39,7 +47,7 @@ async def security_and_override_middleware(
context.result = ChatResponse(
messages=[
ChatMessage(
role=Role.ASSISTANT,
role="assistant",
text="I cannot process requests containing sensitive information. "
"Please rephrase your question without including passwords, secrets, or other "
"sensitive data.",
@@ -48,8 +56,7 @@ async def security_and_override_middleware(
)
# Set terminate flag to stop execution
context.terminate = True
return
raise MiddlewareTermination
# Continue to next middleware or AI execution
await next(context)
@@ -70,7 +70,7 @@ async def main() -> None:
# Show information about the generated image
for message in result.messages:
for content in message.contents:
if content.type == "image_generation" and content.outputs:
if content.type == "image_generation_tool_result" and content.outputs:
for output in content.outputs:
if output.type in ("data", "uri") and output.uri:
show_image_info(output.uri)
@@ -32,7 +32,7 @@ async def main() -> None:
print(f"Result: {result}\n")
for message in result.messages:
code_blocks = [c for c in message.contents if c.type == "code_interpreter_tool_input"]
code_blocks = [c for c in message.contents if c.type == "code_interpreter_tool_call"]
outputs = [c for c in message.contents if c.type == "code_interpreter_tool_result"]
if code_blocks:
code_inputs = code_blocks[0].inputs or []
@@ -14,7 +14,7 @@ OpenAI Responses Client, including user approval workflows for function call sec
"""
if TYPE_CHECKING:
from agent_framework import SupportsAgentRun, AgentThread
from agent_framework import AgentThread, SupportsAgentRun
async def handle_approvals_without_thread(query: str, agent: "SupportsAgentRun"):