Open
Description
Issue Title: Missing Handling for delta.reasoning_content
in agents.models.chatcmpl_stream_handler.ChatCmplStreamHandler.handle_stream
Description:
In the ChatCmplStreamHandler.handle_stream
method, the case where delta.reasoning_content
is present is not handled. This could lead to incomplete or incorrect handling of the stream response when reasoning content is provided by the model.
Problematic Code Example:
class ChatCmplStreamHandler:
@classmethod
async def handle_stream(
cls,
response: Response,
stream: AsyncStream[ChatCompletionChunk],
) -> AsyncIterator[TResponseStreamEvent]:
usage: CompletionUsage | None = None
state = StreamingState()
async for chunk in stream:
if not state.started:
state.started = True
yield ResponseCreatedEvent(
response=response,
type="response.created",
)
usage = chunk.usage
if not chunk.choices or not chunk.choices[0].delta:
continue
delta = chunk.choices[0].delta
# Handle text
if delta.content:
……
# Handle refusals (model declines to answer)
if delta.refusal:
Steps to Reproduce:
- Use a model that provides reasoning content in its responses.
- Trigger a stream response that includes
delta.reasoning_content
. - Observe that the
ChatCmplStreamHandler.handle_stream
method does not process or emit events related to the reasoning content.
Actual Behavior:
The delta.reasoning_content
is ignored, and no events are emitted to handle or notify consumers of the reasoning content.
Impact:
This issue prevents the proper handling and display of reasoning content in the stream, which is crucial for models that provide explanations or reasoning behind their responses.
Proposed Solution:
Add handling for delta.reasoning_content
in the ChatCmplStreamHandler.handle_stream
method. Example code snippet:
class ChatCmplStreamHandler:
@classmethod
async def handle_stream(
cls,
response: Response,
stream: AsyncStream[ChatCompletionChunk],
) -> AsyncIterator[TResponseStreamEvent]:
usage: CompletionUsage | None = None
state = StreamingState()
async for chunk in stream:
if not state.started:
state.started = True
yield ResponseCreatedEvent(
response=response,
type="response.created",
)
usage = chunk.usage
if not chunk.choices or not chunk.choices[0].delta:
continue
delta = chunk.choices[0].delta
# Handle text
if delta.content:
# Handle reasoning content text
if delta.reasoning_content: