Skip to content

A programming framework for agentic AI

Fix spurious </think> tags caused by empty string reasoning_content in streaming (#7025)

Copilot79d5d6ab47f2
diff --git a/python/packages/autogen-ext/src/autogen_ext/models/openai/_openai_client.py b/python/packages/autogen-ext/src/autogen_ext/models/openai/_openai_client.py
index 359ddfe6c..2cbb235ce 100644
--- a/python/packages/autogen-ext/src/autogen_ext/models/openai/_openai_client.py
+++ b/python/packages/autogen-ext/src/autogen_ext/models/openai/_openai_client.py
@@ -947,8 +947,8 @@ class BaseOpenAIChatCompletionClient(ChatCompletionClient):
is_reasoning = True
thought_deltas.append(reasoning_content)
yield reasoning_content
- elif is_reasoning:
- # Exit reasoning mode.
+ elif reasoning_content is None and is_reasoning:
+ # Exit reasoning mode only when reasoning_content is None (not when it's an empty string).
reasoning_content = "</think>"
thought_deltas.append(reasoning_content)
is_reasoning = False