Skip to content

Commit 1bc3ddd

Browse files
kaylieeejpalvarezl
andauthored
Regen from latest TSP to emit listConversations (#48411)
* regen to emit list conversations * Removing `Conversation(Async)Client` , rename `listConversations` -> `listAgentConversations` and adjusted samples (#48428) * Project compiles * Moved listConversations agent filters into the Agents(Async)Client * Using correct commit for changes * update projects readme sample * remove conversationsclient from readme * update readmesample to match * Update sdk/ai/azure-ai-agents/CHANGELOG.md Co-authored-by: Jose Alvarez <jpalvarezl@users.noreply.github.com> --------- Co-authored-by: Jose Alvarez <jpalvarezl@users.noreply.github.com>
1 parent c896936 commit 1bc3ddd

35 files changed

Lines changed: 718 additions & 288 deletions

sdk/ai/azure-ai-agents/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- Added type-safe accessors on `McpTool` for the `allowedTools` property: `setAllowedTools(List<String>)`, `setAllowedTools(McpToolFilter)`, `getAllowedToolsAsStringList()`, and `getAllowedToolsAsMcpToolFilter()`.
1212
- Added type-safe accessors on `McpTool` for the `requireApproval` property: `setRequireApproval(String)`, `setRequireApproval(McpToolRequireApproval)`, `getRequireApprovalAsString()`, and `getRequireApprovalAsMcpToolRequireApproval()`.
1313
- Added `setComparisonFilter(ComparisonFilter)` and `setCompoundFilter(CompoundFilter)` convenience methods on `FileSearchTool`, accepting the openai-java filter types directly.
14+
- Added `listAgentConversations` operation to `AgentsClient` and `AgentsAsyncClient` to list conversations attached to a specific agent filtering by `agentName` and `agentId`.
1415
- Added streaming response methods to `ResponsesClient` and `ResponsesAsyncClient`:
1516
- `createStreamingWithAgent` and `createStreamingWithAgentConversation` on `ResponsesClient` return `IterableStream<ResponseStreamEvent>` for synchronous streaming.
1617
- `createStreamingWithAgent` and `createStreamingWithAgentConversation` on `ResponsesAsyncClient` return `Flux<ResponseStreamEvent>` for asynchronous streaming.

sdk/ai/azure-ai-agents/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,13 @@ This will return an `AgentVersionObject` which contains the information necessar
180180
First we need to create our `Conversation` object so we can attach items to it:
181181

182182
```java com.azure.ai.agents.create_conversation
183-
Conversation conversation = conversationsClient.getConversationService().create();
183+
Conversation conversation = conversationsClient.create();
184184
```
185185

186186
With `conversation.id()` contains the reference we will use to append messages to this `Conversation`. `Conversation` objects can be used by multiple agents and serve the purpose of being a centralized source of context. To add items:
187187

188188
```java com.azure.ai.agents.add_message_to_conversation
189-
conversationsClient.getConversationService().items().create(
189+
conversationsClient.items().create(
190190
ItemCreateParams.builder()
191191
.conversationId(conversation.id())
192192
.addItem(EasyInputMessage.builder()

sdk/ai/azure-ai-agents/checkstyle-suppressions.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
<suppress files="com.azure.ai.agents.MemoryStoresAsyncClient.java" checks="io.clientcore.linting.extensions.checkstyle.checks.ExternalDependencyExposedCheck" />
2323
<suppress files="com.azure.ai.agents.MemoryStoresClient.java" checks="io.clientcore.linting.extensions.checkstyle.checks.ExternalDependencyExposedCheck" />
2424
<suppress files="com.azure.ai.agents.AgentsClientBuilder.java" checks="io.clientcore.linting.extensions.checkstyle.checks.ExternalDependencyExposedCheck" />
25+
<suppress files="com.azure.ai.agents.AgentsAsyncClient.java" checks="io.clientcore.linting.extensions.checkstyle.checks.ExternalDependencyExposedCheck" />
26+
<suppress files="com.azure.ai.agents.AgentsClient.java" checks="io.clientcore.linting.extensions.checkstyle.checks.ExternalDependencyExposedCheck" />
2527
<suppress files="com.azure.ai.agents.models.FileSearchTool.java" checks="io.clientcore.linting.extensions.checkstyle.checks.ExternalDependencyExposedCheck" />
2628
<suppress files="com.azure.ai.agents.models.PromptAgentDefinition.java" checks="io.clientcore.linting.extensions.checkstyle.checks.ExternalDependencyExposedCheck" />
2729
</suppressions>

sdk/ai/azure-ai-agents/src/main/java/com/azure/ai/agents/AgentsAsyncClient.java

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.azure.core.http.rest.Response;
3535
import com.azure.core.util.BinaryData;
3636
import com.azure.core.util.FluxUtil;
37+
import com.openai.models.conversations.Conversation;
3738
import java.util.Map;
3839
import java.util.stream.Collectors;
3940
import reactor.core.publisher.Flux;
@@ -1432,4 +1433,154 @@ public Mono<AgentVersionDetails> createAgentVersion(String agentName, AgentDefin
14321433
.flatMap(FluxUtil::toMono)
14331434
.map(protocolMethodData -> protocolMethodData.toObject(AgentVersionDetails.class));
14341435
}
1436+
1437+
/**
1438+
* Returns the list of all conversations.
1439+
* <p><strong>Query Parameters</strong></p>
1440+
* <table border="1">
1441+
* <caption>Query Parameters</caption>
1442+
* <tr><th>Name</th><th>Type</th><th>Required</th><th>Description</th></tr>
1443+
* <tr><td>limit</td><td>Integer</td><td>No</td><td>A limit on the number of objects to be returned. Limit can range
1444+
* between 1 and 100, and the
1445+
* default is 20.</td></tr>
1446+
* <tr><td>order</td><td>String</td><td>No</td><td>Sort order by the `created_at` timestamp of the objects. `asc`
1447+
* for ascending order and`desc`
1448+
* for descending order. Allowed values: "asc", "desc".</td></tr>
1449+
* <tr><td>after</td><td>String</td><td>No</td><td>A cursor for use in pagination. `after` is an object ID that
1450+
* defines your place in the list.
1451+
* For instance, if you make a list request and receive 100 objects, ending with obj_foo, your
1452+
* subsequent call can include after=obj_foo in order to fetch the next page of the list.</td></tr>
1453+
* <tr><td>before</td><td>String</td><td>No</td><td>A cursor for use in pagination. `before` is an object ID that
1454+
* defines your place in the list.
1455+
* For instance, if you make a list request and receive 100 objects, ending with obj_foo, your
1456+
* subsequent call can include before=obj_foo in order to fetch the previous page of the list.</td></tr>
1457+
* <tr><td>agent_name</td><td>String</td><td>No</td><td>Filter by agent name. If provided, only items associated
1458+
* with the specified agent will be returned.</td></tr>
1459+
* <tr><td>agent_id</td><td>String</td><td>No</td><td>Filter by agent ID in the format `name:version`. If provided,
1460+
* only items associated with the specified agent ID will be returned.</td></tr>
1461+
* </table>
1462+
* You can add these to a request with {@link RequestOptions#addQueryParam}
1463+
* <p><strong>Response Body Schema</strong></p>
1464+
*
1465+
* <pre>
1466+
* {@code
1467+
* {
1468+
* id: String (Required)
1469+
* object: String (Required)
1470+
* metadata (Required): {
1471+
* (Optional): {
1472+
* String: String (Required)
1473+
* }
1474+
* }
1475+
* created_at: long (Required)
1476+
* }
1477+
* }
1478+
* </pre>
1479+
*
1480+
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
1481+
* @throws HttpResponseException thrown if the request is rejected by server.
1482+
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
1483+
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
1484+
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
1485+
* @return the response data for a requested list of items as paginated response with {@link PagedFlux}.
1486+
*/
1487+
@Generated
1488+
@ServiceMethod(returns = ReturnType.COLLECTION)
1489+
public PagedFlux<BinaryData> listAgentConversations(RequestOptions requestOptions) {
1490+
return this.serviceClient.listAgentConversationsAsync(requestOptions);
1491+
}
1492+
1493+
/**
1494+
* Returns the list of all conversations.
1495+
*
1496+
* @param limit A limit on the number of objects to be returned. Limit can range between 1 and 100, and the
1497+
* default is 20.
1498+
* @param order Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and`desc`
1499+
* for descending order.
1500+
* @param after A cursor for use in pagination. `after` is an object ID that defines your place in the list.
1501+
* For instance, if you make a list request and receive 100 objects, ending with obj_foo, your
1502+
* subsequent call can include after=obj_foo in order to fetch the next page of the list.
1503+
* @param before A cursor for use in pagination. `before` is an object ID that defines your place in the list.
1504+
* For instance, if you make a list request and receive 100 objects, ending with obj_foo, your
1505+
* subsequent call can include before=obj_foo in order to fetch the previous page of the list.
1506+
* @param agentName Filter by agent name. If provided, only items associated with the specified agent will be
1507+
* returned.
1508+
* @param agentId Filter by agent ID in the format `name:version`. If provided, only items associated with the
1509+
* specified agent ID will be returned.
1510+
* @throws IllegalArgumentException thrown if parameters fail the validation.
1511+
* @throws HttpResponseException thrown if the request is rejected by server.
1512+
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
1513+
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
1514+
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
1515+
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
1516+
* @return the response data for a requested list of items as paginated response with {@link PagedFlux}.
1517+
*/
1518+
@Generated
1519+
@ServiceMethod(returns = ReturnType.COLLECTION)
1520+
public PagedFlux<Conversation> listAgentConversations(Integer limit, PageOrder order, String after, String before,
1521+
String agentName, String agentId) {
1522+
// Generated convenience method for listAgentConversations
1523+
RequestOptions requestOptions = new RequestOptions();
1524+
if (limit != null) {
1525+
requestOptions.addQueryParam("limit", String.valueOf(limit), false);
1526+
}
1527+
if (order != null) {
1528+
requestOptions.addQueryParam("order", order.toString(), false);
1529+
}
1530+
if (after != null) {
1531+
requestOptions.addQueryParam("after", after, false);
1532+
}
1533+
if (before != null) {
1534+
requestOptions.addQueryParam("before", before, false);
1535+
}
1536+
if (agentName != null) {
1537+
requestOptions.addQueryParam("agent_name", agentName, false);
1538+
}
1539+
if (agentId != null) {
1540+
requestOptions.addQueryParam("agent_id", agentId, false);
1541+
}
1542+
PagedFlux<BinaryData> pagedFluxResponse = listAgentConversations(requestOptions);
1543+
return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> {
1544+
Flux<PagedResponse<BinaryData>> flux = (continuationTokenParam == null)
1545+
? pagedFluxResponse.byPage().take(1)
1546+
: pagedFluxResponse.byPage(continuationTokenParam).take(1);
1547+
return flux.map(pagedResponse -> new PagedResponseBase<Void, Conversation>(pagedResponse.getRequest(),
1548+
pagedResponse.getStatusCode(), pagedResponse.getHeaders(),
1549+
pagedResponse.getValue()
1550+
.stream()
1551+
.map(protocolMethodData -> protocolMethodData.toObject(Conversation.class))
1552+
.collect(Collectors.toList()),
1553+
pagedResponse.getContinuationToken(), null));
1554+
});
1555+
}
1556+
1557+
/**
1558+
* Returns the list of all conversations.
1559+
*
1560+
* @throws HttpResponseException thrown if the request is rejected by server.
1561+
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
1562+
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
1563+
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
1564+
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
1565+
* @return the response data for a requested list of items as paginated response with {@link PagedFlux}.
1566+
*/
1567+
@Generated
1568+
@ServiceMethod(returns = ReturnType.COLLECTION)
1569+
public PagedFlux<Conversation> listAgentConversations() {
1570+
// Generated convenience method for listAgentConversations
1571+
RequestOptions requestOptions = new RequestOptions();
1572+
PagedFlux<BinaryData> pagedFluxResponse = listAgentConversations(requestOptions);
1573+
return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> {
1574+
Flux<PagedResponse<BinaryData>> flux = (continuationTokenParam == null)
1575+
? pagedFluxResponse.byPage().take(1)
1576+
: pagedFluxResponse.byPage(continuationTokenParam).take(1);
1577+
return flux.map(pagedResponse -> new PagedResponseBase<Void, Conversation>(pagedResponse.getRequest(),
1578+
pagedResponse.getStatusCode(), pagedResponse.getHeaders(),
1579+
pagedResponse.getValue()
1580+
.stream()
1581+
.map(protocolMethodData -> protocolMethodData.toObject(Conversation.class))
1582+
.collect(Collectors.toList()),
1583+
pagedResponse.getContinuationToken(), null));
1584+
});
1585+
}
14351586
}

0 commit comments

Comments
 (0)