Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
AgentResponseUpdate,
ChatAgent,
CitationAnnotation,
Content,
HostedCodeInterpreterTool,
HostedFileContent,
TextContent,
tool,
)
from agent_framework.azure import AzureAIProjectAgentProvider
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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",
),
Expand Down
10 changes: 5 additions & 5 deletions python/samples/getting_started/agents/custom/custom_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
AgentThread,
BaseAgent,
ChatMessage,
Content,
Role,
TextContent,
tool,
)

Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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,
)

Expand All @@ -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)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
ChatMessage,
ChatResponse,
ChatResponseUpdate,
Content,
Role,
TextContent,
use_chat_middleware,
use_function_invocation,
tool,
Expand Down Expand Up @@ -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],
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand All @@ -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",
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
ChatAgent,
CodeInterpreterToolCallContent,
CodeInterpreterToolResultContent,
Content,
HostedCodeInterpreterTool,
TextContent,
tool,
)
from agent_framework.openai import OpenAIResponsesClient
Expand Down Expand Up @@ -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)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
ChatMessage,
ChatResponse,
ChatResponseUpdate,
Content,
FunctionInvocationContext,
Role,
TextContent,
tool,
chat_middleware,
function_middleware,
Expand Down Expand Up @@ -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,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
AgentResponseUpdate,
AgentRunContext,
ChatMessage,
Content,
Role,
TextContent,
tool,
)
from agent_framework.azure import AzureAIAgentClient
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
from agent_framework import (
AgentRunUpdateEvent,
ChatAgent,
Content,
HandoffAgentUserRequest,
HandoffBuilder,
HostedCodeInterpreterTool,
HostedFileContent,
RequestInfoEvent,
TextContent,
WorkflowEvent,
WorkflowRunState,
WorkflowStatusEvent,
Expand Down Expand Up @@ -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)
Expand Down
Loading