Skip to content

Commit 733fa9e

Browse files
committed
Support streaming
1 parent 243bd42 commit 733fa9e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

python/packages/core/agent_framework/_types.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,13 +858,18 @@ def __add__(self, other: "TextReasoningContent") -> "TextReasoningContent":
858858
else:
859859
annotations = self.annotations + other.annotations
860860

861+
# Replace protected data.
862+
# Discussion: https://github.com/microsoft/agent-framework/pull/2950#discussion_r2634345613
863+
protected_data = other.protected_data or self.protected_data
864+
861865
# Create new instance using from_dict for proper deserialization
862866
result_dict = {
863867
"text": self.text + other.text,
864868
"type": "text_reasoning",
865869
"annotations": [ann.to_dict(exclude_none=False) for ann in annotations] if annotations else None,
866870
"additional_properties": {**(self.additional_properties or {}), **(other.additional_properties or {})},
867871
"raw_representation": raw_representation,
872+
"protected_data": protected_data,
868873
}
869874
return TextReasoningContent.from_dict(result_dict)
870875

@@ -900,6 +905,11 @@ def __iadd__(self, other: "TextReasoningContent") -> Self:
900905
self.raw_representation if isinstance(self.raw_representation, list) else [self.raw_representation]
901906
) + (other.raw_representation if isinstance(other.raw_representation, list) else [other.raw_representation])
902907

908+
# Replace protected data.
909+
# Discussion: https://github.com/microsoft/agent-framework/pull/2950#discussion_r2634345613
910+
if other.protected_data is not None:
911+
self.protected_data = other.protected_data
912+
903913
# Merge annotations
904914
if other.annotations:
905915
if self.annotations is None:

python/packages/core/agent_framework/openai/_chat_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
from openai.types.chat.chat_completion_message_custom_tool_call import ChatCompletionMessageCustomToolCall
1717
from pydantic import BaseModel, ValidationError
1818

19-
from agent_framework import TextReasoningContent
20-
2119
from .._clients import BaseChatClient
2220
from .._logging import get_logger
2321
from .._middleware import use_chat_middleware
@@ -36,6 +34,7 @@
3634
FunctionResultContent,
3735
Role,
3836
TextContent,
37+
TextReasoningContent,
3938
UriContent,
4039
UsageContent,
4140
UsageDetails,
@@ -255,6 +254,8 @@ def _create_chat_response_update(
255254

256255
if text_content := self._parse_text_from_choice(choice):
257256
contents.append(text_content)
257+
if reasoning_details := getattr(choice.delta, "reasoning_details", None):
258+
contents.append(TextReasoningContent(None, protected_data=json.dumps(reasoning_details)))
258259
return ChatResponseUpdate(
259260
created_at=datetime.fromtimestamp(chunk.created, tz=timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%fZ"),
260261
contents=contents,

0 commit comments

Comments
 (0)