Skip to content

Commit 82e5ce9

Browse files
committed
Merge branch 'jc/agentserver/af-streaming-fix' into lusu/agentserver-1110
2 parents a26603e + 9cdf214 commit 82e5ce9

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

sdk/agentserver/azure-ai-agentserver-agentframework/azure/ai/agentserver/agentframework/models/agent_framework_output_streaming_converter.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import datetime
99
import json
10-
from typing import AsyncIterable, List, Optional
10+
from typing import Any, AsyncIterable, List, Optional
1111

1212
from agent_framework import AgentRunResponseUpdate, BaseContent, FunctionApprovalRequestContent, FunctionResultContent
1313
from agent_framework._types import (
@@ -201,7 +201,7 @@ async def convert_contents(self, contents: AsyncIterable[FunctionResultContent])
201201

202202
output = (f"{type(content.exception)}({str(content.exception)})"
203203
if content.exception
204-
else json.dumps(content.result))
204+
else self._to_output(content.result))
205205

206206
item = FunctionToolCallOutputItemResource(
207207
id=item_id,
@@ -224,6 +224,21 @@ async def convert_contents(self, contents: AsyncIterable[FunctionResultContent])
224224

225225
self._parent.add_completed_output_item(item) # pylint: disable=protected-access
226226

227+
@classmethod
228+
def _to_output(cls, result: Any) -> str:
229+
if isinstance(result, str):
230+
return result
231+
elif isinstance(result, list):
232+
text = []
233+
for item in result:
234+
if isinstance(item, BaseContent):
235+
text.append(item.to_dict())
236+
else:
237+
text.append(str(item))
238+
return json.dumps(text)
239+
else:
240+
return ""
241+
227242

228243
class AgentFrameworkOutputStreamingConverter:
229244
"""Streaming converter using content-type-specific state handlers."""

0 commit comments

Comments
 (0)