From 01d8a8af5348f276748c24f49b003e6c85761844 Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Mon, 20 Apr 2026 20:27:26 -0700 Subject: [PATCH] Fix pre commit 4 --- .../_responses.py | 16 +++---- .../samples/02-agents/observability/README.md | 43 ++++++++++--------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py b/python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py index f7e6dcf2e4..cdd4b34b4f 100644 --- a/python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py +++ b/python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py @@ -390,36 +390,36 @@ class _OutputItemTracker: if self._active_type != "text": yield from self._close() yield from self._open_message() - assert self._text_content is not None # noqa: S101 self._accumulated.append(content.text) - yield self._text_content.emit_delta(content.text) + if self._text_content is not None: + yield self._text_content.emit_delta(content.text) elif content.type == "text_reasoning" and content.text is not None: if self._active_type != "text_reasoning": yield from self._close() yield from self._open_reasoning() - assert self._summary_part is not None # noqa: S101 self._accumulated.append(content.text) - yield self._summary_part.emit_text_delta(content.text) + if self._summary_part is not None: + yield self._summary_part.emit_text_delta(content.text) elif content.type == "function_call" and content.call_id is not None: if self._active_type != "function_call" or self._active_id != content.call_id: yield from self._close() yield from self._open_function_call(content) - assert self._fc_builder is not None # noqa: S101 args_str = _arguments_to_str(content.arguments) self._accumulated.append(args_str) - yield self._fc_builder.emit_arguments_delta(args_str) + if self._fc_builder is not None: + yield self._fc_builder.emit_arguments_delta(args_str) elif content.type == "mcp_server_tool_call" and content.tool_name: key = f"{content.server_name or 'default'}::{content.tool_name}" if self._active_type != "mcp_server_tool_call" or self._active_id != key: yield from self._close() yield from self._open_mcp_call(content) - assert self._mcp_builder is not None # noqa: S101 args_str = _arguments_to_str(content.arguments) self._accumulated.append(args_str) - yield self._mcp_builder.emit_arguments_delta(args_str) + if self._mcp_builder is not None: + yield self._mcp_builder.emit_arguments_delta(args_str) else: yield from self._close() diff --git a/python/samples/02-agents/observability/README.md b/python/samples/02-agents/observability/README.md index 33866ffc89..6066ea741a 100644 --- a/python/samples/02-agents/observability/README.md +++ b/python/samples/02-agents/observability/README.md @@ -347,28 +347,29 @@ setup_observability( ``` **After (Current):** + ```python -# For Microsoft Foundry projects -from agent_framework.foundry import FoundryChatClient -from azure.identity import AzureCliCredential - -client = FoundryChatClient( - project_endpoint="https://your-project.services.ai.azure.com", - model="gpt-4o", - credential=AzureCliCredential(), -) -await client.configure_azure_monitor(enable_live_metrics=True) - -# For non-Azure AI projects -from azure.monitor.opentelemetry import configure_azure_monitor -from agent_framework.observability import create_resource, enable_instrumentation - -configure_azure_monitor( - connection_string="InstrumentationKey=...", - resource=create_resource(), - enable_live_metrics=True, -) -enable_instrumentation() +async def main(): + # For Microsoft Foundry projects + from agent_framework.foundry import FoundryChatClient + from azure.identity import AzureCliCredential + client = FoundryChatClient( + project_endpoint="https://your-project.services.ai.azure.com", + model="gpt-4o", + credential=AzureCliCredential(), + ) + await client.configure_azure_monitor(enable_live_metrics=True) + + # For non-Azure AI projects + from azure.monitor.opentelemetry import configure_azure_monitor + from agent_framework.observability import create_resource, enable_instrumentation + + configure_azure_monitor( + connection_string="InstrumentationKey=...", + resource=create_resource(), + enable_live_metrics=True, + ) + enable_instrumentation() ``` ### Console Output