.NET: fix: accept function approval response input#6036
Open
he-yufeng wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for typed input items (including function approval responses) to the Responses API model layer and executors, with a new unit test covering deserialization and request acceptance.
Changes:
- Extend
ResponseInputto support typedItemsin addition to text/messages, including conversion toChatMessage. - Add
FunctionApprovalResponseItemParamand wire it into JSON (de)serialization. - Update response executors to use
GetChatMessages()so typed items flow into agent execution.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/tests/Microsoft.Agents.AI.Hosting.OpenAI.UnitTests/FunctionApprovalTests.cs | Adds a unit test for function_approval_response input acceptance/deserialization. |
| dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/Models/ResponseInput.cs | Adds Items support, item→message conversions, and updates JSON converter logic. |
| dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/Models/ItemParam.cs | Introduces FunctionApprovalResponseItemParam. |
| dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/HostedAgentResponseExecutor.cs | Switches from GetInputMessages() to GetChatMessages() for typed item support. |
| dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/Converters/ItemParamConverter.cs | Adds converter mapping for function_approval_response. |
| dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/AIAgentResponseExecutor.cs | Switches from GetInputMessages() to GetChatMessages() for typed item support. |
| dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/OpenAIHostingJsonUtilities.cs | Registers FunctionApprovalResponseItemParam for source-gen JSON serialization. |
Comment on lines
+238
to
+260
| private static Dictionary<string, object?>? ParseFunctionArgumentsObject(string? arguments) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(arguments)) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| using var doc = JsonDocument.Parse(arguments); | ||
| var result = new Dictionary<string, object?>(); | ||
| foreach (JsonProperty property in doc.RootElement.EnumerateObject()) | ||
| { | ||
| result[property.Name] = property.Value.ValueKind switch | ||
| { | ||
| JsonValueKind.String => property.Value.GetString(), | ||
| JsonValueKind.Number => property.Value.GetDouble(), | ||
| JsonValueKind.True => true, | ||
| JsonValueKind.False => false, | ||
| JsonValueKind.Null => null, | ||
| _ => property.Value.GetRawText() | ||
| }; | ||
| } |
| return new ResponsesSystemMessageItemParam { Content = message.Content }; | ||
| } | ||
|
|
||
| return new ResponsesDeveloperMessageItemParam { Content = message.Content }; |
Comment on lines
+186
to
+202
| HttpClient client = await this.CreateTestServerAsync(AgentName, "You are a test agent.", string.Empty, (msg) => | ||
| [new TextContent("approval response accepted")]); | ||
|
|
||
| string requestJson = $$""" | ||
| { | ||
| "model": "gpt-4o-mini", | ||
| "input": [ | ||
| { | ||
| "type": "function_approval_response", | ||
| "approval_request_id": "{{RequestId}}", | ||
| "approve": true, | ||
| "reason": "approved in DevUI" | ||
| } | ||
| ], | ||
| "stream": true | ||
| } | ||
| """; |
Comment on lines
+125
to
+137
| if (this.Items is not null) | ||
| { | ||
| var messages = new List<InputMessage>(); | ||
| foreach (ItemParam item in this.Items) | ||
| { | ||
| if (ToInputMessage(item) is { } message) | ||
| { | ||
| messages.Add(message); | ||
| } | ||
| } | ||
|
|
||
| return messages; | ||
| } |
| /// Whether the request was approved. | ||
| /// </summary> | ||
| [JsonPropertyName("approve")] | ||
| public bool Approve { get; init; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
function_approval_responseitems in ResponsesinputarraysFixes #6006
To verify
dotnet run --project dotnet/tests/Microsoft.Agents.AI.Hosting.OpenAI.UnitTests/Microsoft.Agents.AI.Hosting.OpenAI.UnitTests.csproj --framework net10.0 -c Release --no-restore -- --filter-class Microsoft.Agents.AI.Hosting.OpenAI.UnitTests.FunctionApprovalTestsdotnet run --project dotnet/tests/Microsoft.Agents.AI.Hosting.OpenAI.UnitTests/Microsoft.Agents.AI.Hosting.OpenAI.UnitTests.csproj --framework net10.0 -c Release --no-build -- --filter-class Microsoft.Agents.AI.Hosting.OpenAI.UnitTests.OpenAIResponsesSerializationTestsgit diff --check