Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
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_bb4574aecb"
"Tag": "java/ai/azure-ai-agents_8e39898979"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.azure.ai.agents.models.CreateAgentVersionInput;
import com.azure.ai.agents.models.HostedAgentDefinition;
import com.azure.ai.agents.models.ProtocolVersionRecord;
import com.azure.ai.agents.models.VersionRefIndicator;
import com.azure.core.exception.ResourceNotFoundException;
import com.azure.core.http.HttpHeaderName;
import com.azure.core.http.rest.RequestOptions;
Expand Down Expand Up @@ -50,7 +49,9 @@ static HostedAgentSessionResources createAgentAndSession(AgentsClient agentsClie
AgentVersionDetails agent = createHostedAgentVersion(agentsClient, agentName, image);
waitForAgentVersionActive(agentsClient, agentName, agent.getVersion());

AgentSessionResource session = agentsClient.createSession(agentName, new VersionRefIndicator(agent.getVersion()));
AgentSessionResource session = agentsClient.createSessionWithResponse(agentName,
BinaryData.fromObject(createSessionRequest(agent.getVersion())), foundryFeaturesRequestOptions()).getValue()
.toObject(AgentSessionResource.class);
System.out.printf("Session created (id: %s, status: %s)%n", session.getAgentSessionId(), session.getStatus());

return new HostedAgentSessionResources(agent, session);
Expand All @@ -60,7 +61,9 @@ static Mono<HostedAgentSessionResources> createAgentAndSessionAsync(AgentsAsyncC
String agentName, String image) {
return createHostedAgentVersionAsync(agentsAsyncClient, agentName, image)
.flatMap(agent -> waitForAgentVersionActiveAsync(agentsAsyncClient, agentName, agent.getVersion())
.then(agentsAsyncClient.createSession(agentName, new VersionRefIndicator(agent.getVersion())))
.then(agentsAsyncClient.createSessionWithResponse(agentName,
BinaryData.fromObject(createSessionRequest(agent.getVersion())), foundryFeaturesRequestOptions())
.map(response -> response.getValue().toObject(AgentSessionResource.class)))
.map(session -> {
System.out.printf("Session created (id: %s, status: %s)%n", session.getAgentSessionId(),
session.getStatus());
Expand All @@ -75,7 +78,8 @@ static void cleanup(AgentsClient agentsClient, String agentName, HostedAgentSess

if (resources.getSession() != null) {
try {
agentsClient.deleteSession(agentName, resources.getSession().getAgentSessionId());
agentsClient.deleteSession(agentName, resources.getSession().getAgentSessionId(),
AgentDefinitionOptInKeys.HOSTED_AGENTS_V1_PREVIEW);
System.out.printf("Session with id: %s deleted.%n", resources.getSession().getAgentSessionId());
} catch (ResourceNotFoundException ignored) {
// The sample may have already deleted the session.
Expand All @@ -101,7 +105,8 @@ static Mono<Void> cleanupAsync(AgentsAsyncClient agentsAsyncClient, String agent
Mono<Void> deleteSession = Mono.empty();
if (resources.getSession() != null) {
String sessionId = resources.getSession().getAgentSessionId();
deleteSession = agentsAsyncClient.deleteSession(agentName, sessionId)
deleteSession = agentsAsyncClient.deleteSession(agentName, sessionId,
AgentDefinitionOptInKeys.HOSTED_AGENTS_V1_PREVIEW)
.doOnSuccess(unused -> System.out.printf("Session with id: %s deleted.%n", sessionId))
.onErrorResume(ResourceNotFoundException.class, ignored -> Mono.empty());
}
Expand Down Expand Up @@ -234,6 +239,16 @@ private static RequestOptions foundryFeaturesRequestOptions() {
.setHeader(HttpHeaderName.fromString("Foundry-Features"), FOUNDRY_FEATURES_HEADER_VALUE);
}

private static Map<String, Object> createSessionRequest(String agentVersion) {
Map<String, Object> versionIndicator = new HashMap<>();
versionIndicator.put("agent_version", agentVersion);
versionIndicator.put("type", "version_ref");

Map<String, Object> request = new HashMap<>();
request.put("version_indicator", versionIndicator);
return request;
}

private static Map<String, String> sampleMetadata() {
Map<String, String> metadata = new HashMap<>();
metadata.put("enableVnextExperience", "true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.azure.ai.agents.AgentsAsyncClient;
import com.azure.ai.agents.AgentsClientBuilder;
import com.azure.ai.agents.hostedagents.HostedAgentsSampleUtils.HostedAgentSessionResources;
import com.azure.ai.agents.models.AgentDefinitionOptInKeys;
import com.azure.ai.agents.models.AgentSessionResource;
import com.azure.core.util.Configuration;
import com.azure.identity.DefaultAzureCredentialBuilder;
Expand Down Expand Up @@ -43,16 +44,19 @@ public static void main(String[] args) {
resourcesRef.set(resources);
AgentSessionResource session = resources.getSession();

return agentsAsyncClient.getSession(agentName, session.getAgentSessionId())
return agentsAsyncClient.getSession(agentName, session.getAgentSessionId(),
AgentDefinitionOptInKeys.HOSTED_AGENTS_V1_PREVIEW)
.doOnNext(fetched -> System.out.printf("Retrieved session (id: %s, status: %s)%n",
fetched.getAgentSessionId(), fetched.getStatus()))
.thenMany(agentsAsyncClient.listSessions(agentName)
.thenMany(agentsAsyncClient.listSessions(agentName,
AgentDefinitionOptInKeys.HOSTED_AGENTS_V1_PREVIEW, null, null, null, null)
.doOnSubscribe(unused -> System.out.println("Listing sessions for the agent..."))
.doOnNext(item -> System.out.printf(" - %s (status: %s)%n", item.getAgentSessionId(),
item.getStatus())))
.then(Mono.defer(() -> {
System.out.printf("Deleting session with id: %s...%n", session.getAgentSessionId());
return agentsAsyncClient.deleteSession(agentName, session.getAgentSessionId())
return agentsAsyncClient.deleteSession(agentName, session.getAgentSessionId(),
AgentDefinitionOptInKeys.HOSTED_AGENTS_V1_PREVIEW)
.doOnSuccess(unused -> System.out.printf("Session with id: %s deleted.%n",
session.getAgentSessionId()));
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.azure.ai.agents.AgentsClient;
import com.azure.ai.agents.AgentsClientBuilder;
import com.azure.ai.agents.hostedagents.HostedAgentsSampleUtils.HostedAgentSessionResources;
import com.azure.ai.agents.models.AgentDefinitionOptInKeys;
import com.azure.ai.agents.models.AgentSessionResource;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.util.Configuration;
Expand Down Expand Up @@ -38,18 +39,21 @@ public static void main(String[] args) {
resources = HostedAgentsSampleUtils.createAgentAndSession(agentsClient, agentName, image);
AgentSessionResource session = resources.getSession();

AgentSessionResource fetched = agentsClient.getSession(agentName, session.getAgentSessionId());
AgentSessionResource fetched = agentsClient.getSession(agentName, session.getAgentSessionId(),
AgentDefinitionOptInKeys.HOSTED_AGENTS_V1_PREVIEW);
System.out.printf("Retrieved session (id: %s, status: %s)%n", fetched.getAgentSessionId(),
fetched.getStatus());

System.out.println("Listing sessions for the agent...");
PagedIterable<AgentSessionResource> sessions = agentsClient.listSessions(agentName);
PagedIterable<AgentSessionResource> sessions = agentsClient.listSessions(agentName,
AgentDefinitionOptInKeys.HOSTED_AGENTS_V1_PREVIEW, null, null, null, null);
for (AgentSessionResource item : sessions) {
System.out.printf(" - %s (status: %s)%n", item.getAgentSessionId(), item.getStatus());
}

System.out.printf("Deleting session with id: %s...%n", session.getAgentSessionId());
agentsClient.deleteSession(agentName, session.getAgentSessionId());
agentsClient.deleteSession(agentName, session.getAgentSessionId(),
AgentDefinitionOptInKeys.HOSTED_AGENTS_V1_PREVIEW);
System.out.printf("Session with id: %s deleted.%n", session.getAgentSessionId());
} finally {
HostedAgentsSampleUtils.cleanup(agentsClient, agentName, resources);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ private void addTestRecordCustomSanitizers() {

ArrayList<TestProxySanitizer> sanitizers = new ArrayList<>();
sanitizers.add(new TestProxySanitizer("$..key", null, "REDACTED", TestProxySanitizerType.BODY_KEY));
sanitizers.add(new TestProxySanitizer("$..image", null, "REDACTED", TestProxySanitizerType.BODY_KEY));
sanitizers.add(new TestProxySanitizer("(?<=./)([^?]+)", "/REDACTED/", TestProxySanitizerType.URL));
sanitizers.add(new TestProxySanitizer("Content-Type",
"(^multipart\\/form-data; boundary=[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{2})",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.azure.core.http.HttpClient;
import com.azure.core.test.annotation.LiveOnly;
import com.azure.core.util.BinaryData;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand All @@ -30,6 +31,7 @@

import static com.azure.core.test.TestProxyTestBase.getHttpClients;

@Disabled("Direct code deployment is not enabled for the current test subscription.")
public class CodeAgentSamplesTests extends ClientTestBase {
private static final String DISPLAY_NAME_WITH_ARGUMENTS = "{displayName} with [{arguments}]";

Expand Down
Loading