Skip to content

.NET: [Bug]: invalid_payload after the AI responeded with reasoning role. #6911

Description

@karljucutan

Description

After I added a ReasoningOptions, I got invalid_payload error after the AI responded a message with role: "reasoning". If the AI did not respond yet with role: "reasoning" there are no invalid_payload issue.

Request Payload:

{
  "threadId": "thread-1783146160899-7dx2yk",
  "runId": "run-1783146211845-bxzbae",
  "state": {},
  "messages": [
    {
      "id": "msg-1783146164467-7cvmjc",
      "role": "user",
      "parts": [
        {
          "type": "text",
          "content": "hi"
        }
      ],
      "createdAt": "2026-07-04T06:22:44.467Z",
      "content": "hi"
    },
    {
      "id": "msg_08401b0393b4b483006a48a6bac59881958aa78143e8490bfe",
      "role": "assistant",
      "parts": [
        {
          "type": "text",
          "content": "Hi — how can I help you today? I can search business rules, explain rules, map requirements to rules, or create acceptance criteria and test cases. Which would you like?"
        }
      ],
      "createdAt": "2026-07-04T06:22:50.154Z",
      "content": "Hi — how can I help you today? I can search business rules, explain rules, map requirements to rules, or create acceptance criteria and test cases. Which would you like?"
    },
    {
      "id": "msg-1783146176003-b16cnh",
      "role": "user",
      "parts": [
        {
          "type": "text",
          "content": "reason to me"
        }
      ],
      "createdAt": "2026-07-04T06:22:56.003Z",
      "content": "reason to me"
    },
    {
      "role": "reasoning",
      "id": "msg_0b3cc0809fa6331c006a48a6c73d80819399a7d1514a02b948-reasoning-rx7ptq",
      "content": "**Clarifying business rules**\n\nI’m wondering if the user wants me to explain my reasoning about a specific business rule or decision. If that's the case, I need to know which rule or scenario they mean. It’s important to remember that I must use SearchRules to find applicable business rules if needed, and I should keep my questions concise, especially when I’m unsure. Keeping things short and clear is key!"
    },
    {
      "id": "msg_0b3cc0809fa6331c006a48a6c73d80819399a7d1514a02b948",
      "role": "assistant",
      "parts": [
        {
          "type": "thinking",
          "content": "**Clarifying business rules**\n\nI’m wondering if the user wants me to explain my reasoning about a specific business rule or decision. If that's the case, I need to know which rule or scenario they mean. It’s important to remember that I must use SearchRules to find applicable business rules if needed, and I should keep my questions concise, especially when I’m unsure. Keeping things short and clear is key!",
          "stepId": null
        },
        {
          "type": "text",
          "content": "Do you mean you want me to explain my reasoning about a specific business rule or scenario — if so, which rule ID or scenario should I reason about?"
        }
      ],
      "createdAt": "2026-07-04T06:23:01.673Z",
      "content": "Do you mean you want me to explain my reasoning about a specific business rule or scenario — if so, which rule ID or scenario should I reason about?"
    },
    {
      "id": "msg-1783146211845-17rr6i",
      "role": "user",
      "parts": [
        {
          "type": "text",
          "content": "hi"
        }
      ],
      "createdAt": "2026-07-04T06:23:31.845Z",
      "content": "hi"
    }
  ],
  "tools": [],
  "context": [],
  "forwardedProps": {},
  "data": {}
}

EventStream:

{"threadId":"thread-1783146160899-7dx2yk","runId":"run-1783146211845-bxzbae","type":"RUN_STARTED"}
{"message":"HTTP 400 (ServiceError: invalid_payload)\r\n\r\nThe provided data does not match the expected schema [Request ID: caefc2e768a37cbab6286b5fda3d550c]\r\n\r\n{\r\n  \u0022code\u0022: \u0022invalid_payload\u0022,\r\n  \u0022message\u0022: \u0022The provided data does not match the expected schema [Request ID: caefc2e768a37cbab6286b5fda3d550c]\u0022,\r\n  \u0022param\u0022: \u0022/\u0022,\r\n  \u0022type\u0022: \u0022invalid_request_error\u0022,\r\n  \u0022details\u0022: [],\r\n  \u0022additionalInfo\u0022: {\r\n    \u0022request_id\u0022: \u0022caefc2e768a37cbab6286b5fda3d550c\u0022\r\n  }\r\n}","code":"StreamingError","type":"RUN_ERROR"}

Code Sample

using Azure.AI.Projects;
using Azure.Identity;
using Microsoft.Agents.AI.Hosting;
using Microsoft.Extensions.AI;

namespace API.Features.Rules.MafAgents;

public static class SearchRulesAgentBuilderExtensions
{
    public static WebApplicationBuilder AddRuleAssistantAIAgent(this WebApplicationBuilder builder)
    {
        string endpoint = builder.Configuration["AZURE_OPENAI_ENDPOINT"]
            ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
        string deploymentName = builder.Configuration["AZURE_OPENAI_DEPLOYMENT_NAME"]
            ?? throw new InvalidOperationException("AZURE_OPENAI_DEPLOYMENT_NAME is not set.");

        builder.Services.AddSingleton<SearchRulesAgentTool>();

        builder.AddAIAgent(
            name: "RulesAssistantAIAgent",
            (serviceProvider, key) =>
            {
                var tool = serviceProvider.GetRequiredService<SearchRulesAgentTool>();

                return new AIProjectClient(new Uri(endpoint), new DefaultAzureCredential())
                    .AsAIAgent(
                        model: deploymentName,
                        name: key,
                        instructions: @"You are an expert Business Rules Assistant.",
                        tools: [AIFunctionFactory.Create(tool.ExecuteSearchRulesTool)],
                        clientFactory: innerClient => innerClient
                            .AsBuilder()
                            .ConfigureOptions(options =>
                            {
                                // Forces gpt-5-mini to output its internal thought chain
                                options.Reasoning = new ReasoningOptions
                                {
                                    Effort = ReasoningEffort.Medium,
                                    Output = ReasoningOutput.Full
                                };
                            })
                            .Build(),
                        services: serviceProvider // Gives the tool access to scoped DI dependencies
                    );

            });

        return builder;
    }
}

Error Messages / Stack Traces

Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.AGUIServerSentEventsResult: Error: An error occurred while streaming AG-UI events

System.ClientModel.ClientResultException: HTTP 400 (ServiceError: invalid_payload)

The provided data does not match the expected schema [Request ID: caefc2e768a37cbab6286b5fda3d550c]

{
  "code": "invalid_payload",
  "message": "The provided data does not match the expected schema [Request ID: caefc2e768a37cbab6286b5fda3d550c]",
  "param": "/",
  "type": "invalid_request_error",
  "details": [],
  "additionalInfo": {
    "request_id": "caefc2e768a37cbab6286b5fda3d550c"
  }
}
   at OpenAI.ClientPipelineExtensions.ProcessMessageAsync(ClientPipeline pipeline, PipelineMessage message, RequestOptions options)
   at OpenAI.Responses.ResponsesClient.CreateResponseAsync(BinaryContent content, RequestOptions options)
   at OpenAI.Responses.ResponsesClient.<>c__DisplayClass18_0.<<CreateResponseStreamingAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at OpenAI.AsyncSseUpdateCollection`1.GetRawPagesAsync()+MoveNext()
   at OpenAI.AsyncSseUpdateCollection`1.GetRawPagesAsync()+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
   at System.ClientModel.AsyncCollectionResult`1.GetAsyncEnumerator(CancellationToken cancellationToken)+MoveNext()
   at System.ClientModel.AsyncCollectionResult`1.GetAsyncEnumerator(CancellationToken cancellationToken)+MoveNext()
   at System.ClientModel.AsyncCollectionResult`1.GetAsyncEnumerator(CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
   at Microsoft.Extensions.AI.OpenAIResponsesChatClient.FromOpenAIStreamingResponseUpdatesAsync(IAsyncEnumerable`1 streamingResponseUpdates, CreateResponseOptions options, String conversationId, String resumeResponseId, CancellationToken cancellationToken)+MoveNext()
   at Microsoft.Extensions.AI.OpenAIResponsesChatClient.FromOpenAIStreamingResponseUpdatesAsync(IAsyncEnumerable`1 streamingResponseUpdates, CreateResponseOptions options, String conversationId, String resumeResponseId, CancellationToken cancellationToken)+MoveNext()
   at Microsoft.Extensions.AI.OpenAIResponsesChatClient.FromOpenAIStreamingResponseUpdatesAsync(IAsyncEnumerable`1 streamingResponseUpdates, CreateResponseOptions options, String conversationId, String resumeResponseId, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
   at Microsoft.Extensions.AI.ConfigureOptionsChatClient.GetStreamingResponseAsync(IEnumerable`1 messages, ChatOptions options, CancellationToken cancellationToken)+MoveNext()
   at Microsoft.Extensions.AI.ConfigureOptionsChatClient.GetStreamingResponseAsync(IEnumerable`1 messages, ChatOptions options, CancellationToken cancellationToken)+MoveNext()
   at Microsoft.Extensions.AI.ConfigureOptionsChatClient.GetStreamingResponseAsync(IEnumerable`1 messages, ChatOptions options, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
   at Microsoft.Extensions.AI.FunctionInvokingChatClient.GetStreamingResponseAsync(IEnumerable`1 messages, ChatOptions options, CancellationToken cancellationToken)+MoveNext()
   at Microsoft.Extensions.AI.FunctionInvokingChatClient.GetStreamingResponseAsync(IEnumerable`1 messages, ChatOptions options, CancellationToken cancellationToken)+MoveNext()
   at Microsoft.Extensions.AI.FunctionInvokingChatClient.GetStreamingResponseAsync(IEnumerable`1 messages, ChatOptions options, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
   at Microsoft.Agents.AI.ChatClientAgent.RunCoreStreamingAsync(IEnumerable`1 messages, AgentSession session, AgentRunOptions options, CancellationToken cancellationToken)+MoveNext()
   at Microsoft.Agents.AI.ChatClientAgent.RunCoreStreamingAsync(IEnumerable`1 messages, AgentSession session, AgentRunOptions options, CancellationToken cancellationToken)+MoveNext()
   at Microsoft.Agents.AI.ChatClientAgent.RunCoreStreamingAsync(IEnumerable`1 messages, AgentSession session, AgentRunOptions options, CancellationToken cancellationToken)+MoveNext()
   at Microsoft.Agents.AI.ChatClientAgent.RunCoreStreamingAsync(IEnumerable`1 messages, AgentSession session, AgentRunOptions options, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
   at Microsoft.Agents.AI.AIAgent.RunStreamingAsync(IEnumerable`1 messages, AgentSession session, AgentRunOptions options, CancellationToken cancellationToken)+MoveNext()
   at Microsoft.Agents.AI.AIAgent.RunStreamingAsync(IEnumerable`1 messages, AgentSession session, AgentRunOptions options, CancellationToken cancellationToken)+MoveNext()
   at Microsoft.Agents.AI.AIAgent.RunStreamingAsync(IEnumerable`1 messages, AgentSession session, AgentRunOptions options, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
   at Microsoft.Agents.AI.AIAgent.RunStreamingAsync(IEnumerable`1 messages, AgentSession session, AgentRunOptions options, CancellationToken cancellationToken)+MoveNext()
   at Microsoft.Agents.AI.AIAgent.RunStreamingAsync(IEnumerable`1 messages, AgentSession session, AgentRunOptions options, CancellationToken cancellationToken)+MoveNext()
   at Microsoft.Agents.AI.AIAgent.RunStreamingAsync(IEnumerable`1 messages, AgentSession session, AgentRunOptions options, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
   at Microsoft.Agents.AI.AgentResponseExtensions.AsChatResponseUpdatesAsync(IAsyncEnumerable`1 responseUpdates)+MoveNext()
   at Microsoft.Agents.AI.AgentResponseExtensions.AsChatResponseUpdatesAsync(IAsyncEnumerable`1 responseUpdates)+MoveNext()
   at Microsoft.Agents.AI.AgentResponseExtensions.AsChatResponseUpdatesAsync(IAsyncEnumerable`1 responseUpdates)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
   at Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.AGUIChatResponseUpdateStreamExtensions.FilterServerToolsFromMixedToolInvocationsAsync(IAsyncEnumerable`1 updates, List`1 clientTools, CancellationToken cancellationToken)+MoveNext()
   at Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.AGUIChatResponseUpdateStreamExtensions.FilterServerToolsFromMixedToolInvocationsAsync(IAsyncEnumerable`1 updates, List`1 clientTools, CancellationToken cancellationToken)+MoveNext()
   at Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.AGUIChatResponseUpdateStreamExtensions.FilterServerToolsFromMixedToolInvocationsAsync(IAsyncEnumerable`1 updates, List`1 clientTools, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
   at Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.Shared.ChatResponseUpdateAGUIExtensions.AsAGUIEventStreamAsync(IAsyncEnumerable`1 updates, String threadId, String runId, JsonSerializerOptions jsonSerializerOptions, CancellationToken cancellationToken)+MoveNext()
   at Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.Shared.ChatResponseUpdateAGUIExtensions.AsAGUIEventStreamAsync(IAsyncEnumerable`1 updates, String threadId, String runId, JsonSerializerOptions jsonSerializerOptions, CancellationToken cancellationToken)+MoveNext()
   at Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.Shared.ChatResponseUpdateAGUIExtensions.AsAGUIEventStreamAsync(IAsyncEnumerable`1 updates, String threadId, String runId, JsonSerializerOptions jsonSerializerOptions, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
   at Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.AGUIEndpointRouteBuilderExtensions.SaveSessionAfterStreamingAsync(IAsyncEnumerable`1 events, AIHostAgent hostAgent, String threadId, AgentSession session, CancellationToken cancellationToken)+MoveNext()
   at Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.AGUIEndpointRouteBuilderExtensions.SaveSessionAfterStreamingAsync(IAsyncEnumerable`1 events, AIHostAgent hostAgent, String threadId, AgentSession session, CancellationToken cancellationToken)+MoveNext()
   at Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.AGUIEndpointRouteBuilderExtensions.SaveSessionAfterStreamingAsync(IAsyncEnumerable`1 events, AIHostAgent hostAgent, String threadId, AgentSession session, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
   at Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.AGUIServerSentEventsResult.WrapEventsAsSseItemsAsync(IAsyncEnumerable`1 events, CancellationToken cancellationToken)+MoveNext()
   at Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.AGUIServerSentEventsResult.WrapEventsAsSseItemsAsync(IAsyncEnumerable`1 events, CancellationToken cancellationToken)+MoveNext()
   at Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.AGUIServerSentEventsResult.WrapEventsAsSseItemsAsync(IAsyncEnumerable`1 events, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
   at System.Net.ServerSentEvents.SseFormatter.WriteAsyncCore[T](IAsyncEnumerable`1 source, Stream destination, Action`2 itemFormatter, CancellationToken cancellationToken)
   at System.Net.ServerSentEvents.SseFormatter.WriteAsyncCore[T](IAsyncEnumerable`1 source, Stream destination, Action`2 itemFormatter, CancellationToken cancellationToken)
   at Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.AGUIServerSentEventsResult.ExecuteAsync(HttpContext httpContext)

Package Versions

Microsoft.Agents.AI.Hosting.AGUI.AspNetCore: 1.11.1-preview.260625.1, Azure.AI.Projects: 2.0.1, Microsoft.Agents.AI: 1.12.0, Microsoft.Agents.AI.Abstractions: 1.12.0, Microsoft.Agents.AI.Foundry: 1.5.0

.NET Version

.NET 10

Additional Context

I am using Tanstack AI on the client and it includes the "role": "reasoning" in the Messages.

I debug Microsoft.Agents.AI.Hosting.AGUI and it change the role from reasoning to assistant. Not sure if this will help.

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETUsage: [Issues, PRs], Target: .NetreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflowtriageUsage: [Issues], Target: All issues that still need to be triaged

    Type

    Fields

    No fields configured for Bug.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions