-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
Describe the bug
ResponsesAgentThread.GetMessagesAsync()
can enter an infinite loop and repeatedly yield the same set of messages when used with Azure OpenAI. The root cause is upstream in the Azure SDK (Azure.AI.OpenAI
): list calls for Responses items don’t propagate pagination args (after
/before
/order
/limit
), so the SDK re-fetches the same page even while has_more=true
.
Tracking upstream issue: Azure/azure-sdk-for-net#50906
Even though this originates in the Azure SDK, Semantic Kernel should defensively handle non-advancing pagination so app code doesn’t hang.
To Reproduce
Happens some multi-turn conversations where the Responses API returns has_more=true
near the end.
-
Configure SK Agents with Azure OpenAI (Responses API) and obtain a
previousResponseId
from a multi-turn conversation that spans more than one page of items. -
Create a
ResponsesAgentThread
and enumerate messages:var agentThread = new OpenAIResponseAgentThread(_client, previousResponseId); await foreach (var t in agentThread.GetMessagesAsync()) { <loop content> }
-
Observe that the enumeration never completes and the same user/assistant messages repeat indefinitely.
-
(Optional diagnostic) Log per page:
count
,first_id
,last_id
, and the outgoing cursor. You’ll see unchangedfirst_id/last_id
on successive requests (non-advancing cursor).
Expected behavior
GetMessagesAsync()
should always terminate and get the complete list of messages.
Platform
- Language: C#
- Source:
- Semantic Kernel: 1.61.0(-preview)
- Azure SDK:
Azure.AI.OpenAI
2.2.0-beta.5
- AI model: Azure OpenAI Responses with GPT-4.1
Additional context
-
Upstream Azure SDK bug (non-advancing pagination): [BUG] AzureOpenAIResponseClient.CreateListInputItemsRequest method is dropping paging arguments(limits, order, after, before) Azure/azure-sdk-for-net#50906
-
From looking at source code, this loop likely doesnot repro with the official OpenAI .NET; it appears specific to
Azure.AI.OpenAI
pagination for Responses.