Responses API fix

This commit is contained in:
Peer Schütt 2026-06-11 09:45:34 +02:00
parent 2da420e549
commit 8fd7e18113
2 changed files with 10 additions and 2 deletions

View File

@ -313,6 +313,10 @@ public sealed class ProviderOpenAI() : BaseProvider(LLMProviders.OPEN_AI, new Ur
var providerTools = runnableTools
.Select(x => (object)ProviderToolAdapters.ToResponsesTool(x.Definition))
.ToList();
// Keep only the minimal safe continuation state across follow-up requests.
// The Responses API requires the original function_call item together with
// the later function_call_output, but replaying all response output would
// include server-side IDs that are unavailable when store=false.
var internalItems = new List<object>();
var toolCallCount = 0;
@ -369,8 +373,8 @@ public sealed class ProviderOpenAI() : BaseProvider(LLMProviders.OPEN_AI, new Ur
await currentAssistantContent.StreamingEvent();
}
foreach (var outputItem in response.Output)
internalItems.Add(outputItem);
foreach (var functionCallItem in response.GetRawFunctionCallItems())
internalItems.Add(functionCallItem);
foreach (var functionCall in functionCalls)
{

View File

@ -27,6 +27,10 @@ public sealed record ResponsesResponse
.Where(x => !string.IsNullOrWhiteSpace(x.CallId) && !string.IsNullOrWhiteSpace(x.Name))
.ToList();
public IReadOnlyList<JsonElement> GetRawFunctionCallItems() => this.Output
.Where(x => ReadString(x, "type").Equals("function_call", StringComparison.Ordinal))
.ToList();
public string GetTextOutput()
{
if (!string.IsNullOrWhiteSpace(this.OutputText))