Skip to content

Python: .NET: [Bug]: Missing streaming response code interpreter deltas in AIContent stream #3683

@c-t-fallon

Description

@c-t-fallon

Description

  • was expecting to have some access to the code interpreter reasoning stream from the Contents collection

  • see code below

  • in the debugging screenshot, you can see when i hit the raw delta object, the Contents object is empty

  • in the code output screenshot, you can see that the TextReasoningContent dont contain any of the code from the raw objects

https://github.com/c-t-fallon/ErrorResponseDemo/blob/main/CodeInterpreterReasoningResponseStreaming/Program.cs

Image Image

Code Sample

#pragma warning disable OPENAI001

using Microsoft.Extensions.AI;
using Microsoft.Extensions.Configuration;
using OpenAI;
using OpenAI.Responses;
using System.ClientModel;
using System.Text;

var config = new ConfigurationBuilder()
    .AddUserSecrets<Program>()
    .Build();

var cred = new ApiKeyCredential(config["OpenAIAPIKey"]);
var openAIClient = new OpenAIClient(cred);

var agent = openAIClient
    .GetResponsesClient("gpt-5")
    .AsIChatClient()
    .AsBuilder()
    .ConfigureOptions(options =>
    {
        options.Tools = [new HostedCodeInterpreterTool()];
        options.RawRepresentationFactory = _ => new CreateResponseOptions()
        {
            ReasoningOptions = new ResponseReasoningOptions()
            {
                ReasoningEffortLevel = "medium",
                ReasoningSummaryVerbosity = "detailed"
            }
        };
    })
    .Build()
    .AsAIAgent();

var message = "Write and execute a simple, arbitrary python script with code interpreter.";

var reasoningCodeInterpreterResponse = new StringBuilder();
var reasoningContent = new StringBuilder();

Console.WriteLine("AIContent objects types received:");
Console.WriteLine("---------------------------------");

await foreach (var update in agent.RunStreamingAsync(message))
{
    switch (update.RawRepresentation)
    {
        case ChatResponseUpdate chatResponseUpdate:
            switch (chatResponseUpdate.RawRepresentation)
            {
                case StreamingResponseCodeInterpreterCallCodeDeltaUpdate delta:
                    reasoningCodeInterpreterResponse.Append(delta.Delta);
                    break;
                default:
                    break;
            }
            break;
    }

    foreach (var content in update.Contents)
    {
        Console.WriteLine(content.GetType().FullName);

        switch (content)
        {
            case TextReasoningContent textContent:
                reasoningContent.Append(textContent.Text);
                break;
        }
    }
}

Console.WriteLine();
Console.WriteLine("Code Interpreter Response:");
Console.WriteLine("--------------------------");
Console.WriteLine(reasoningCodeInterpreterResponse.ToString());
Console.WriteLine();
Console.WriteLine("Reasoning Response:");
Console.WriteLine("-------------------");
Console.WriteLine(reasoningContent.ToString());

Error Messages / Stack Traces

Package Versions

Microsoft.Agents.AI (1.0.0-preview.260128.1), Microsoft.Agents.AI.OpenAI (1.0.0-preview.260128.1)

.NET Version

.NET 8.0

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions