diff --git a/sdk/ai/azure-ai-agents/src/main/java/com/azure/ai/agents/AgentsClient.java b/sdk/ai/azure-ai-agents/src/main/java/com/azure/ai/agents/AgentsClient.java index 3861935fae9f..f3c1f491b205 100644 --- a/sdk/ai/azure-ai-agents/src/main/java/com/azure/ai/agents/AgentsClient.java +++ b/sdk/ai/azure-ai-agents/src/main/java/com/azure/ai/agents/AgentsClient.java @@ -46,6 +46,13 @@ import com.azure.core.util.BinaryData; import com.azure.core.util.IterableStream; import com.openai.models.conversations.Conversation; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Map; /** @@ -62,7 +69,7 @@ public final class AgentsClient { * * Retrieves an agent definition by its unique name. *

Response Body Schema

- * + * *
      * {@code
      * {
@@ -162,7 +169,7 @@ public Response getAgentWithResponse(String agentName, RequestOption
      *
      * Creates a new version for the specified agent and returns the created version resource.
      * 

Request Body Schema

- * + * *
      * {@code
      * {
@@ -182,9 +189,9 @@ public Response getAgentWithResponse(String agentName, RequestOption
      * }
      * }
      * 
- * + * *

Response Body Schema

- * + * *
      * {@code
      * {
@@ -309,7 +316,7 @@ public void deleteAgentVersion(String agentName, String agentVersion) {
      * 
      * You can add these to a request with {@link RequestOptions#addQueryParam}
      * 

Response Body Schema

- * + * *
      * {@code
      * {
@@ -458,7 +465,7 @@ public AgentVersionDetails createAgentVersion(String agentName, AgentDefinition
      *
      * Creates a new agent or a new version of an existing agent.
      * 

Request Body Schema

- * + * *
      * {@code
      * {
@@ -515,9 +522,9 @@ public AgentVersionDetails createAgentVersion(String agentName, AgentDefinition
      * }
      * }
      * 
- * + * *

Response Body Schema

- * + * *
      * {@code
      * {
@@ -616,7 +623,7 @@ Response createAgentWithResponse(BinaryData createAgentRequest, Requ
      * Updates the agent by adding a new version if there are any changes to the agent definition.
      * If no changes, returns the existing agent version.
      * 

Request Body Schema

- * + * *
      * {@code
      * {
@@ -636,9 +643,9 @@ Response createAgentWithResponse(BinaryData createAgentRequest, Requ
      * }
      * }
      * 
- * + * *

Response Body Schema

- * + * *
      * {@code
      * {
@@ -775,7 +782,7 @@ AgentDetails updateAgent(String agentName, AgentDefinition definition) {
      *
      * Imports the provided manifest to create an agent and returns the created resource.
      * 

Request Body Schema

- * + * *
      * {@code
      * {
@@ -791,9 +798,9 @@ AgentDetails updateAgent(String agentName, AgentDefinition definition) {
      * }
      * }
      * 
- * + * *

Response Body Schema

- * + * *
      * {@code
      * {
@@ -893,7 +900,7 @@ Response createAgentFromManifestWithResponse(BinaryData createAgentF
      * Updates the agent from a manifest by adding a new version if there are any changes to the agent definition.
      * If no changes, returns the existing agent version.
      * 

Request Body Schema

- * + * *
      * {@code
      * {
@@ -908,9 +915,9 @@ Response createAgentFromManifestWithResponse(BinaryData createAgentF
      * }
      * }
      * 
- * + * *

Response Body Schema

- * + * *
      * {@code
      * {
@@ -1011,7 +1018,7 @@ Response updateAgentFromManifestWithResponse(String agentName,
      *
      * Imports the provided manifest to create a new version for the specified agent.
      * 

Request Body Schema

- * + * *
      * {@code
      * {
@@ -1026,9 +1033,9 @@ Response updateAgentFromManifestWithResponse(String agentName,
      * }
      * }
      * 
- * + * *

Response Body Schema

- * + * *
      * {@code
      * {
@@ -1258,7 +1265,7 @@ public AgentVersionDetails createAgentVersionFromManifest(String agentName, Stri
      *
      * Retrieves the specified version of an agent by its agent name and version identifier.
      * 

Response Body Schema

- * + * *
      * {@code
      * {
@@ -1457,7 +1464,7 @@ public PagedIterable listAgentVersions(String agentName, In
      * 
      * You can add these to a request with {@link RequestOptions#addQueryParam}
      * 

Response Body Schema

- * + * *
      * {@code
      * {
@@ -1626,7 +1633,7 @@ AgentDetails createAgentFromManifest(String agentName, String manifestId, Map
      * You can add these to a request with {@link RequestOptions#addHeader}
      * 

Response Body Schema

- * + * *
      * {@code
      * {
@@ -1735,7 +1742,7 @@ public Response deleteAgentWithResponse(String agentName, RequestOptions r
      * 
      * You can add these to a request with {@link RequestOptions#addQueryParam}
      * 

Response Body Schema

- * + * *
      * {@code
      * {
@@ -1776,7 +1783,7 @@ Response internalDeleteAgentWithResponse(String agentName, RequestOp
      * 
      * You can add these to a request with {@link RequestOptions#addQueryParam}
      * 

Response Body Schema

- * + * *
      * {@code
      * {
@@ -2054,7 +2061,7 @@ AgentDetails updateAgent(String agentName, AgentDefinition definition, MapResponse Body Schema

- * + * *
      * {@code
      * {
@@ -2163,7 +2170,7 @@ Response createAgentFromCodeWithResponse(String agentName, String co
      * irrelevant).
      * Maximum upload size is 250 MB.
      * 

Response Body Schema

- * + * *
      * {@code
      * {
@@ -2270,7 +2277,7 @@ Response updateAgentFromCodeWithResponse(String agentName, String co
      *
      * Applies a merge-patch update to the specified agent endpoint configuration.
      * 

Request Body Schema

- * + * *
      * {@code
      * {
@@ -2312,9 +2319,9 @@ Response updateAgentFromCodeWithResponse(String agentName, String co
      * }
      * }
      * 
- * + * *

Response Body Schema

- * + * *
      * {@code
      * {
@@ -2421,7 +2428,7 @@ public Response updateAgentDetailsWithResponse(String agentName, Bin
      * irrelevant).
      * Maximum upload size is 250 MB.
      * 

Response Body Schema

- * + * *
      * {@code
      * {
@@ -2499,7 +2506,7 @@ Response createAgentVersionFromCodeWithResponse(String agentName, St
      * 
      * You can add these to a request with {@link RequestOptions#addQueryParam}
      * 

Response Body Schema

- * + * *
      * {@code
      * BinaryData
@@ -2520,6 +2527,51 @@ public Response downloadAgentCodeWithResponse(String agentName, Requ
         return this.serviceClient.downloadAgentCodeWithResponse(agentName, requestOptions);
     }
 
+    /**
+     * Download agent code
+     *
+     * Downloads the code zip for a code-based hosted agent.
+     * Returns the previously-uploaded zip (`application/zip`).
+     *
+     * If `agent_version` is supplied, returns that version's code zip; otherwise
+     * returns the latest version's code zip.
+     *
+     * The SHA-256 digest of the returned bytes matches the `content_hash` on the
+     * resolved version's `code_configuration`.
+     * 

Query Parameters

+ * + * + * + * + *
Query Parameters
NameTypeRequiredDescription
agent_versionStringNoThe version of the agent whose code zip should be + * downloaded. + * If omitted, the latest version's code zip is returned.
+ * You can add these to a request with {@link RequestOptions#addQueryParam} + *

Response Body Schema

+ * + *
+     * {@code
+     * BinaryData
+     * }
+     * 
+ * + * @param agentName The name of the agent. + * @param filePath The path to the file where the downloaded code zip will be saved. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response downloadAgentCodeWithResponse(String agentName, Path filePath, RequestOptions requestOptions) + throws IOException { + Response response = this.serviceClient.downloadAgentCodeWithResponse(agentName, requestOptions); + response.getValue().writeTo(new FileOutputStream(filePath.toFile())); + return new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), null); + } + /** * Create a session * @@ -2535,7 +2587,7 @@ public Response downloadAgentCodeWithResponse(String agentName, Requ * * You can add these to a request with {@link RequestOptions#addHeader} *

Request Body Schema

- * + * *
      * {@code
      * {
@@ -2546,9 +2598,9 @@ public Response downloadAgentCodeWithResponse(String agentName, Requ
      * }
      * }
      * 
- * + * *

Response Body Schema

- * + * *
      * {@code
      * {
@@ -2594,7 +2646,7 @@ public Response createSessionWithResponse(String agentName, BinaryDa
      * 
      * You can add these to a request with {@link RequestOptions#addHeader}
      * 

Response Body Schema

- * + * *
      * {@code
      * {
@@ -2710,7 +2762,7 @@ public Response stopSessionWithResponse(String agentName, String sessionId
      * 
      * You can add these to a request with {@link RequestOptions#addHeader}
      * 

Response Body Schema

- * + * *
      * {@code
      * {
@@ -2771,7 +2823,7 @@ public PagedIterable listSessions(String agentName, RequestOptions r
      * The stream remains open until the client disconnects or the server
      * terminates the connection. Clients should handle reconnection as needed.
      * 

Response Body Schema

- * + * *
      * {@code
      * {
@@ -2815,15 +2867,15 @@ public Response getSessionLogStreamWithResponse(String agentName, St
      * 
      * You can add these to a request with {@link RequestOptions#addHeader}
      * 

Request Body Schema

- * + * *
      * {@code
      * BinaryData
      * }
      * 
- * + * *

Response Body Schema

- * + * *
      * {@code
      * {
@@ -2852,6 +2904,56 @@ public Response uploadSessionFileWithResponse(String agentName, Stri
             requestOptions);
     }
 
+    /**
+     * Upload a session file
+     *
+     * Uploads binary file content to the specified path in the session sandbox.
+     * The service stores the file relative to the session home directory and rejects payloads larger than 50 MB.
+     * 

Header Parameters

+ * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
x-ms-user-isolation-keyStringNoOpaque per-user isolation key used to scope + * endpoint-scoped data (responses, conversations, sessions) to a specific end user.
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Request Body Schema

+ * + *
+     * {@code
+     * BinaryData
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     path: String (Required)
+     *     bytes_written: long (Required)
+     * }
+     * }
+     * 
+ * + * @param agentName The name of the agent. + * @param agentSessionId The session ID. + * @param path The destination file path within the sandbox, relative to the session home directory. + * @param fileInDisk The content parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return response from uploading a file to a session sandbox along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response uploadSessionFileWithResponse(String agentName, String agentSessionId, String path, + Path fileInDisk, RequestOptions requestOptions) { + return this.serviceClient.uploadSessionFileWithResponse(agentName, agentSessionId, path, + BinaryData.fromFile(fileInDisk), requestOptions); + } + /** * Download a session file * @@ -2866,7 +2968,7 @@ public Response uploadSessionFileWithResponse(String agentName, Stri * * You can add these to a request with {@link RequestOptions#addHeader} *

Response Body Schema

- * + * *
      * {@code
      * BinaryData
@@ -2890,6 +2992,47 @@ public Response downloadSessionFileWithResponse(String agentName, St
         return this.serviceClient.downloadSessionFileWithResponse(agentName, agentSessionId, path, requestOptions);
     }
 
+    /**
+     * Download a session file
+     *
+     * Downloads the file at the specified sandbox path as a binary stream.
+     * The path is resolved relative to the session home directory.
+     * 

Header Parameters

+ * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
x-ms-user-isolation-keyStringNoOpaque per-user isolation key used to scope + * endpoint-scoped data (responses, conversations, sessions) to a specific end user.
+ * You can add these to a request with {@link RequestOptions#addHeader} + *

Response Body Schema

+ * + *
+     * {@code
+     * BinaryData
+     * }
+     * 
+ * + * @param agentName The name of the agent. + * @param agentSessionId The session ID. + * @param path The file path to download from the sandbox, relative to the session home directory. + * @param filePath path to disc in file where to save the downloaded file. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response downloadSessionFileWithResponse(String agentName, String agentSessionId, String path, + Path filePath, RequestOptions requestOptions) throws IOException { + Response response + = this.serviceClient.downloadSessionFileWithResponse(agentName, agentSessionId, path, requestOptions); + response.getValue().writeTo(new FileOutputStream(filePath.toFile())); + return new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), null); + } + /** * List session files * @@ -2927,7 +3070,7 @@ public Response downloadSessionFileWithResponse(String agentName, St * * You can add these to a request with {@link RequestOptions#addHeader} *

Response Body Schema

- * + * *
      * {@code
      * {
@@ -3177,6 +3320,38 @@ public BinaryData downloadAgentCode(String agentName, String agentVersion) {
         return downloadAgentCodeWithResponse(agentName, requestOptions).getValue();
     }
 
+    /**
+     * Download agent code
+     *
+     * Downloads the code zip for a code-based hosted agent.
+     * Returns the previously-uploaded zip (`application/zip`).
+     *
+     * If `agent_version` is supplied, returns that version's code zip; otherwise
+     * returns the latest version's code zip.
+     *
+     * The SHA-256 digest of the returned bytes matches the `content_hash` on the
+     * resolved version's `code_configuration`.
+     *
+     * @param agentName The name of the agent.
+     * @param agentVersion The version of the agent whose code zip should be downloaded.
+     * If omitted, the latest version's code zip is returned.
+     * @throws IllegalArgumentException thrown if parameters fail the validation.
+     * @throws HttpResponseException thrown if the request is rejected by server.
+     * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
+     * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
+     * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
+     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
+     * @return the response.
+     */
+    @ServiceMethod(returns = ReturnType.SINGLE)
+    public void downloadAgentCode(String agentName, String agentVersion, Path destinationPath) throws IOException {
+        RequestOptions requestOptions = new RequestOptions();
+        if (agentVersion != null) {
+            requestOptions.addQueryParam("agent_version", agentVersion, false);
+        }
+        downloadAgentCode(agentName, agentVersion).writeTo(new FileOutputStream(destinationPath.toFile(), true));
+    }
+
     /**
      * Download agent code
      *
@@ -3508,6 +3683,38 @@ public SessionFileWriteResult uploadSessionFile(String agentName, String agentSe
             .toObject(SessionFileWriteResult.class);
     }
 
+    /**
+     * Upload a session file
+     *
+     * Uploads binary file content to the specified path in the session sandbox.
+     * The service stores the file relative to the session home directory and rejects payloads larger than 50 MB.
+     *
+     * @param agentName The name of the agent.
+     * @param agentSessionId The session ID.
+     * @param path The destination file path within the sandbox, relative to the session home directory.
+     * @param filePath path to file on disc.
+     * @param userIsolationKey Opaque per-user isolation key used to scope endpoint-scoped data (responses,
+     * conversations, sessions) to a specific end user.
+     * @throws IllegalArgumentException thrown if parameters fail the validation.
+     * @throws HttpResponseException thrown if the request is rejected by server.
+     * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
+     * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
+     * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
+     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
+     * @return response from uploading a file to a session sandbox.
+     */
+    @ServiceMethod(returns = ReturnType.SINGLE)
+    public SessionFileWriteResult uploadSessionFile(String agentName, String agentSessionId, String path, Path filePath,
+        String userIsolationKey) {
+        // Generated convenience method for uploadSessionFileWithResponse
+        RequestOptions requestOptions = new RequestOptions();
+        if (userIsolationKey != null) {
+            requestOptions.setHeader(HttpHeaderName.fromString("x-ms-user-isolation-key"), userIsolationKey);
+        }
+        return uploadSessionFileWithResponse(agentName, agentSessionId, path, BinaryData.fromFile(filePath),
+            requestOptions).getValue().toObject(SessionFileWriteResult.class);
+    }
+
     /**
      * Upload a session file
      *
@@ -3567,6 +3774,37 @@ public BinaryData downloadSessionFile(String agentName, String agentSessionId, S
         return downloadSessionFileWithResponse(agentName, agentSessionId, path, requestOptions).getValue();
     }
 
+    /**
+     * Download a session file
+     *
+     * Downloads the file at the specified sandbox path as a binary stream.
+     * The path is resolved relative to the session home directory.
+     *
+     * @param agentName The name of the agent.
+     * @param agentSessionId The session ID.
+     * @param path The file path to download from the sandbox, relative to the session home directory.
+     * @param userIsolationKey Opaque per-user isolation key used to scope endpoint-scoped data (responses,
+     * conversations, sessions) to a specific end user.
+     * @throws IllegalArgumentException thrown if parameters fail the validation.
+     * @throws HttpResponseException thrown if the request is rejected by server.
+     * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
+     * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
+     * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
+     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
+     */
+    @ServiceMethod(returns = ReturnType.SINGLE)
+    public void downloadSessionFile(String agentName, String agentSessionId, String path, String userIsolationKey,
+        Path fileInDisk) throws IOException {
+        RequestOptions requestOptions = new RequestOptions();
+        if (userIsolationKey != null) {
+            requestOptions.setHeader(HttpHeaderName.fromString("x-ms-user-isolation-key"), userIsolationKey);
+        }
+
+        BinaryData fileContent
+            = downloadSessionFileWithResponse(agentName, agentSessionId, path, requestOptions).getValue();
+        fileContent.writeTo(new FileOutputStream(fileInDisk.toFile(), true));
+    }
+
     /**
      * Download a session file
      *
diff --git a/sdk/ai/azure-ai-agents/src/main/java/com/azure/ai/agents/models/CodeFileDetails.java b/sdk/ai/azure-ai-agents/src/main/java/com/azure/ai/agents/models/CodeFileDetails.java
index 1bed6e5dd593..8f162bd20d6a 100644
--- a/sdk/ai/azure-ai-agents/src/main/java/com/azure/ai/agents/models/CodeFileDetails.java
+++ b/sdk/ai/azure-ai-agents/src/main/java/com/azure/ai/agents/models/CodeFileDetails.java
@@ -7,6 +7,8 @@
 import com.azure.core.annotation.Generated;
 import com.azure.core.util.BinaryData;
 
+import java.nio.file.Path;
+
 /**
  * The file details for the "code" field.
  */
@@ -41,6 +43,16 @@ public CodeFileDetails(BinaryData content) {
         this.content = content;
     }
 
+    /**
+     * Creates an instance of CodeFileDetails class.
+     *
+     * @param filePath path to the file in disc to upload.
+     */
+    public CodeFileDetails(Path filePath) {
+        this.content = BinaryData.fromFile(filePath);
+        this.filename = filePath.getFileName().toString();
+    }
+
     /**
      * Get the content property: The content of the file.
      *