Skip to content

Commit be95b41

Browse files
committed
fixing merge conflict
2 parents d25894b + 5ebb63d commit be95b41

File tree

6 files changed

+371
-3
lines changed

6 files changed

+371
-3
lines changed
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
---
2+
manager: nitinme
3+
author: aahill
4+
ms.author: aahi
5+
ms.service: azure-ai-agent-service
6+
ms.topic: include
7+
ms.date: 01/28/2025
8+
ms.custom: devx-track-js
9+
---
10+
11+
12+
| [Reference documentation](/javascript/api/overview/azure/ai-projects-readme) | [Samples](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/README.md) | [Library source code](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/ai/ai-projects) | [Package (npm)](https://www.npmjs.com/package/@azure/ai-projects) |
13+
14+
## Prerequisites
15+
16+
* An Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services).
17+
* [Node.js LTS](https://nodejs.org/)
18+
* Make sure you have the **Azure AI Developer** [RBAC role](../../../ai-studio/concepts/rbac-ai-studio.md) assigned at the appropriate level.
19+
* Install [the Azure CLI and the machine learning extension](/azure/machine-learning/how-to-configure-cli). If you have the CLI already installed, make sure it's updated to the latest version.
20+
21+
[!INCLUDE [bicep-setup](bicep-setup.md)]
22+
23+
## Configure and run an agent
24+
25+
| Component | Description |
26+
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
27+
| Agent | Custom AI that uses AI models in conjunction with tools. |
28+
| Tool | Tools help extend an agent’s ability to reliably and accurately respond during conversation. Such as connecting to user-defined knowledge bases to ground the model, or enabling web search to provide current information. |
29+
| Thread | A conversation session between an agent and a user. Threads store Messages and automatically handle truncation to fit content into a model’s context. |
30+
| Message | A message created by an agent or a user. Messages can include text, images, and other files. Messages are stored as a list on the Thread. |
31+
| Run | Activation of an agent to begin running based on the contents of Thread. The agent uses its configuration and Thread’s Messages to perform tasks by calling models and tools. As part of a Run, the agent appends Messages to the Thread. |
32+
| Run Step | A detailed list of steps the agent took as part of a Run. An agent can call tools or create Messages during its run. Examining Run Steps allows you to understand how the agent is getting to its results. |
33+
34+
Run the following commands to install the npm packages.
35+
36+
```console
37+
npm install @azure/ai-projects
38+
npm install @azure/identity
39+
```
40+
41+
Use the following code to create and run an agent. To run this code, you will need to create a connection string using information from your project. This string is in the format:
42+
43+
`<HostName>;<AzureSubscriptionId>;<ResourceGroup>;<ProjectName>`
44+
45+
[!INCLUDE [connection-string-portal](connection-string-portal.md)]
46+
47+
`HostName` can be found by navigating to your `discovery_url` and removing the leading `https://` and trailing `/discovery`. To find your `discovery_url`, run this CLI command:
48+
49+
```azurecli
50+
az ml workspace show -n {project_name} --resource-group {resource_group_name} --query discovery_url
51+
```
52+
53+
For example, your connection string may look something like:
54+
55+
`eastus.api.azureml.ms;12345678-abcd-1234-9fc6-62780b3d3e05;my-resource-group;my-project-name`
56+
57+
Set this connection string as an environment variable named `PROJECT_CONNECTION_STRING`.
58+
59+
```javascript
60+
// index.js
61+
62+
import {
63+
AIProjectsClient,
64+
DoneEvent,
65+
ErrorEvent,
66+
isOutputOfType,
67+
MessageStreamEvent,
68+
RunStreamEvent,
69+
ToolUtility,
70+
} from "@azure/ai-projects";
71+
import { DefaultAzureCredential } from "@azure/identity";
72+
73+
const connectionString =
74+
process.env["AZURE_AI_PROJECTS_CONNECTION_STRING"] || "<project connection string>";
75+
76+
if (!connectionString) {
77+
throw new Error("AZURE_AI_PROJECTS_CONNECTION_STRING must be set in the environment variables");
78+
}
79+
80+
export async function main() {
81+
const client = AIProjectsClient.fromConnectionString(
82+
connectionString || "",
83+
new DefaultAzureCredential(),
84+
);
85+
86+
// Step 1 code interpreter tool
87+
const codeInterpreterTool = ToolUtility.createCodeInterpreterTool();
88+
89+
// Step 2 an agent
90+
const agent = await client.agents.createAgent("gpt-35-turbo", {
91+
name: "my-agent",
92+
instructions: "You are a helpful agent",
93+
tools: [codeInterpreterTool.definition],
94+
toolResources: codeInterpreterTool.resources,
95+
});
96+
97+
// Step 3 a thread
98+
const thread = await client.agents.createThread();
99+
100+
// Step 4 a message to thread
101+
await client.agents.createMessage(
102+
thread.id, {
103+
role: "user",
104+
content: "I need to solve the equation `3x + 11 = 14`. Can you help me?",
105+
});
106+
107+
// Intermission is now correlated with thread
108+
// Intermission messages will retrieve the message just added
109+
110+
// Step 5 the agent
111+
const streamEventMessages = await client.agents.createRun(thread.id, agent.id).stream();
112+
113+
for await (const eventMessage of streamEventMessages) {
114+
switch (eventMessage.event) {
115+
case RunStreamEvent.ThreadRunCreated:
116+
break;
117+
case MessageStreamEvent.ThreadMessageDelta:
118+
{
119+
const messageDelta = eventMessage.data;
120+
messageDelta.delta.content.forEach((contentPart) => {
121+
if (contentPart.type === "text") {
122+
const textContent = contentPart;
123+
const textValue = textContent.text?.value || "No text";
124+
}
125+
});
126+
}
127+
break;
128+
129+
case RunStreamEvent.ThreadRunCompleted:
130+
break;
131+
case ErrorEvent.Error:
132+
console.log(`An error occurred. Data ${eventMessage.data}`);
133+
break;
134+
case DoneEvent.Done:
135+
break;
136+
}
137+
}
138+
139+
// 6. Print the messages from the agent
140+
const messages = await client.agents.listMessages(thread.id);
141+
142+
// Messages iterate from oldest to newest
143+
// messages[0] is the most recent
144+
for (let i = messages.data.length - 1; i >= 0; i--) {
145+
const m = messages.data[i];
146+
if (isOutputOfType<MessageTextContentOutput>(m.content[0], "text")) {
147+
const textContent = m.content[0];
148+
console.log(`${textContent.text.value}`);
149+
console.log(`---------------------------------`);
150+
}
151+
}
152+
153+
// 7. Delete the agent once done
154+
await client.agents.deleteAgent(agent.id);
155+
}
156+
157+
main().catch((err) => {
158+
console.error("The sample encountered an error:", err);
159+
});
160+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
manager: nitinme
3+
author: aahill
4+
ms.author: aahi
5+
ms.service: azure-ai-agent-service
6+
ms.topic: include
7+
ms.date: 01/28/2025
8+
ms.custom: devx-track-js
9+
---
10+
11+
The output contains the prompt, and answers.
12+
13+
```
14+
I need to solve the equation `3x + 11 = 14`. Can you help me?
15+
---------------------------------
16+
Sure! I can help you solve the equation \(3x + 11 = 14\).
17+
18+
To solve this equation, we need to isolate the variable \(x\). Let's go ahead and solve it.
19+
---------------------------------
20+
The solution to the equation \(3x + 11 = 14\) is \(x = 1\).
21+
22+
Therefore, the value of \(x\) that satisfies the equation is 1.
23+
24+
Let me know if you need help with anything else!
25+
---------------------------------
26+
```
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
---
2+
manager: nitinme
3+
author: aahill
4+
ms.author: aahi
5+
ms.service: azure-ai-agent-service
6+
ms.topic: include
7+
ms.date: 01/28/2025
8+
ms.custom: devx-track-ts
9+
---
10+
11+
12+
| [Reference documentation](/javascript/api/overview/azure/ai-projects-readme) | [Samples](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/README.md) | [Library source code](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/ai/ai-projects) | [Package (npm)](https://www.npmjs.com/package/@azure/ai-projects) |
13+
14+
## Prerequisites
15+
16+
* An Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services).
17+
* [Node.js LTS](https://nodejs.org/)
18+
* [TypeScript 5.x](https://www.typescriptlang.org/)
19+
* Make sure you have the **Azure AI Developer** [RBAC role](../../../ai-studio/concepts/rbac-ai-studio.md) assigned at the appropriate level.
20+
* Install [the Azure CLI and the machine learning extension](/azure/machine-learning/how-to-configure-cli). If you have the CLI already installed, make sure it's updated to the latest version.
21+
22+
[!INCLUDE [bicep-setup](bicep-setup.md)]
23+
24+
## Configure and run an agent
25+
26+
| Component | Description |
27+
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
28+
| Agent | Custom AI that uses AI models in conjunction with tools. |
29+
| Tool | Tools help extend an agent’s ability to reliably and accurately respond during conversation. Such as connecting to user-defined knowledge bases to ground the model, or enabling web search to provide current information. |
30+
| Thread | A conversation session between an agent and a user. Threads store Messages and automatically handle truncation to fit content into a model’s context. |
31+
| Message | A message created by an agent or a user. Messages can include text, images, and other files. Messages are stored as a list on the Thread. |
32+
| Run | Activation of an agent to begin running based on the contents of Thread. The agent uses its configuration and Thread’s Messages to perform tasks by calling models and tools. As part of a Run, the agent appends Messages to the Thread. |
33+
| Run Step | A detailed list of steps the agent took as part of a Run. An agent can call tools or create Messages during its run. Examining Run Steps allows you to understand how the agent is getting to its results. |
34+
35+
Run the following commands to install the npm packages.
36+
37+
```console
38+
npm install @azure/ai-projects
39+
npm install @azure/identity
40+
```
41+
42+
Use the following code to create and run an agent. To run this code, you will need to create a connection string using information from your project. This string is in the format:
43+
44+
`<HostName>;<AzureSubscriptionId>;<ResourceGroup>;<ProjectName>`
45+
46+
[!INCLUDE [connection-string-portal](connection-string-portal.md)]
47+
48+
`HostName` can be found by navigating to your `discovery_url` and removing the leading `https://` and trailing `/discovery`. To find your `discovery_url`, run this CLI command:
49+
50+
```azurecli
51+
az ml workspace show -n {project_name} --resource-group {resource_group_name} --query discovery_url
52+
```
53+
54+
For example, your connection string may look something like:
55+
56+
`eastus.api.azureml.ms;12345678-abcd-1234-9fc6-62780b3d3e05;my-resource-group;my-project-name`
57+
58+
Set this connection string as an environment variable named `PROJECT_CONNECTION_STRING`.
59+
60+
```typescript
61+
// index.ts
62+
63+
import type {
64+
MessageDeltaChunk,
65+
MessageDeltaTextContent,
66+
MessageTextContentOutput,
67+
} from "@azure/ai-projects";
68+
import {
69+
AIProjectsClient,
70+
DoneEvent,
71+
ErrorEvent,
72+
isOutputOfType,
73+
MessageStreamEvent,
74+
RunStreamEvent,
75+
ToolUtility,
76+
} from "@azure/ai-projects";
77+
import { DefaultAzureCredential } from "@azure/identity";
78+
79+
const connectionString =
80+
process.env["AZURE_AI_PROJECTS_CONNECTION_STRING"] || "<project connection string>";
81+
82+
if (!connectionString) {
83+
throw new Error("AZURE_AI_PROJECTS_CONNECTION_STRING must be set in the environment variables");
84+
}
85+
86+
export async function main(): Promise<void> {
87+
const client = AIProjectsClient.fromConnectionString(
88+
connectionString || "",
89+
new DefaultAzureCredential(),
90+
);
91+
92+
// Step 1: Create code interpreter tool
93+
const codeInterpreterTool = ToolUtility.createCodeInterpreterTool();
94+
95+
// Step 2: Create an agent
96+
const agent = await client.agents.createAgent("gpt-35-turbo", {
97+
name: "my-agent",
98+
instructions: "You are a helpful agent",
99+
tools: [codeInterpreterTool.definition],
100+
toolResources: codeInterpreterTool.resources,
101+
});
102+
103+
// Step 3: Create a thread
104+
const thread = await client.agents.createThread();
105+
106+
// Step 4: Add a message to thread
107+
await client.agents.createMessage(
108+
thread.id, {
109+
role: "user",
110+
content: "I need to solve the equation `3x + 11 = 14`. Can you help me?",
111+
});
112+
113+
// Intermission: message is now correlated with thread
114+
// Intermission: listing messages will retrieve the message just added
115+
116+
// Step 5: Run the agent
117+
const streamEventMessages = await client.agents.createRun(thread.id, agent.id).stream();
118+
119+
for await (const eventMessage of streamEventMessages) {
120+
switch (eventMessage.event) {
121+
case RunStreamEvent.ThreadRunCreated:
122+
break;
123+
case MessageStreamEvent.ThreadMessageDelta:
124+
{
125+
const messageDelta = eventMessage.data as MessageDeltaChunk;
126+
messageDelta.delta.content.forEach((contentPart) => {
127+
if (contentPart.type === "text") {
128+
const textContent = contentPart as MessageDeltaTextContent;
129+
const textValue = textContent.text?.value || "No text";
130+
}
131+
});
132+
}
133+
break;
134+
135+
case RunStreamEvent.ThreadRunCompleted:
136+
break;
137+
case ErrorEvent.Error:
138+
console.log(`An error occurred. Data ${eventMessage.data}`);
139+
break;
140+
case DoneEvent.Done:
141+
break;
142+
}
143+
}
144+
145+
// 6. Print the messages from the agent
146+
const messages = await client.agents.listMessages(thread.id);
147+
148+
// Messages iterate from oldest to newest
149+
// messages[0] is the most recent
150+
for (let i = messages.data.length - 1; i >= 0; i--) {
151+
const m = messages.data[i];
152+
if (isOutputOfType<MessageTextContentOutput>(m.content[0], "text")) {
153+
const textContent = m.content[0] as MessageTextContentOutput;
154+
console.log(`${textContent.text.value}`);
155+
console.log(`---------------------------------`);
156+
}
157+
}
158+
159+
// 7. Delete the agent once done
160+
await client.agents.deleteAgent(agent.id);
161+
}
162+
163+
main().catch((err) => {
164+
console.error("The sample encountered an error:", err);
165+
});
166+
```
167+

articles/ai-services/agents/quickstart.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,18 @@ Azure AI Agent Service allows you to create AI agents tailored to your needs thr
3838

3939
::: zone-end
4040

41+
::: zone pivot="programming-language-javascript"
4142

43+
[!INCLUDE [quickstart-javascript](includes/quickstart-javascript.md)]
44+
[!INCLUDE [quickstart-output](includes/quickstart-output.md)]
45+
46+
::: zone-end
47+
::: zone pivot="programming-language-typescript"
48+
49+
[!INCLUDE [quickstart-typescript](includes/quickstart-typescript.md)]
50+
[!INCLUDE [quickstart-output](includes/quickstart-output.md)]
51+
52+
::: zone-end
4253

4354

4455

articles/machine-learning/v1/how-to-troubleshoot-auto-ml.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Troubleshoot automated ML experiments
33
titleSuffix: Azure Machine Learning
44
description: Learn how to troubleshoot and resolve issues in your automated machine learning experiments.
55
author: manashgoswami
6-
ms.author: manashg
6+
ms.author: ssalgado
77
ms.reviewer: ssalgado
88
services: machine-learning
99
ms.service: azure-machine-learning
@@ -211,7 +211,7 @@ If you have over 100 automated ML experiments, this may cause new automated ML e
211211
If you are under virtual networks (VNets), you may run into model download failures when using AutoML NLP. This is because network traffic is blocked from downloading the models and tokenizers from Azure CDN. To unblock this, please allow list the below URLs in the "Application rules" setting of the VNet firewall policy:
212212
213213
* ```aka.ms ```
214-
* ```https://automlresources-prod.azureedge.net ```
214+
* ```https://automlresources-prod-d0eaehh7g8andvav.b02.azurefd.net```
215215
216216
Please follow the instructions [here to configure the firewall settings.](../how-to-access-azureml-behind-firewall.md)
217217

0 commit comments

Comments
 (0)