.NET: [Bug]: Replying in a CopilotKit webchat with reasoning results in "System.InvalidOperationException: Unknown chat role: reasoning"

Open
#8,462 1 comment 0 reactions 1 assignee View on GitHub

@javiercn is already working on this.

Since Sep 17, 2026.

Assessment

This issue has not been assessed yet.

Description

.NET ag-ui hosting reproduced
Description

Setup:

  • Set up Harness Agent with reasoning
  • CopilotKit as webchat

Reproduction:

  • User sends first message --> Agent responds with reasoning and output
  • User sends followup message --> 500 status code from agent service
Code Sample

Program.cs

#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.
    // The Responses API variant is needed for the Reasoning field to work without a 400 Bad Request from the LLM.
    builder.Services.AddKeyedSingleton<IChatClient>("responses-chatclient", (sp, _) =>
{
    var projectClient = new AIProjectClient(foundryUri, new DefaultAzureCredential());
    var openAIClient = projectClient.GetProjectOpenAIClient();
    return openAIClient.GetResponsesClient().AsIChatClient(azureOpenAIDeploymentName);
});
#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.

Agent:

return chatClient.AsHarnessAgent(new HarnessAgentOptions
        {
            // FileAccessStore is left unset, which disables file access; leaving DisableFileMemory/DisableTodoProvider/
            // DisableAgentModeProvider false keeps their defaults, including writing to ./agent-file-memory on disk.
            Name = name,
            HarnessInstructions = Instructions,
            ChatOptions = new ChatOptions { Tools = tools, Reasoning = new() { Effort = ReasoningEffort.Medium, Output = ReasoningOutput.Summary} },
            AIContextProviders = contextProviders,
            DisableWebSearch = true,
            OpenTelemetrySourceName = GenAiSourceNames.Agents,
        });
Error Messages / Stack Traces
HTTP 500: System.InvalidOperationException: Unknown chat role: reasoning
   at AGUI.Abstractions.AGUIChatMessageExtensions.MapChatRole(String role)
   at AGUI.Abstractions.AGUIChatMessageExtensions.AsChatMessages(IEnumerable`1 aguiMessages)+MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at AGUI.Server.RunAgentInputExtensions.ToChatRequestContext(RunAgentInput input, JsonSerializerOptions jsonSerializerOptions, AGUIStreamOptions streamOptions)
   at Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.AGUIEndpointRouteBuilderExtensions.<>c__DisplayClass2_0.<<MapAGUIServer>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Http.Generated.<GeneratedRouteBuilderExtensions_g>FB87DEE35F409427C0993BF3A8E11207C78AB7E4167B350548AEB87B222E3F58E__GeneratedRouteBuilderExtensionsCore.<>c__DisplayClass2_0.<<MapPost0>g__RequestHandler|5>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|7_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
Package Versions

Microsoft.Agents.AI.Hosting.AGUI.AspNetCore: 1.21.0-preview.260911.1
Microsoft.Agents.AI.Harness: 1.21.0
@copilotkit/react-core: ^1.71.1

.NET Version

.NET 10

Additional Context

No response

Dominant language
Python
Stars
13.6k
Forks
2.3k
Avg merge
1d 20h
Merged PRs (30d)
342

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/agent-framework

All issues in microsoft/agent-framework

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.