Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
89496d3
Porting over changes from private repo
jpalvarezl Dec 2, 2025
eca457f
formatting
jpalvarezl Dec 2, 2025
954ba7d
Update sdk/ai/azure-ai-agents/src/main/java/com/azure/ai/agents/imple…
jpalvarezl Dec 3, 2025
4df3dba
Update sdk/ai/azure-ai-agents/src/main/java/com/azure/ai/agents/imple…
jpalvarezl Dec 3, 2025
385e9b5
Formatting mismatch
jpalvarezl Dec 3, 2025
0957fd2
Add async and error propagation test coverage for PolicyDecoratingHtt…
Copilot Dec 3, 2025
d113cc2
Add error handling tests for HttpClientHelper (#47428)
Copilot Dec 3, 2025
224e3fb
Merged and improved assertions
jpalvarezl Dec 3, 2025
672a6df
More PR feedback
jpalvarezl Dec 3, 2025
d4505e6
More PR feedback
jpalvarezl Dec 3, 2025
bf085da
More PR feedback
jpalvarezl Dec 3, 2025
226c2c0
lazy mapping of types for the AzureHttpResponseAdapter
jpalvarezl Dec 4, 2025
7c95643
Simplified mapping
jpalvarezl Dec 4, 2025
867d0d6
Always using default httpPipeline
jpalvarezl Dec 5, 2025
6bf38b7
Using bare minimum code
jpalvarezl Dec 5, 2025
7c1b414
WIP: removing redundant code. Using default httpPipeline
jpalvarezl Dec 5, 2025
96153b7
fix async tests
srnagar Dec 9, 2025
a4e5c29
Code style checks
jpalvarezl Dec 10, 2025
8e760a9
Added recording for async test
jpalvarezl Dec 10, 2025
94b0797
Merge branch 'main' into feature/stainless_httpclient_instrumentation
jpalvarezl Dec 11, 2025
b4bbdd3
Enabled sync tests and update assets
jpalvarezl Dec 11, 2025
b9a37e8
Updated test suite and restored value for context config
jpalvarezl Dec 11, 2025
ce40dab
Using latest version of azure-core-test
jpalvarezl Dec 11, 2025
a53bbd1
Forwarding request timeout and adding more custom machters for tests
jpalvarezl Dec 11, 2025
d9293fa
reassign addData result
jpalvarezl Dec 11, 2025
27aa57f
WIP: timeout tests
jpalvarezl Dec 11, 2025
edcf29d
Timeout tests are run only in Live test mode
jpalvarezl Dec 11, 2025
28d3d6e
Test asset update
jpalvarezl Dec 11, 2025
275e2e9
Exceptions are allowed to propagate upwards
jpalvarezl Dec 11, 2025
8c77862
Error mapping in place
jpalvarezl Dec 11, 2025
2fcfb4d
reformat
jpalvarezl Dec 11, 2025
f4206bb
Format
jpalvarezl Dec 11, 2025
67c9970
Fixed timeout tests
jpalvarezl Dec 11, 2025
38694bb
PR feedback 1st round
jpalvarezl Dec 12, 2025
6967620
PR feedback round 2: pom updates
jpalvarezl Dec 12, 2025
41ca65d
dependency tag fixed and disabled test
jpalvarezl Dec 12, 2025
f0fc0ed
Disabled flacky timeout tests
jpalvarezl Dec 12, 2025
ad2d539
Disabled one more test
jpalvarezl Dec 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eng/versioning/version_client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ io.clientcore:optional-dependency-tests;1.0.0-beta.1;1.0.0-beta.1

unreleased_com.azure:azure-data-appconfiguration;1.9.0-beta.1
unreleased_com.azure.v2:azure-core;2.0.0-beta.1
unreleased_com.azure:azure-core-test;1.27.0-beta.14
unreleased_com.azure.v2:azure-identity;2.0.0-beta.1
unreleased_com.azure.v2:azure-data-appconfiguration;2.0.0-beta.1
unreleased_io.clientcore:http-netty4;1.0.0-beta.1
Expand Down
5 changes: 3 additions & 2 deletions sdk/agrifood/azure-verticals-agrifood-farming/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ Farm hierarchy is a collection of below entities.

```java readme-sample-createFarmHierarchy
// Create Party
JSONObject object = new JSONObject().appendField("name", "party1");
BinaryData party = BinaryData.fromObject(object);
Map<String, String> partyData = new HashMap<>();
partyData.put("name", "party1");
BinaryData party = BinaryData.fromObject(partyData);
partiesClient.createOrUpdateWithResponse("contoso-party", party, null).block();

// Get Party
Expand Down
2 changes: 1 addition & 1 deletion sdk/ai/azure-ai-agents/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/ai/azure-ai-agents",
"Tag": "java/ai/azure-ai-agents_ca2ca780eb"
"Tag": "java/ai/azure-ai-agents_3f32cd8dff"
}
8 changes: 7 additions & 1 deletion sdk/ai/azure-ai-agents/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.27.0-beta.13</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<version>1.27.0-beta.14</version> <!-- {x-version-update;unreleased_com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-http-okhttp</artifactId>
<version>1.13.2</version> <!-- {x-version-update;com.azure:azure-core-http-okhttp;dependency} -->
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.azure.ai.agents.implementation.AgentsClientImpl;
import com.azure.ai.agents.implementation.TokenUtils;
import com.azure.ai.agents.implementation.http.HttpClientHelper;
import com.azure.core.annotation.Generated;
import com.azure.core.annotation.ServiceClientBuilder;
import com.azure.core.client.traits.ConfigurationTrait;
Expand Down Expand Up @@ -32,7 +33,6 @@
import com.azure.core.util.ClientOptions;
import com.azure.core.util.Configuration;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.UserAgentUtil;
import com.azure.core.util.builder.ClientBuilderUtil;
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.serializer.JacksonAdapter;
Expand All @@ -41,7 +41,7 @@
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.client.okhttp.OpenAIOkHttpClientAsync;
import com.openai.credential.BearerTokenCredential;
import java.time.Duration;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -328,7 +328,9 @@ private HttpPipeline createHttpPipeline() {
* @return an instance of ConversationsAsyncClient.
*/
public ConversationsAsyncClient buildConversationsAsyncClient() {
return new ConversationsAsyncClient(getOpenAIAsyncClientBuilder().build());
return new ConversationsAsyncClient(getOpenAIAsyncClientBuilder().build()
.withOptions(optionBuilder -> optionBuilder
.httpClient(HttpClientHelper.mapToOpenAIHttpClient(createHttpPipeline()))));
}

/**
Expand All @@ -337,7 +339,9 @@ public ConversationsAsyncClient buildConversationsAsyncClient() {
* @return an instance of ConversationsClient.
*/
public ConversationsClient buildConversationsClient() {
return new ConversationsClient(getOpenAIClientBuilder().build());
return new ConversationsClient(getOpenAIClientBuilder().build()
.withOptions(optionBuilder -> optionBuilder
.httpClient(HttpClientHelper.mapToOpenAIHttpClient(createHttpPipeline()))));
}

/**
Expand All @@ -346,8 +350,9 @@ public ConversationsClient buildConversationsClient() {
* @return an instance of ResponsesClient
*/
public ResponsesClient buildResponsesClient() {
OpenAIOkHttpClient.Builder builder = getOpenAIClientBuilder();
return new ResponsesClient(builder.build());
return new ResponsesClient(getOpenAIClientBuilder().build()
.withOptions(optionBuilder -> optionBuilder
.httpClient(HttpClientHelper.mapToOpenAIHttpClient(createHttpPipeline()))));
}

/**
Expand All @@ -356,20 +361,22 @@ public ResponsesClient buildResponsesClient() {
* @return an instance of ResponsesAsyncClient
*/
public ResponsesAsyncClient buildResponsesAsyncClient() {
return new ResponsesAsyncClient(getOpenAIAsyncClientBuilder().build());
return new ResponsesAsyncClient(getOpenAIAsyncClientBuilder().build()
.withOptions(optionBuilder -> optionBuilder
.httpClient(HttpClientHelper.mapToOpenAIHttpClient(createHttpPipeline()))));
}

private OpenAIOkHttpClient.Builder getOpenAIClientBuilder() {
OpenAIOkHttpClient.Builder builder = OpenAIOkHttpClient.builder()
.credential(
BearerTokenCredential.create(TokenUtils.getBearerTokenSupplier(this.tokenCredential, DEFAULT_SCOPES)));
builder.baseUrl(this.endpoint + (this.endpoint.endsWith("/") ? "openai" : "/openai"));
builder.replaceHeaders("User-Agent", getUserAgent());
if (this.serviceVersion != null) {
builder.azureServiceVersion(AzureOpenAIServiceVersion.fromString(this.serviceVersion.getVersion()));
builder.azureUrlPathMode(AzureUrlPathMode.UNIFIED);
}
builder.timeout(Duration.ofSeconds(30));
// We set the builder retries to 0 to avoid conflicts with the retry policy added through the HttpPipeline.
builder.maxRetries(0);
return builder;
}

Expand All @@ -378,24 +385,15 @@ private OpenAIOkHttpClientAsync.Builder getOpenAIAsyncClientBuilder() {
.credential(
BearerTokenCredential.create(TokenUtils.getBearerTokenSupplier(this.tokenCredential, DEFAULT_SCOPES)));
builder.baseUrl(this.endpoint + (this.endpoint.endsWith("/") ? "openai" : "/openai"));
builder.replaceHeaders("User-Agent", getUserAgent());
if (this.serviceVersion != null) {
builder.azureServiceVersion(AzureOpenAIServiceVersion.fromString(this.serviceVersion.getVersion()));
builder.azureUrlPath(AzureUrlPathMode.UNIFIED);
}
builder.timeout(Duration.ofSeconds(30));
// We set the builder retries to 0 to avoid conflicts with the retry policy added through the HttpPipeline.
builder.maxRetries(0);
return builder;
}

private String getUserAgent() {
HttpLogOptions localHttpLogOptions = this.httpLogOptions == null ? new HttpLogOptions() : this.httpLogOptions;
ClientOptions localClientOptions = this.clientOptions == null ? new ClientOptions() : this.clientOptions;
String sdkName = PROPERTIES.getOrDefault(SDK_NAME, "UnknownName");
String sdkVersion = PROPERTIES.getOrDefault(SDK_VERSION, "UnknownVersion");
String applicationId = CoreUtils.getApplicationId(localClientOptions, localHttpLogOptions);
return UserAgentUtil.toUserAgentString(applicationId, sdkName, sdkVersion, configuration);
}

private static final ClientLogger LOGGER = new ClientLogger(AgentsClientBuilder.class);

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.ai.agents.implementation.http;

import com.azure.core.http.HttpHeader;
import com.azure.core.http.HttpHeaders;
import com.azure.core.util.logging.ClientLogger;
import com.openai.core.http.Headers;
import com.openai.core.http.HttpResponse;

import java.io.InputStream;

/**
* Adapter that exposes an Azure {@link com.azure.core.http.HttpResponse} as an OpenAI {@link HttpResponse}. This keeps
* the translation logic encapsulated so response handling elsewhere can remain framework agnostic.
*/
final class AzureHttpResponseAdapter implements HttpResponse {

private static final ClientLogger LOGGER = new ClientLogger(AzureHttpResponseAdapter.class);

private final com.azure.core.http.HttpResponse azureResponse;

/**
* Creates a new adapter instance for the provided Azure response.
*
* @param azureResponse Response returned by the Azure pipeline.
*/
AzureHttpResponseAdapter(com.azure.core.http.HttpResponse azureResponse) {
this.azureResponse = azureResponse;
}

@Override
public int statusCode() {
return azureResponse.getStatusCode();
}

@Override
public Headers headers() {
return toOpenAiHeaders(azureResponse.getHeaders());
}

@Override
public InputStream body() {
return azureResponse.getBodyAsBinaryData().toStream();
}

@Override
public void close() {
azureResponse.close();
}

/**
* Copies headers from the Azure response into the immutable OpenAI {@link Headers} collection.
*/
private static Headers toOpenAiHeaders(HttpHeaders httpHeaders) {
Headers.Builder builder = Headers.builder();
for (HttpHeader header : httpHeaders) {
builder.put(header.getName(), header.getValuesList());
}
return builder.build();
}
}
Loading