You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Move system prompt to Instructions to prevent accumulation across turns
When using previous_response_id, the system prompt was being added as a
ResponseItem.CreateSystemMessageItem in every turn's input list. Since
OpenAI already holds the full conversation server-side, this caused the
system prompt to accumulate in context on each turn and each tool-call leg.
Fix: Set the system prompt via ResponseCreationOptions.Instructions in
CreateResponseOptionsAsync instead. Per the Azure OpenAI API docs,
Instructions is stateless across turns when using previous_response_id,
so it is applied fresh each turn without accumulating.
Both GetChatCompletionCore and GetChatCompletionStream now always pass
only [ResponseItem.CreateUserMessageItem(prompt)] as input items.
CreateResponseOptionsAsync is no longer static since it accesses _Options.
// Create the streaming response using the Responses API
92
89
#pragma warning disable OPENAI001// Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
93
-
List<ResponseItem>responseItems=systemContextis not null
#pragma warning restore OPENAI001// Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
/// Creates response options with optional features
255
250
/// </summary>
256
251
#pragma warning disable OPENAI001// Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
#pragma warning restore OPENAI001// Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
267
263
264
+
// Set the system prompt via Instructions — this is stateless across turns when using previous_response_id,
265
+
// preventing accumulation of system messages in the conversation context.
#pragma warning disable OPENAI001// Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
313
317
ResponseCreationOptionsresponseOptions,
314
318
#pragma warning restore OPENAI001// Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
315
-
string?systemPrompt=null,
316
319
CancellationTokencancellationToken=default)
317
320
{
318
-
// Construct the user input with system context if provided
// Create the streaming response using the Responses API
321
+
// Create the response using the Responses API
322
322
#pragma warning disable OPENAI001// Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
323
-
List<ResponseItem>responseItems=systemContextis not null
#pragma warning restore OPENAI001// Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
0 commit comments