microsoft / microsoft/agent-framework

.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 Claimed by @javiercn View on GitHub
.NET ag-ui hosting reproduced
Dominant language
Python
Stars
13.6k
Forks
2.3k
Avg merge
2d 45m
Merged PRs (30d)
358

Description

### 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

```csharp
#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("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:
```csharp
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

```markdown
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.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Http.Generated.FB87DEE35F409427C0993BF3A8E11207C78AB7E4167B350548AEB87B222E3F58E__GeneratedRouteBuilderExtensionsCore.<>c__DisplayClass2_0.<g__RequestHandler|5>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Routing.EndpointMiddleware.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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.