diff --git a/python/samples/getting_started/agents/azure_ai/azure_ai_with_code_interpreter_file_download.py b/python/samples/getting_started/agents/azure_ai/azure_ai_with_code_interpreter_file_download.py index ba3f72c1ce..72e290e1b4 100644 --- a/python/samples/getting_started/agents/azure_ai/azure_ai_with_code_interpreter_file_download.py +++ b/python/samples/getting_started/agents/azure_ai/azure_ai_with_code_interpreter_file_download.py @@ -8,9 +8,9 @@ AgentResponseUpdate, ChatAgent, CitationAnnotation, + Content, HostedCodeInterpreterTool, HostedFileContent, - TextContent, tool, ) from agent_framework.azure import AzureAIProjectAgentProvider @@ -138,7 +138,7 @@ async def non_streaming_example() -> None: # AgentResponse has messages property, which contains ChatMessage objects for message in result.messages: for content in message.contents: - if isinstance(content, TextContent) and content.annotations: + if content.type == "text" and content.annotations: for annotation in content.annotations: if isinstance(annotation, CitationAnnotation) and annotation.file_id: annotations_found.append(annotation) @@ -181,7 +181,7 @@ async def streaming_example() -> None: async for update in agent.run_stream(QUERY): if isinstance(update, AgentResponseUpdate): for content in update.contents: - if isinstance(content, TextContent): + if content.type == "text": if content.text: text_chunks.append(content.text) if content.annotations: diff --git a/python/samples/getting_started/agents/azure_openai/azure_responses_client_image_analysis.py b/python/samples/getting_started/agents/azure_openai/azure_responses_client_image_analysis.py index ebfb81dada..9bf05e32e0 100644 --- a/python/samples/getting_started/agents/azure_openai/azure_responses_client_image_analysis.py +++ b/python/samples/getting_started/agents/azure_openai/azure_responses_client_image_analysis.py @@ -2,7 +2,7 @@ import asyncio -from agent_framework import ChatMessage, TextContent, UriContent +from agent_framework import ChatMessage, Content from agent_framework.azure import AzureOpenAIResponsesClient from azure.identity import AzureCliCredential @@ -27,8 +27,8 @@ async def main(): user_message = ChatMessage( role="user", contents=[ - TextContent(text="What do you see in this image?"), - UriContent( + Content.from_text(text="What do you see in this image?"), + Content.from_uri( uri="https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg", media_type="image/jpeg", ), diff --git a/python/samples/getting_started/agents/custom/custom_agent.py b/python/samples/getting_started/agents/custom/custom_agent.py index 8408f88fd0..4bdc0d79e3 100644 --- a/python/samples/getting_started/agents/custom/custom_agent.py +++ b/python/samples/getting_started/agents/custom/custom_agent.py @@ -10,8 +10,8 @@ AgentThread, BaseAgent, ChatMessage, + Content, Role, - TextContent, tool, ) @@ -78,7 +78,7 @@ async def run( if not normalized_messages: response_message = ChatMessage( role=Role.ASSISTANT, - contents=[TextContent(text="Hello! I'm a custom echo agent. Send me a message and I'll echo it back.")], + contents=[Content.from_text(text="Hello! I'm a custom echo agent. Send me a message and I'll echo it back.")], ) else: # For simplicity, echo the last user message @@ -88,7 +88,7 @@ async def run( else: echo_text = f"{self.echo_prefix}[Non-text message received]" - response_message = ChatMessage(role=Role.ASSISTANT, contents=[TextContent(text=echo_text)]) + response_message = ChatMessage(role=Role.ASSISTANT, contents=[Content.from_text(text=echo_text)]) # Notify the thread of new messages if provided if thread is not None: @@ -133,7 +133,7 @@ async def run_stream( chunk_text = f" {word}" if i > 0 else word yield AgentResponseUpdate( - contents=[TextContent(text=chunk_text)], + contents=[Content.from_text(text=chunk_text)], role=Role.ASSISTANT, ) @@ -142,7 +142,7 @@ async def run_stream( # Notify the thread of the complete response if provided if thread is not None: - complete_response = ChatMessage(role=Role.ASSISTANT, contents=[TextContent(text=response_text)]) + complete_response = ChatMessage(role=Role.ASSISTANT, contents=[Content.from_text(text=response_text)]) await self._notify_thread_of_new_messages(thread, normalized_messages, complete_response) diff --git a/python/samples/getting_started/agents/custom/custom_chat_client.py b/python/samples/getting_started/agents/custom/custom_chat_client.py index 00078d14c3..c7df328b00 100644 --- a/python/samples/getting_started/agents/custom/custom_chat_client.py +++ b/python/samples/getting_started/agents/custom/custom_chat_client.py @@ -11,8 +11,8 @@ ChatMessage, ChatResponse, ChatResponseUpdate, + Content, Role, - TextContent, use_chat_middleware, use_function_invocation, tool, @@ -77,7 +77,7 @@ async def _inner_get_response( else: response_text = f"{self.prefix} [No text message found]" - response_message = ChatMessage(role=Role.ASSISTANT, contents=[TextContent(text=response_text)]) + response_message = ChatMessage(role=Role.ASSISTANT, contents=[Content.from_text(text=response_text)]) return ChatResponse( messages=[response_message], @@ -103,7 +103,7 @@ async def _inner_get_streaming_response( # Stream character by character for char in response_text: yield ChatResponseUpdate( - contents=[TextContent(text=char)], + contents=[Content.from_text(text=char)], role=Role.ASSISTANT, response_id=f"echo-stream-resp-{random.randint(1000, 9999)}", model_id="echo-model-v1", diff --git a/python/samples/getting_started/agents/openai/openai_responses_client_image_analysis.py b/python/samples/getting_started/agents/openai/openai_responses_client_image_analysis.py index 83908b162a..c9c56d5e48 100644 --- a/python/samples/getting_started/agents/openai/openai_responses_client_image_analysis.py +++ b/python/samples/getting_started/agents/openai/openai_responses_client_image_analysis.py @@ -2,7 +2,7 @@ import asyncio -from agent_framework import ChatMessage, TextContent, UriContent +from agent_framework import ChatMessage, Content from agent_framework.openai import OpenAIResponsesClient """ @@ -26,8 +26,8 @@ async def main(): user_message = ChatMessage( role="user", contents=[ - TextContent(text="What do you see in this image?"), - UriContent( + Content.from_text(text="What do you see in this image?"), + Content.from_uri( uri="https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg", media_type="image/jpeg", ), diff --git a/python/samples/getting_started/agents/openai/openai_responses_client_image_generation.py b/python/samples/getting_started/agents/openai/openai_responses_client_image_generation.py index 39eda7fd18..9d9fcbf546 100644 --- a/python/samples/getting_started/agents/openai/openai_responses_client_image_generation.py +++ b/python/samples/getting_started/agents/openai/openai_responses_client_image_generation.py @@ -3,7 +3,7 @@ import asyncio import base64 -from agent_framework import DataContent, HostedImageGenerationTool, ImageGenerationToolResultContent, UriContent +from agent_framework import Content, HostedImageGenerationTool, ImageGenerationToolResultContent from agent_framework.openai import OpenAIResponsesClient """ @@ -72,7 +72,7 @@ async def main() -> None: for content in message.contents: if isinstance(content, ImageGenerationToolResultContent) and content.outputs: for output in content.outputs: - if isinstance(output, (DataContent, UriContent)) and output.uri: + if output.type in ("data", "uri") and output.uri: show_image_info(output.uri) break diff --git a/python/samples/getting_started/agents/openai/openai_responses_client_streaming_image_generation.py b/python/samples/getting_started/agents/openai/openai_responses_client_streaming_image_generation.py index 1f3ceae7ec..c5373b69f7 100644 --- a/python/samples/getting_started/agents/openai/openai_responses_client_streaming_image_generation.py +++ b/python/samples/getting_started/agents/openai/openai_responses_client_streaming_image_generation.py @@ -4,7 +4,7 @@ import base64 import anyio -from agent_framework import DataContent, HostedImageGenerationTool +from agent_framework import Content, HostedImageGenerationTool from agent_framework.openai import OpenAIResponsesClient """OpenAI Responses Client Streaming Image Generation Example @@ -72,7 +72,7 @@ async def main(): # Handle partial images # The final partial image IS the complete, full-quality image. Each partial # represents a progressive refinement, with the last one being the finished result. - if isinstance(content, DataContent) and content.additional_properties.get("is_partial_image"): + if content.type == "data" and content.additional_properties.get("is_partial_image"): print(f" Image {image_count} received") # Extract file extension from media_type (e.g., "image/png" -> "png") diff --git a/python/samples/getting_started/agents/openai/openai_responses_client_with_code_interpreter.py b/python/samples/getting_started/agents/openai/openai_responses_client_with_code_interpreter.py index 5e8e9565ac..6988219dcc 100644 --- a/python/samples/getting_started/agents/openai/openai_responses_client_with_code_interpreter.py +++ b/python/samples/getting_started/agents/openai/openai_responses_client_with_code_interpreter.py @@ -6,8 +6,8 @@ ChatAgent, CodeInterpreterToolCallContent, CodeInterpreterToolResultContent, + Content, HostedCodeInterpreterTool, - TextContent, tool, ) from agent_framework.openai import OpenAIResponsesClient @@ -41,13 +41,13 @@ async def main() -> None: if code_blocks: code_inputs = code_blocks[0].inputs or [] for content in code_inputs: - if isinstance(content, TextContent): + if content.type == "text": print(f"Generated code:\n{content.text}") break if outputs: print("Execution outputs:") for out in outputs[0].outputs or []: - if isinstance(out, TextContent): + if out.type == "text": print(out.text) diff --git a/python/samples/getting_started/devui/weather_agent_azure/agent.py b/python/samples/getting_started/devui/weather_agent_azure/agent.py index 56ba546135..cc2992d0c5 100644 --- a/python/samples/getting_started/devui/weather_agent_azure/agent.py +++ b/python/samples/getting_started/devui/weather_agent_azure/agent.py @@ -12,9 +12,9 @@ ChatMessage, ChatResponse, ChatResponseUpdate, + Content, FunctionInvocationContext, Role, - TextContent, tool, chat_middleware, function_middleware, @@ -57,7 +57,7 @@ async def security_filter_middleware( # Streaming mode: return async generator async def blocked_stream() -> AsyncIterable[ChatResponseUpdate]: yield ChatResponseUpdate( - contents=[TextContent(text=error_message)], + contents=[Content.from_text(text=error_message)], role=Role.ASSISTANT, ) diff --git a/python/samples/getting_started/middleware/override_result_with_middleware.py b/python/samples/getting_started/middleware/override_result_with_middleware.py index e364eac279..a22b15a67b 100644 --- a/python/samples/getting_started/middleware/override_result_with_middleware.py +++ b/python/samples/getting_started/middleware/override_result_with_middleware.py @@ -10,8 +10,8 @@ AgentResponseUpdate, AgentRunContext, ChatMessage, + Content, Role, - TextContent, tool, ) from agent_framework.azure import AzureAIAgentClient @@ -69,7 +69,7 @@ async def weather_override_middleware( # For streaming: create an async generator that yields chunks async def override_stream() -> AsyncIterable[AgentResponseUpdate]: for chunk in chunks: - yield AgentResponseUpdate(contents=[TextContent(text=chunk)]) + yield AgentResponseUpdate(contents=[Content.from_text(text=chunk)]) context.result = override_stream() else: diff --git a/python/samples/getting_started/workflows/orchestration/handoff_with_code_interpreter_file.py b/python/samples/getting_started/workflows/orchestration/handoff_with_code_interpreter_file.py index b1d6f394b7..54f7f4504c 100644 --- a/python/samples/getting_started/workflows/orchestration/handoff_with_code_interpreter_file.py +++ b/python/samples/getting_started/workflows/orchestration/handoff_with_code_interpreter_file.py @@ -32,12 +32,12 @@ from agent_framework import ( AgentRunUpdateEvent, ChatAgent, + Content, HandoffAgentUserRequest, HandoffBuilder, HostedCodeInterpreterTool, HostedFileContent, RequestInfoEvent, - TextContent, WorkflowEvent, WorkflowRunState, WorkflowStatusEvent, @@ -76,7 +76,7 @@ def _handle_events(events: list[WorkflowEvent]) -> tuple[list[RequestInfoEvent], if isinstance(content, HostedFileContent): file_ids.append(content.file_id) print(f"[Found HostedFileContent: file_id={content.file_id}]") - elif isinstance(content, TextContent) and content.annotations: + elif content.type == "text" and content.annotations: for annotation in content.annotations: if hasattr(annotation, "file_id") and annotation.file_id: file_ids.append(annotation.file_id)