Skip to content

Commit 71c9cc1

Browse files
committed
edits
1 parent bb9a086 commit 71c9cc1

File tree

3 files changed

+71
-53
lines changed

3 files changed

+71
-53
lines changed

articles/ai-services/agents/includes/quickstart-javascript.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author: aahill
44
ms.author: aahi
55
ms.service: azure-ai-agent-service
66
ms.topic: include
7-
ms.date: 02/03/2025
7+
ms.date: 03/21/2025
88
ms.custom: devx-track-js
99
---
1010

@@ -37,6 +37,12 @@ ms.custom: devx-track-js
3737
| 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. |
3838
| 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. |
3939

40+
Key objects in this code include:
41+
42+
* [AIProjectsClient](/javascript/api/@azure/ai-projects/aiprojectsclient)
43+
* [ToolUtility](/javascript/api/@azure/ai-projects/toolutility)
44+
* [Agent operations](/javascript/api/@azure/ai-projects/agentsoperations)
45+
4046
First, initialize a new project by running:
4147

4248
```console
@@ -84,7 +90,6 @@ Next, create an `index.js` file and paste in the code below:
8490

8591
```javascript
8692
// index.js
87-
8893
import {
8994
AIProjectsClient,
9095
DoneEvent,
@@ -101,6 +106,7 @@ dotenv.config();
101106

102107
// Set the connection string from the environment variable
103108
const connectionString = process.env.PROJECT_CONNECTION_STRING;
109+
const model = "gpt-4o";
104110

105111
// Throw an error if the connection string is not set
106112
if (!connectionString) {
@@ -114,14 +120,14 @@ export async function main() {
114120
);
115121

116122
// Step 1 code interpreter tool
117-
const codeInterpreterTool = ToolUtility.createCodeInterpreterTool();
123+
const codeInterpreterTool = ToolUtility.createCodeInterpreterTool([]);
118124

119125
// Step 2 an agent
120-
const agent = await client.agents.createAgent("gpt-4o-mini", {
126+
const agent = await client.agents.createAgent(model, {
121127
name: "my-agent",
122128
instructions: "You are a helpful agent",
123129
tools: [codeInterpreterTool.definition],
124-
toolResources: codeInterpreterTool.file_ids,
130+
toolResources: codeInterpreterTool.resources,
125131
});
126132

127133
// Step 3 a thread
@@ -171,14 +177,13 @@ export async function main() {
171177

172178
// Messages iterate from oldest to newest
173179
// messages[0] is the most recent
174-
for (let i = messages.data.length - 1; i >= 0; i--) {
175-
const m = messages.data[i];
176-
if (m.content && m.content.length > 0 && isOutputOfType(m.content[0], "text")) {
180+
await messages.data.forEach((m) => {
181+
console.log(`Type: ${m.content[0].type}`);
182+
if (isOutputOfType(m.content[0], "text")) {
177183
const textContent = m.content[0];
178-
console.log(`${textContent.text.value}`);
179-
console.log(`---------------------------------`);
184+
console.log(`Text: ${textContent.text.value}`);
180185
}
181-
}
186+
});
182187

183188
// 7. Delete the agent once done
184189
await client.agents.deleteAgent(agent.id);
@@ -189,4 +194,4 @@ main().catch((err) => {
189194
});
190195
```
191196
192-
Run the code using `node index.js` and observe.
197+
Run the code using `node index.js` and observe.

articles/ai-services/agents/includes/quickstart-output.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,27 @@ author: aahill
44
ms.author: aahi
55
ms.service: azure-ai-agent-service
66
ms.topic: include
7-
ms.date: 01/28/2025
7+
ms.date: 03/21/2025
88
ms.custom: devx-track-js
99
---
1010

1111
The output contains the prompt, and answers.
1212

1313
```
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\).
14+
Type: text
15+
Text: Sure, I can help you solve the equation \(3x + 11 = 14\).
1716
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\).
17+
To solve for \(x\), we need to isolate \(x\) on one side of the equation. Here are the steps:
2118
22-
Therefore, the value of \(x\) that satisfies the equation is 1.
19+
1. Subtract 11 from both sides of the equation:
20+
\[3x + 11 - 11 = 14 - 11\]
21+
\[3x = 3\]
2322
24-
Let me know if you need help with anything else!
25-
---------------------------------
23+
2. Divide both sides of the equation by 3:
24+
\[\frac{3x}{3} = \frac{3}{3}\]
25+
\[x = 1\]
26+
27+
So the solution to the equation \(3x + 11 = 14\) is \(x = 1\).
28+
Type: text
29+
Text: I need to solve the equation `3x + 11 = 14`. Can you help me?
2630
```

articles/ai-services/agents/includes/quickstart-typescript.md

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author: aahill
44
ms.author: aahi
55
ms.service: azure-ai-agent-service
66
ms.topic: include
7-
ms.date: 02/03/2025
7+
ms.date: 03/21/2025
88
ms.custom: devx-track-ts
99
---
1010

@@ -35,6 +35,12 @@ ms.custom: devx-track-ts
3535
| 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. |
3636
| 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. |
3737

38+
Key objects in this code include:
39+
40+
* [AIProjectsClient](/javascript/api/@azure/ai-projects/aiprojectsclient)
41+
* [ToolUtility](/javascript/api/@azure/ai-projects/toolutility)
42+
* [Agent operations](/javascript/api/@azure/ai-projects/agentsoperations)
43+
3844
Run the following commands to install the npm packages.
3945

4046
```console
@@ -68,65 +74,65 @@ Set this connection string as an environment variable named `PROJECT_CONNECTION_
6874

6975
```typescript
7076
// index.ts
71-
72-
import type {
73-
MessageDeltaChunk,
74-
MessageDeltaTextContent,
75-
MessageTextContentOutput,
76-
} from "@azure/ai-projects";
7777
import {
7878
AIProjectsClient,
7979
DoneEvent,
8080
ErrorEvent,
8181
isOutputOfType,
8282
MessageStreamEvent,
8383
RunStreamEvent,
84-
ToolUtility,
84+
ToolUtility
85+
} from "@azure/ai-projects";
86+
import type {
87+
MessageDeltaChunk,
88+
MessageDeltaTextContent,
89+
MessageTextContentOutput
8590
} from "@azure/ai-projects";
8691
import { DefaultAzureCredential } from "@azure/identity";
92+
import dotenv from 'dotenv';
93+
94+
dotenv.config();
8795

88-
const connectionString =
89-
process.env["AZURE_AI_PROJECTS_CONNECTION_STRING"] || "<project connection string>";
96+
// Set the connection string from the environment variable
97+
const connectionString = process.env.PROJECT_CONNECTION_STRING;
98+
const model = "gpt-4o";
9099

100+
// Throw an error if the connection string is not set
91101
if (!connectionString) {
92-
throw new Error("AZURE_AI_PROJECTS_CONNECTION_STRING must be set in the environment variables");
102+
throw new Error("Please set the PROJECT_CONNECTION_STRING environment variable.");
93103
}
94104

95-
export async function main(): Promise<void> {
105+
export async function main() {
96106
const client = AIProjectsClient.fromConnectionString(
97107
connectionString || "",
98108
new DefaultAzureCredential(),
99109
);
100110

101-
// Step 1: Create code interpreter tool
102-
const codeInterpreterTool = ToolUtility.createCodeInterpreterTool();
111+
// Step 1 code interpreter tool
112+
const codeInterpreterTool = ToolUtility.createCodeInterpreterTool([]);
103113

104-
// Step 2: Create an agent
105-
const agent = await client.agents.createAgent("gpt-4o-mini", {
114+
// Step 2 an agent
115+
const agent = await client.agents.createAgent(model, {
106116
name: "my-agent",
107117
instructions: "You are a helpful agent",
108118
tools: [codeInterpreterTool.definition],
109-
toolResources: {
110-
codeInterpreter: {
111-
fileIds: []
112-
}
113-
}
119+
toolResources: codeInterpreterTool.resources,
114120
});
115121

116-
// Step 3: Create a thread
122+
// Step 3 a thread
117123
const thread = await client.agents.createThread();
118124

119-
// Step 4: Add a message to thread
125+
// Step 4 a message to thread
120126
await client.agents.createMessage(
121127
thread.id, {
122128
role: "user",
123129
content: "I need to solve the equation `3x + 11 = 14`. Can you help me?",
124130
});
125131

126-
// Intermission: message is now correlated with thread
127-
// Intermission: listing messages will retrieve the message just added
132+
// Intermission is now correlated with thread
133+
// Intermission messages will retrieve the message just added
128134

129-
// Step 5: Run the agent
135+
// Step 5 the agent
130136
const streamEventMessages = await client.agents.createRun(thread.id, agent.id).stream();
131137

132138
for await (const eventMessage of streamEventMessages) {
@@ -140,6 +146,7 @@ export async function main(): Promise<void> {
140146
if (contentPart.type === "text") {
141147
const textContent = contentPart as MessageDeltaTextContent;
142148
const textValue = textContent.text?.value || "No text";
149+
process.stdout.write(textValue);
143150
}
144151
});
145152
}
@@ -157,17 +164,17 @@ export async function main(): Promise<void> {
157164

158165
// 6. Print the messages from the agent
159166
const messages = await client.agents.listMessages(thread.id);
167+
console.log("Messages:\n----------------------------------------------");
160168

161169
// Messages iterate from oldest to newest
162170
// messages[0] is the most recent
163-
for (let i = messages.data.length - 1; i >= 0; i--) {
164-
const m = messages.data[i];
171+
await messages.data.forEach((m) => {
172+
console.log(`Type: ${m.content[0].type}`);
165173
if (isOutputOfType<MessageTextContentOutput>(m.content[0], "text")) {
166174
const textContent = m.content[0] as MessageTextContentOutput;
167-
console.log(`${textContent.text.value}`);
168-
console.log(`---------------------------------`);
175+
console.log(`Text: ${textContent.text.value}`);
169176
}
170-
}
177+
});
171178

172179
// 7. Delete the agent once done
173180
await client.agents.deleteAgent(agent.id);
@@ -178,3 +185,5 @@ main().catch((err) => {
178185
});
179186
```
180187

188+
189+
Build the TypeScript code then run the code using `node index.js` and observe.

0 commit comments

Comments
 (0)