Skip to content

Responses protocol methods#49244

Open
jpalvarezl wants to merge 6 commits into
mainfrom
josealvar/responses-protocol-methods
Open

Responses protocol methods#49244
jpalvarezl wants to merge 6 commits into
mainfrom
josealvar/responses-protocol-methods

Conversation

@jpalvarezl
Copy link
Copy Markdown
Member

This pull request adds new protocol-style methods to both the ResponsesClient and ResponsesAsyncClient classes, 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 createResponseWithResponse and createResponseStreamWithResponse methods to ResponsesClient and ResponsesAsyncClient. These methods accept a raw JSON body (BinaryData) and OpenAI RequestOptions, and return the raw HTTP response (HttpResponseFor<Response> or HttpResponseFor<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:

  • Enabled and expanded ResponsesTests and ResponsesAsyncTests (previously disabled), adding CRUD, input-items, and background-cancel coverage for both the typed and new protocol-style methods. [1] [2]

Asset updates:

  • Updated the assets.json file to reference the latest published test recordings.

Documentation:

  • Updated the CHANGELOG.md to describe the new protocol methods and test coverage.

jpalvarezl and others added 5 commits May 22, 2026 11:42
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>
Copilot AI review requested due to automatic review settings May 22, 2026 11:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 createResponseWithResponse and createResponseStreamWithResponse to ResponsesClient and ResponsesAsyncClient to support raw JSON request bodies and raw HTTP responses.
  • Introduced OpenAIJsonHelper.jsonBodyToValueMap(BinaryData) to translate raw JSON bodies into the additionalBodyProperties format required by openai-java.
  • Re-enabled and expanded ResponsesTests / ResponsesAsyncTests, and updated assets.json + CHANGELOG.md accordingly.

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.

Comment thread sdk/ai/azure-ai-agents/src/test/java/com/azure/ai/agents/ResponsesTests.java Outdated
Comment thread sdk/ai/azure-ai-agents/src/test/java/com/azure/ai/agents/ResponsesAsyncTests.java Outdated
Comment thread sdk/ai/azure-ai-agents/src/test/java/com/azure/ai/agents/ResponsesTests.java Outdated
Comment thread sdk/ai/azure-ai-agents/src/test/java/com/azure/ai/agents/ResponsesAsyncTests.java Outdated
Comment thread sdk/ai/azure-ai-agents/src/main/java/com/azure/ai/agents/ResponsesClient.java Outdated
- 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants