Responses protocol methods#49244
Open
jpalvarezl wants to merge 6 commits into
Open
Conversation
Adds BinaryData + com.openai.core.RequestOptions protocol-style methods on the Responses sync and async clients that delegate to the openai-java ResponseService.withRawResponse() / ResponseServiceAsync.withRawResponse() surface and return the openai-java raw HTTP response types directly. Specifically: - createResponseWithResponse / createResponseStreamWithResponse - getResponseWithResponse - deleteResponseWithResponse - cancelResponseWithResponse The async variants wrap the underlying CompletableFuture in Mono.fromFuture(...). All methods continue to flow through the Azure HTTP pipeline via HttpClientHelper.mapToOpenAIHttpClient. Adds OpenAIJsonHelper.jsonBodyToValueMap(BinaryData) helper used by the create methods to forward the raw JSON body verbatim through ResponseCreateParams.Builder.additionalBodyProperties. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Mirrors the existing basicCRUDOperations tests against the new createResponseWithResponse protocol methods (BinaryData + RequestOptions), parses the returned HttpResponseFor<Response>, and asserts on the same shape (non-null Response with an id) as the typed-method tests. Tests remain @disabled pending public preview recordings, consistent with the existing typed tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…items coverage Cleanup, expansion, and enablement of ResponsesTests and ResponsesAsyncTests: 1. Removed the stale '// currently returning 500' comments and the orphan getOpenAIClient() pseudo-code blocks from the initial Agents V2 commit (PR #47134). Live calls against the service confirmed all four previously-flagged endpoints (retrieve, delete, cancel, input_items) now return 200. 2. Expanded both typed and protocol-method tests to actually exercise the full surface: create -> retrieve -> input_items -> delete in basicCRUDOperations, plus a separate cancelBackgroundResponse / cancelBackgroundResponseWithResponse that creates a background:true response and cancels it (asserting CANCELLED or COMPLETED, since the response may finish before cancel hits). 4 test methods per class (sync + async) x 2 surfaces = 8 tests total. 3. Dropped the class-level @disabled annotations now that recordings exist. Captured live recordings via AZURE_TEST_MODE=RECORD against the Foundry endpoint, pushed via 'test-proxy push -a assets.json' to Azure/azure-sdk-assets, and bumped the assets.json Tag to java/ai/azure-ai-agents_7a1b5ec037. Verified by re-running in default (playback) mode: all 8 tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Drop the getResponseWithResponse, deleteResponseWithResponse, and cancelResponseWithResponse protocol methods added previously. The ResponsesClient/ResponsesAsyncClient surface now exposes protocol-method variants only for createAzureResponse and createStreamingAzureResponse, matching the original typed surface. Tests: - Trim basicCRUDOperationsWithResponse to exercise createResponseWithResponse only. - Add basicStreamingOperationsWithResponse to cover createResponseStreamWithResponse. - Drop cancelBackgroundResponseWithResponse. - Re-recorded affected sessions; bumped assets.json tag. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ResponsesClient and ResponsesAsyncClient are thin Azure-aware wrappers, so non-Azure operations (retrieve, delete, cancel) should go through the underlying com.openai client directly rather than the wrappers' service getters. Adds getResponseServiceSyncClient/getResponseServiceAsyncClient helpers in ClientTestBase that build the OpenAIClient/OpenAIClientAsync and expose .responses(). Updates basicCRUDOperations and cancelBackgroundResponse in both test classes to use the new helpers for retrieve/delete/cancel; create still flows through ResponsesClient. Recordings unchanged (the OpenAI client built by AgentsClientBuilder shares the same Azure HTTP pipeline as the wrappers' service). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends azure-ai-agents Responses clients with protocol-style APIs that accept a raw JSON request (BinaryData) and return the underlying openai-java raw HTTP response, while also enabling and expanding recordings-backed test coverage for both typed and protocol surfaces.
Changes:
- Added
createResponseWithResponseandcreateResponseStreamWithResponsetoResponsesClientandResponsesAsyncClientto support raw JSON request bodies and raw HTTP responses. - Introduced
OpenAIJsonHelper.jsonBodyToValueMap(BinaryData)to translate raw JSON bodies into theadditionalBodyPropertiesformat required by openai-java. - Re-enabled and expanded
ResponsesTests/ResponsesAsyncTests, and updatedassets.json+CHANGELOG.mdaccordingly.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/ai/azure-ai-agents/src/main/java/com/azure/ai/agents/ResponsesClient.java | Adds sync protocol-style “raw JSON in / raw HTTP response out” APIs for Responses. |
| sdk/ai/azure-ai-agents/src/main/java/com/azure/ai/agents/ResponsesAsyncClient.java | Adds async equivalents of the new protocol-style APIs. |
| sdk/ai/azure-ai-agents/src/main/java/com/azure/ai/agents/implementation/OpenAIJsonHelper.java | Adds helper to parse raw JSON request bodies into Map<String, JsonValue> for openai-java builders. |
| sdk/ai/azure-ai-agents/src/test/java/com/azure/ai/agents/ClientTestBase.java | Adds helpers to build openai-java ResponseService clients used in tests. |
| sdk/ai/azure-ai-agents/src/test/java/com/azure/ai/agents/ResponsesTests.java | Enables and expands sync tests for typed CRUD/input-items/cancel and protocol raw-response methods. |
| sdk/ai/azure-ai-agents/src/test/java/com/azure/ai/agents/ResponsesAsyncTests.java | Enables and expands async tests for typed CRUD/input-items/cancel and protocol raw-response methods. |
| sdk/ai/azure-ai-agents/CHANGELOG.md | Documents the new protocol methods and test enablement. |
| sdk/ai/azure-ai-agents/assets.json | Updates the assets tag to point at the new recordings. |
- Reword JavaDoc on createResponseWithResponse in both clients to clarify the JSON body is forwarded semantically (parsed and re-serialized via additionalBodyProperties), not byte-for-byte, since property ordering may change and duplicate top-level keys are not preserved. - Apply the same clarification to the streaming variant JavaDoc. - Wrap HttpResponseFor<Response> in try-with-resources in basicCRUDOperationsWithResponse for both sync and async test classes so the response is reliably closed. - Remove unused CREATE_BACKGROUND_RESPONSE_BODY constant in both test classes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
This pull request adds new protocol-style methods to both the
ResponsesClientandResponsesAsyncClientclasses, enabling users to send raw JSON request bodies and receive raw HTTP responses. It also enables and expands test coverage for these new methods and the existing typed surfaces, and updates asset references accordingly.Protocol method additions:
Added
createResponseWithResponseandcreateResponseStreamWithResponsemethods toResponsesClientandResponsesAsyncClient. These methods accept a raw JSON body (BinaryData) and OpenAIRequestOptions, and return the raw HTTP response (HttpResponseFor<Response>orHttpResponseFor<StreamResponse<ResponseStreamEvent>>). This allows advanced scenarios, such as including Azure-specific extensions, without relying on the strongly-typed builder. [1] [2] [3]Introduced the
OpenAIJsonHelper.jsonBodyToValueMap(BinaryData)utility method to convert raw JSON request bodies into the map format required by the OpenAI Java SDK.Test enhancements:
ResponsesTestsandResponsesAsyncTests(previously disabled), adding CRUD, input-items, and background-cancel coverage for both the typed and new protocol-style methods. [1] [2]Asset updates:
assets.jsonfile to reference the latest published test recordings.Documentation:
CHANGELOG.mdto describe the new protocol methods and test coverage.