Skip to content

Commit 03ccc6b

Browse files
authored
Agents V2 (#47134)
* Initial commit * Minor cleanups * Reformat * Bumped stainless version temporarily; waiting for change to reach main * Revert "Bumped stainless version temporarily; waiting for change to reach main" This reverts commit 960729f. * Latest changes * Adjusted AgentsV2 version of stainless SDK * Undoing bad merge leftovers * Adding new library entry to the eng/versioning/versions_client.txt file * Version bump * Added excep spell checker * Updated docs * Fixed bad spelling enum names * more spelling exceps * Adjusting and adding agents to parent pom.xml * Latest version from private mirror * Adding self to owners in the AI folder * Adding stainless sdk sample and section in readme
1 parent cf3ad27 commit 03ccc6b

File tree

270 files changed

+38359
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

270 files changed

+38359
-1
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
# ServiceOwners: @mojayara @Prasanna-Padmanabhan
8484

8585
# PRLabel: %AI
86-
/sdk/ai/ @dargilco @jhakulin @Azure/azure-java-sdk
86+
/sdk/ai/ @dargilco @jhakulin @jpalvarezl @Azure/azure-java-sdk
8787

8888
# PRLabel: %AI Agents
8989
/sdk/ai/azure-ai-agents-persistent/ @dargilco @jhakulin @jayantjha @Azure/azure-java-sdk

.vscode/cspell.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@
234234
"Dskip",
235235
"mvnw",
236236
"TBLPROPERTIES",
237+
"CSDL",
237238
"Cyclomatic",
238239
"branchcoverage",
239240
"cacerts",
@@ -293,6 +294,7 @@
293294
"eventhubs",
294295
"failondeprecatedstatus",
295296
"FHIR",
297+
"FOURX",
296298
"filereports",
297299
"gapra",
298300
"gltf",
@@ -313,6 +315,7 @@
313315
"includable",
314316
"includables",
315317
"idnum",
318+
"inpainting",
316319
"insights",
317320
"intellij",
318321
"Intellij",
@@ -401,6 +404,7 @@
401404
"SERIALVERSIONID",
402405
"servicebus",
403406
"sftdl",
407+
"SIXX",
404408
"skus",
405409
"snomed",
406410
"sonatype",

eng/versioning/version_client.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ com.azure:azure-data-sdk-parent;1.3.0;1.3.0
3737
com.azure:azure-sdk-parent;1.6.0;1.6.0
3838
com.azure:azure-client-sdk-parent;1.7.0;1.7.0
3939
com.azure:azure-ai-agents-persistent;1.0.0-beta.2;1.0.0-beta.3
40+
com.azure:azure-ai-agents;1.0.0-beta.1;1.0.0-beta.1
4041
com.azure:azure-ai-anomalydetector;3.0.0-beta.5;3.0.0-beta.6
4142
com.azure:azure-ai-contentsafety;1.0.16;1.1.0-beta.1
4243
com.azure:azure-ai-documentintelligence;1.0.6;1.1.0-beta.1
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Release History
2+
3+
## 1.0.0-beta.1 (Unreleased)
4+
5+
- Azure Agents client library for Java. This package contains Microsoft Azure Agents client library.
6+
7+
### Features Added
8+
9+
### Breaking Changes
10+
11+
### Bugs Fixed
12+
13+
### Other Changes

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

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
# Azure Agents client library for Java
2+
3+
Develop Agents using the Azure AI Foundry platform, leveraging an extensive ecosystem of models, tools, and capabilities from OpenAI, Microsoft, and other LLM providers.
4+
5+
## Documentation
6+
7+
Various documentation is available to help you get started
8+
9+
- [API reference documentation][docs]
10+
- [Product documentation][product_documentation]
11+
12+
## Getting started
13+
14+
### Prerequisites
15+
16+
- [Java Development Kit (JDK)][jdk] with version 8 or above
17+
- [Azure Subscription][azure_subscription]
18+
19+
### Adding the package to your product
20+
21+
[//]: # ({x-version-update-start;com.azure:azure-ai-agents;current})
22+
```xml
23+
<dependency>
24+
<groupId>com.azure</groupId>
25+
<artifactId>azure-ai-agents</artifactId>
26+
<version>1.0.0-beta.1</version>
27+
</dependency>
28+
```
29+
[//]: # ({x-version-update-end})
30+
31+
### Authentication
32+
33+
[Azure Identity][azure_identity] package provides the default implementation for authenticating the client.
34+
35+
## Key concepts
36+
37+
### Create an AgentsClient
38+
39+
To interact with the Azure Agents service, you'll need to create an instance of the `AgentsClient` class.
40+
41+
```java
42+
AgentsClient agentsClient = new AgentsClientBuilder()
43+
.credential(new DefaultAzureCredentialBuilder().build())
44+
.endpoint(endpoint)
45+
.buildClient();
46+
```
47+
48+
Alternatively, you can create an asynchronous client using the `AgentsAsyncClient` class.
49+
50+
```java
51+
AgentsAsyncClient agentsAsyncClient = new AgentsClientBuilder()
52+
.credential(new DefaultAzureCredentialBuilder().build())
53+
.endpoint(endpoint)
54+
.buildAsyncClient();
55+
```
56+
57+
The Agents client library has 3 sub-clients which group the different operations that can be performed:
58+
- `AgentsClient` / `AgentsAsyncClient`: Perform operations related to agents, such as creating, retrieving, updating, and deleting agents.
59+
- `ConversationsClient` / `ConversationsAsyncClient`: Handle conversation operations. See the [OpenAI's Conversation API documentation][openai_conversations_api_docs] for more information.
60+
- `ResponsesClient` / `ResponsesAsyncClient`: Handle responses operations. See the [OpenAI's Responses API documentation][openai_responses_api_docs] for more information.
61+
62+
To access each sub-client you need to use your `AgentsClientBuilder()`. The Agents client library takes the [Official OpenAI SDK][openai_java_sdk] as a dependency, which is used for all operations, except the ones corresponding to direct Agent management.
63+
64+
```java
65+
AgentsClientBuilder builder = new AgentsClientBuilder()
66+
.credential(new DefaultAzureCredentialBuilder().build())
67+
.endpoint(endpoint);
68+
69+
// Agents sub-clients
70+
AgentsClient agentsClient = builder.buildClient();
71+
AgentsAsyncClient agentsAsyncClient = builder.buildAsyncClient();
72+
// Conversations sub-clients.
73+
ConversationsClient conversationsClient = builder.buildConversationsClient();
74+
ConversationsAsyncClient conversationsAsyncClient = builder.buildConversationsAsyncClient();
75+
// Responses sub-clients.
76+
ResponsesClient responsesClient = builder.buildResponsesClient();
77+
ResponsesAsyncClient responsesAsyncClient = builder.buildResponsesAsyncClient();
78+
```
79+
80+
The [OpenAI Official Java SDK][openai_java_sdk] is imported transitively and can be accessed from either the `ResponsesClient` or the `ConversationsClient` using the `getOpenAIClient()` method.
81+
82+
```java
83+
// OpenAI SDK ResponsesService accessed from ResponsesClient
84+
ResponsesClient responsesClient = builder.buildResponsesClient();
85+
ResponsesService responsesService = responsesClient.getOpenAIClient();
86+
87+
// OpenAI SDK ConversationService accessed from ConversationsClient
88+
ConversationsClient conversationsClient = builder.buildConversationsClient();
89+
ConversationService conversationService = conversationsClient.getOpenAIClient();
90+
```
91+
92+
### Using OpenAI's official library
93+
94+
If you prefer using the [OpenAI official Java client library][openai_java_sdk] instead, you can do so by including that dependency in your project instead and following the instructions in the linked repository. Additionally, you will have to set up your `OpenAIClient` as shown below:
95+
96+
```java com.azure.ai.agents.openai_official_library
97+
OpenAIClient client = OpenAIOkHttpClient.builder()
98+
.baseUrl(endpoint.endsWith("/") ? endpoint + "openai" : endpoint + "/openai")
99+
.azureUrlPathMode(AzureUrlPathMode.UNIFIED)
100+
.credential(BearerTokenCredential.create(AuthenticationUtil.getBearerTokenSupplier(
101+
new DefaultAzureCredentialBuilder().build(), "https://ai.azure.com/.default")))
102+
.azureServiceVersion(AzureOpenAIServiceVersion.fromString("2025-11-15-preview"))
103+
.build();
104+
105+
ResponseCreateParams responseRequest = new ResponseCreateParams.Builder()
106+
.input("Hello, how can you help me?")
107+
.model(model)
108+
.build();
109+
110+
Response result = client.responses().create(responseRequest);
111+
```
112+
113+
Remember to adjust your value for the `AzureOpenAIServiceVersion` in the builder and to postpend to your `endpoint`'s path `openai` (if it's not already there) like it's shown in the above code snippet.
114+
115+
## Examples
116+
117+
### Prompt Agent
118+
119+
This example will show how to create the context necessary for a `PromptAgent` to work. Note that the way that context is handled in this scenario would allow you to share the context with multiple agents.
120+
121+
#### Create an Agent
122+
123+
Creating an Agent can be done like in the following code snippet:
124+
125+
```java com.azure.ai.agents.create_prompt_agent
126+
PromptAgentDefinition promptAgentDefinition = new PromptAgentDefinition("gpt-4o");
127+
AgentVersionDetails agent = agentsClient.createAgentVersion("my-agent", promptAgentDefinition);
128+
```
129+
130+
This will return an `AgentVersionObject` which contains the information necessary to create an `AgentReference`. But first it's necessary to setup the `Conversation` and its messages to be able to obtain `Response`s with a centralized context.
131+
132+
#### Create conversation
133+
134+
First we need to create our `Conversation` object so we can attach items to it:
135+
136+
```java com.azure.ai.agents.create_conversation
137+
Conversation conversation = conversationsClient.getConversationService().create();
138+
```
139+
140+
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:
141+
142+
```java com.azure.ai.agents.add_message_to_conversation
143+
conversationsClient.getConversationService().items().create(
144+
ItemCreateParams.builder()
145+
.conversationId(conversation.id())
146+
.addItem(EasyInputMessage.builder()
147+
.role(EasyInputMessage.Role.SYSTEM)
148+
.content("You are a helpful assistant that speaks like a pirate.")
149+
.build()
150+
).addItem(EasyInputMessage.builder()
151+
.role(EasyInputMessage.Role.USER)
152+
.content("Hello, agent!")
153+
.build()
154+
).build()
155+
);
156+
```
157+
158+
#### Text generation with Responses
159+
160+
And the final step that ties everything together, we pass the `AgentReference` and the `conversation.id()` as parameters for the `Response` creation:
161+
162+
```java com.azure.ai.agents.create_response
163+
AgentReference agentReference = new AgentReference(agent.getName()).setVersion(agent.getVersion());
164+
Response response = responsesClient.createWithAgentConversation(agentReference, conversation.id());
165+
```
166+
167+
### Service API versions
168+
169+
The client library targets the latest service API version by default.
170+
The service client builder accepts an optional service API version parameter to specify which API version to communicate.
171+
172+
#### Select a service API version
173+
174+
You have the flexibility to explicitly select a supported service API version when initializing a service client via the service client builder.
175+
This ensures that the client can communicate with services using the specified API version.
176+
177+
When selecting an API version, it is important to verify that there are no breaking changes compared to the latest API version.
178+
If there are significant differences, API calls may fail due to incompatibility.
179+
180+
Always ensure that the chosen API version is fully supported and operational for your specific use case and that it aligns with the service's versioning policy.
181+
182+
## Troubleshooting
183+
184+
## Next steps
185+
186+
## Contributing
187+
188+
For details on contributing to this repository, see the [contributing guide](https://github.com/Azure/azure-sdk-for-java/blob/main/CONTRIBUTING.md).
189+
190+
1. Fork it
191+
1. Create your feature branch (`git checkout -b my-new-feature`)
192+
1. Commit your changes (`git commit -am 'Add some feature'`)
193+
1. Push to the branch (`git push origin my-new-feature`)
194+
1. Create new Pull Request
195+
196+
<!-- LINKS -->
197+
[product_documentation]: https://aka.ms/azsdk/azure-ai-agents/product-doc
198+
[docs]: https://azure.github.io/azure-sdk-for-java/
199+
[jdk]: https://learn.microsoft.com/azure/developer/java/fundamentals/
200+
[azure_subscription]: https://azure.microsoft.com/free/
201+
[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/identity/azure-identity
202+
[openai_java_sdk]: https://github.com/openai/openai-java/
203+
[openai_responses_api_docs]: https://platform.openai.com/docs/api-reference/responses
204+
[openai_conversations_api_docs]: https://platform.openai.com/docs/api-reference/conversations
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
directory: specification/ai/Azure.AI.Agents.V2.java
2+
commit: d9fef42c87992deb6b3e16de0bd0386723cb9865
3+
repo: Azure/azure-rest-api-specs-pr
4+
additionalDirectories:
5+
- specification/ai/Azure.AI.Projects

sdk/ai/azure-ai-agents/assets.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"AssetsRepo": "Azure/azure-sdk-assets",
3+
"AssetsRepoPrefixPath": "java",
4+
"TagPrefix": "java/ai/azure-ai-agents",
5+
"Tag": ""
6+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE suppressions PUBLIC "-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN" "https://checkstyle.org/dtds/suppressions_1_2.dtd">
3+
<!-- This file is generated by the /eng/scripts/linting_suppression_generator.py script. -->
4+
5+
<suppressions>
6+
<suppress files="com.azure.ai.agents.models.InvokeAzureAgentWorkflowActionOutputItemResource.java" checks="io.clientcore.linting.extensions.checkstyle.checks.EnforceFinalFieldsCheck" />
7+
<suppress files="com.azure.ai.agents.models.ResponsesAssistantMessageItemParam.java" checks="io.clientcore.linting.extensions.checkstyle.checks.EnforceFinalFieldsCheck" />
8+
<suppress files="com.azure.ai.agents.models.ResponsesAssistantMessageItemResource.java" checks="io.clientcore.linting.extensions.checkstyle.checks.EnforceFinalFieldsCheck" />
9+
<suppress files="com.azure.ai.agents.models.ResponsesDeveloperMessageItemParam.java" checks="io.clientcore.linting.extensions.checkstyle.checks.EnforceFinalFieldsCheck" />
10+
<suppress files="com.azure.ai.agents.models.ResponsesDeveloperMessageItemResource.java" checks="io.clientcore.linting.extensions.checkstyle.checks.EnforceFinalFieldsCheck" />
11+
<suppress files="com.azure.ai.agents.models.ResponsesMessageItemParam.java" checks="io.clientcore.linting.extensions.checkstyle.checks.EnforceFinalFieldsCheck" />
12+
<suppress files="com.azure.ai.agents.models.ResponsesMessageItemResource.java" checks="io.clientcore.linting.extensions.checkstyle.checks.EnforceFinalFieldsCheck" />
13+
<suppress files="com.azure.ai.agents.models.ResponsesSystemMessageItemParam.java" checks="io.clientcore.linting.extensions.checkstyle.checks.EnforceFinalFieldsCheck" />
14+
<suppress files="com.azure.ai.agents.models.ResponsesSystemMessageItemResource.java" checks="io.clientcore.linting.extensions.checkstyle.checks.EnforceFinalFieldsCheck" />
15+
<suppress files="com.azure.ai.agents.models.ResponsesUserMessageItemParam.java" checks="io.clientcore.linting.extensions.checkstyle.checks.EnforceFinalFieldsCheck" />
16+
<suppress files="com.azure.ai.agents.models.ResponsesUserMessageItemResource.java" checks="io.clientcore.linting.extensions.checkstyle.checks.EnforceFinalFieldsCheck" />
17+
<suppress files="com.azure.ai.agents.models.WorkflowActionOutputItemResource.java" checks="io.clientcore.linting.extensions.checkstyle.checks.EnforceFinalFieldsCheck" />
18+
<suppress files="com.azure.ai.agents.ResponsesAsyncClient.java" checks="io.clientcore.linting.extensions.checkstyle.checks.ExternalDependencyExposedCheck" />
19+
<suppress files="com.azure.ai.agents.ResponsesClient.java" checks="io.clientcore.linting.extensions.checkstyle.checks.ExternalDependencyExposedCheck" />
20+
<suppress files="com.azure.ai.agents.ConversationsAsyncClient.java" checks="io.clientcore.linting.extensions.checkstyle.checks.ExternalDependencyExposedCheck" />
21+
<suppress files="com.azure.ai.agents.ConversationsClient.java" checks="io.clientcore.linting.extensions.checkstyle.checks.ExternalDependencyExposedCheck" />
22+
</suppressions>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>com.azure</groupId>
9+
<artifactId>azure-code-customization-parent</artifactId>
10+
<version>1.0.0-beta.1</version> <!-- {x-version-update;com.azure:azure-code-customization-parent;current} -->
11+
<relativePath>../../../parents/azure-code-customization-parent</relativePath>
12+
</parent>
13+
14+
<groupId>com.azure.tools</groupId>
15+
<artifactId>azure-ai-agents-customizations</artifactId>
16+
<version>1.2.0-beta.1</version>
17+
<packaging>jar</packaging>
18+
</project>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import com.azure.autorest.customization.Customization;
2+
import com.azure.autorest.customization.LibraryCustomization;
3+
import org.slf4j.Logger;
4+
5+
6+
/**
7+
* This class contains the customization code to customize the AutoRest generated code for the Agents Client library
8+
* Reference: https://github.com/Azure/autorest.java/blob/main/customization-base/README.md
9+
*/
10+
public class AgentsCustomizations extends Customization {
11+
12+
@Override
13+
public void customize(LibraryCustomization libraryCustomization, Logger logger) {
14+
renameImageGenSizeEnums(libraryCustomization, logger);
15+
}
16+
17+
/**
18+
* Customization for enum values that are originally numbers and get transliterated by the emitter.
19+
* @param customization
20+
* @param logger
21+
*/
22+
private void renameImageGenSizeEnums(LibraryCustomization customization, Logger logger) {
23+
logger.info("Renaming enum ImageGenToolSize variants");
24+
customization.getClass("com.azure.ai.agents.models", "ImageGenToolSize").customizeAst(ast -> ast.getEnumByName("ImageGenToolSize")
25+
.ifPresent(clazz -> clazz.getEntries().stream()
26+
.filter(entry -> "ONE_ZERO_TWO_FOURX_ONE_ZERO_TWO_FOUR".equals(entry.getName().getIdentifier()))
27+
.forEach(entry -> entry.setName("SIZE_1024X1024"))));
28+
29+
customization.getClass("com.azure.ai.agents.models", "ImageGenToolSize").customizeAst(ast -> ast.getEnumByName("ImageGenToolSize")
30+
.ifPresent(clazz -> clazz.getEntries().stream()
31+
.filter(entry -> "ONE_ZERO_TWO_FOURX_ONE_FIVE_THREE_SIX".equals(entry.getName().getIdentifier()))
32+
.forEach(entry -> entry.setName("SIZE_1024X1536"))));
33+
34+
customization.getClass("com.azure.ai.agents.models", "ImageGenToolSize").customizeAst(ast -> ast.getEnumByName("ImageGenToolSize")
35+
.ifPresent(clazz -> clazz.getEntries().stream()
36+
.filter(entry -> "ONE_FIVE_THREE_SIXX_ONE_ZERO_TWO_FOUR".equals(entry.getName().getIdentifier()))
37+
.forEach(entry -> entry.setName("SIZE_1536X1024"))));
38+
39+
customization.getClass("com.azure.ai.agents.models", "ComputerActionType").customizeAst(ast -> ast.getEnumByName("ComputerActionType")
40+
.ifPresent(clazz -> clazz.getEntries().stream()
41+
.filter(entry -> "KEYPRESS".equals(entry.getName().getIdentifier()))
42+
.forEach(entry -> entry.setName("KEY_PRESS"))));
43+
44+
customization.getClass("com.azure.ai.agents.models", "ComputerActionKeyPress")
45+
.customizeAst(ast -> ast.getClassByName("ComputerActionKeyPress")
46+
.flatMap(clazz -> clazz.getFieldByName("type"))
47+
.ifPresent(barField ->
48+
barField.getVariables().forEach(var -> {
49+
if (var.getNameAsString().equals("type")) {
50+
var.setInitializer("ComputerActionType.KEY_PRESS");
51+
}
52+
})));
53+
}
54+
}

0 commit comments

Comments
 (0)