Skip to content

.Net: Bug: Unable to get Reasoning Summary/Detail when using ChatClient with Reasoning model #13054

@MustafaJamal

Description

@MustafaJamal

Describe the bug
Unable to get Reasoning Summary/Detail when using ChatClient with Reasoning model.

To Reproduce

Here is code:

ChatOptions chatOptions = new ChatOptions()
{
    //AllowMultipleToolCalls = useFunctionCall,
    ToolMode = useFunctionCall ? ChatToolMode.Auto : ChatToolMode.None,
    Temperature = (reasoningEffort == null || reasoningEffort == string.Empty) ? (float?)temperature : null,
    ResponseFormat = convertToJSON == true
        ? ChatResponseFormat.Json : ChatResponseFormat.Text,
    FrequencyPenalty = 0,
    PresencePenalty = 0,
    Tools = tools,
};

chatOptions.AdditionalProperties = new AdditionalPropertiesDictionary();

if (!string.IsNullOrWhiteSpace(verbosity))
{
    chatOptions.AdditionalProperties["text"] = new Dictionary<string, object?>()
    {
        { "verbosity", verbosity }
    };
}

if (!string.IsNullOrEmpty(reasoningEffort))
{
    chatOptions.AdditionalProperties["reasoning"] = new Dictionary<string, object?>()
    {
        { "effort", reasoningEffort },
        {"summary", "auto"}
    };
}

///////////

 await foreach (ChatResponseUpdate c in chatSvc.GetStreamingResponseAsync(hist, chatOptions,
                    cancellationToken: cancellationToken))
 {
     bool hadReasoning = false;

     foreach (TextReasoningContent textContent in c.Contents.OfType<TextReasoningContent>()) // <<<<<----- THIS CONDITION NEVER MEETS
     {
         hadReasoning = true;
         string reasoning = $"##{textContent.Text}";
         full += reasoning;
         yield return reasoning;
     }

     if (hadReasoning)
     {
         continue;
     }

     if (!string.IsNullOrEmpty(c.Text))
     {
         full += c.Text;
         yield return c.Text;
     }

     foreach (UsageContent usageContent in c.Contents.OfType<UsageContent>())
     {
         _usageDetails = usageContent.Details;
     }

     foreach (AIContent aiContent in c.Contents)
     {
         if (aiContent is FunctionCallContent functionCallContent) 
         {
             var (pluginName, functionName) = CoPilot.Utility.ParseFunctionName(functionCallContent.Name);
             KernelArguments kargs = CoPilot.Utility.BuildKernelArguments(functionCallContent.Arguments);

             string invocationResult;
             try
             {
                 invocationResult = await CoPilot.Utility.TryInvokeKernelFunctionAsync(kernel, pluginName,
                     functionName, kargs, cancellationToken);
             }
             catch (OperationCanceledException)
             {
                 throw;
             }
             catch (Exception ex)
             {
                 _logger.LogError(ex, "Error invoking function {FunctionFullName}", functionCallContent.Name);
                 invocationResult = $"Error invoking function {functionCallContent.Name}: {ex.Message}";
             }

             try
             {
                 CoPilot.Utility.AppendToolResultToHistory(hist, invocationResult);
             }
             catch (Exception ex)
             {
                 _logger.LogError(ex, "Failed to append tool result to chat history for {FunctionName}",
                     functionCallContent.Name);
                 hist.Add(new ChatMessage(ChatRole.Tool, invocationResult));
             }
         }
     }
 }

I have used o3, gpt-5, models but none of them giving reasoning summary.

Assembly versions:

Microsoft.SemanticKernel v1.63.0
Microsoft.SemanticKernel.Connectors.AzureOpenAI v1.63.0
Microsoft.SemanticKernel.Connectors.OpenAI v1.63.0
Environment: C# ASP.NET Core 8
OS: Windows 11

Let me know if further details are needed.

Thanks,
Mustafa

Metadata

Metadata

Assignees

Labels

.NETIssue or Pull requests regarding .NET codeai connectorAnything related to AI connectorsblocked externalThis item is blocked due to an external dependency that needs to be addressedbugSomething isn't working

Type

Projects

Status

Bug

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions