Skip to content

Commit 1102af8

Browse files
authored
Remove AgentsClient from JS/TS QuickStarts (#245)
* Update packages and integrate new AgentClient * Merge branch 'main' of https://github.com/azure-ai-foundry/foundry-samples * Add TypeScript QuickStart and remove old files * Remove AgentsClient from JS/TS QuickStarts
1 parent 01b5147 commit 1102af8

File tree

6 files changed

+52
-97
lines changed

6 files changed

+52
-97
lines changed

samples/microsoft/javascript/mslearn-resources/quickstart/package-lock.json

Lines changed: 5 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/microsoft/javascript/mslearn-resources/quickstart/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"dependencies": {
2121
"@azure/ai-projects": "1.0.0-beta.8",
22-
"@azure/ai-agents": "1.0.0",
22+
"@azure/ai-agents": "1.0.0-beta.3",
2323
"@azure/identity": "^4.10.2",
2424
"dotenv": "^17.1.0"
2525
}

samples/microsoft/javascript/mslearn-resources/quickstart/src/quickstart.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'fs';
22
import path from 'path';
33
import { fileURLToPath } from 'url';
44
import { DefaultAzureCredential } from '@azure/identity';
5-
import { AgentsClient, ToolUtility, DoneEvent, ErrorEvent } from '@azure/ai-agents';
5+
import { ToolUtility, DoneEvent, ErrorEvent } from '@azure/ai-agents';
66
import { AIProjectClient } from '@azure/ai-projects';
77
import { config } from 'dotenv';
88
config();
@@ -42,44 +42,44 @@ async function runAgents() {
4242
// <create_and_run_agent>
4343
const endpoint = process.env.PROJECT_ENDPOINT;
4444
const deployment = process.env.MODEL_DEPLOYMENT_NAME || 'gpt-4o';
45-
const client = new AgentsClient(endpoint, new DefaultAzureCredential());
45+
const client = new AIProjectClient(endpoint, new DefaultAzureCredential());
4646

4747
// Create an Agent
48-
const agent = await client.createAgent(deployment, {
48+
const agent = await client.agents.createAgent(deployment, {
4949
name: 'my-agent',
5050
instructions: 'You are a helpful agent'
5151
});
5252
console.log(`\n==================== 🕵️ POEM AGENT ====================`);
5353

5454
// Create a thread and message
55-
const thread = await client.threads.create();
55+
const thread = await client.agents.threads.create();
5656
const prompt = 'Write me a poem about flowers';
5757
console.log(`\n---------------- 📝 User Prompt ---------------- \n${prompt}`);
58-
await client.messages.create(thread.id, 'user', prompt);
58+
await client.agents.messages.create(thread.id, 'user', prompt);
5959

6060
// Create run
61-
let run = await client.runs.create(thread.id, agent.id);
61+
let run = await client.agents.runs.create(thread.id, agent.id);
6262

6363
// Wait for run to complete
6464
console.log(`\n---------------- 🚦 Run Status ----------------`);
6565
while (['queued', 'in_progress', 'requires_action'].includes(run.status)) {
6666
// Avoid adding a lot of messages to the console
6767
await new Promise((resolve) => setTimeout(resolve, 1000));
68-
run = await client.runs.get(thread.id, run.id);
68+
run = await client.agents.runs.get(thread.id, run.id);
6969
console.log(`Run status: ${run.status}`);
7070
}
7171

7272
console.log('\n---------------- 📊 Token Usage ----------------');
7373
console.table([run.usage]);
7474

75-
const messagesIterator = await client.messages.list(thread.id);
75+
const messagesIterator = await client.agents.messages.list(thread.id);
7676
const assistantMessage = await getAssistantMessage(messagesIterator);
7777
console.log('\n---------------- 💬 Response ----------------');
7878
printAssistantMessage(assistantMessage);
7979

8080
// Clean up
8181
console.log(`\n---------------- 🧹 Clean Up Poem Agent ----------------`);
82-
await client.deleteAgent(agent.id);
82+
await client.agents.deleteAgent(agent.id);
8383
console.log(`Deleted Agent, Agent ID: ${agent.id}`);
8484
// </create_and_run_agent>
8585

@@ -92,11 +92,11 @@ async function runAgents() {
9292
fileStream.on('data', (chunk) => {
9393
console.log(`Read ${chunk.length} bytes of data.`);
9494
});
95-
const file = await client.files.upload(fileStream, 'assistants', {
95+
const file = await client.agents.files.upload(fileStream, 'assistants', {
9696
fileName: 'product_info_1.md'
9797
});
9898
console.log(`Uploaded file, ID: ${file.id}`);
99-
const vectorStore = await client.vectorStores.create({
99+
const vectorStore = await client.agents.vectorStores.create({
100100
fileIds: [file.id],
101101
name: 'my_vectorstore'
102102
});
@@ -111,21 +111,21 @@ async function runAgents() {
111111

112112
// Create an Agent and a FileSearch tool
113113
const fileSearchTool = ToolUtility.createFileSearchTool([vectorStore.id]);
114-
const fileAgent = await client.createAgent(deployment, {
114+
const fileAgent = await client.agents.createAgent(deployment, {
115115
name: 'my-file-agent',
116116
instructions: 'You are a helpful assistant and can search information from uploaded files',
117117
tools: [fileSearchTool.definition],
118118
toolResources: fileSearchTool.resources,
119119
});
120120

121121
// Create a thread and message
122-
const fileSearchThread = await client.threads.create({ toolResources: fileSearchTool.resources });
122+
const fileSearchThread = await client.agents.threads.create({ toolResources: fileSearchTool.resources });
123123
const filePrompt = 'What are the steps to setup the TrailMaster X4 Tent?';
124124
console.log(`\n---------------- 📝 User Prompt ---------------- \n${filePrompt}`);
125-
await client.messages.create(fileSearchThread.id, 'user', filePrompt);
125+
await client.agents.messages.create(fileSearchThread.id, 'user', filePrompt);
126126

127127
// Create run
128-
let fileSearchRun = await client.runs.create(fileSearchThread.id, fileAgent.id).stream();
128+
let fileSearchRun = await client.agents.runs.create(fileSearchThread.id, fileAgent.id).stream();
129129

130130
for await (const eventMessage of fileSearchRun) {
131131
if (eventMessage.event === DoneEvent.Done) {
@@ -136,16 +136,16 @@ async function runAgents() {
136136
}
137137
}
138138

139-
const fileSearchMessagesIterator = await client.messages.list(fileSearchThread.id);
139+
const fileSearchMessagesIterator = await client.agents.messages.list(fileSearchThread.id);
140140
const fileAssistantMessage = await getAssistantMessage(fileSearchMessagesIterator);
141141
console.log(`\n---------------- 💬 Response ---------------- \n`);
142142
printAssistantMessage(fileAssistantMessage);
143143

144144
// Clean up
145145
console.log(`\n---------------- 🧹 Clean Up File Agent ----------------`);
146-
client.vectorStores.delete(vectorStore.id);
147-
client.files.delete(file.id);
148-
client.deleteAgent(fileAgent.id);
146+
client.agents.vectorStores.delete(vectorStore.id);
147+
client.agents.files.delete(file.id);
148+
client.agents.deleteAgent(fileAgent.id);
149149
console.log(`Deleted VectorStore, File, and FileAgent. FileAgent ID: ${fileAgent.id}`);
150150
// </create_filesearch_agent>
151151
}
@@ -180,5 +180,4 @@ function printAssistantMessage(message) {
180180
return;
181181
}
182182
output.split('\n').forEach(line => console.log(line));
183-
}
184-
183+
}

samples/microsoft/typescript/mslearn-resources/quickstart/package-lock.json

Lines changed: 5 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/microsoft/typescript/mslearn-resources/quickstart/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
"dependencies": {
2424
"@azure/ai-projects": "1.0.0-beta.8",
25-
"@azure/ai-agents": "1.0.0",
25+
"@azure/ai-agents": "1.0.0-beta.3",
2626
"@azure/identity": "^4.10.2",
2727
"dotenv": "^17.1.0"
2828
},

samples/microsoft/typescript/mslearn-resources/quickstart/src/quickstart.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'fs';
22
import path from 'path';
33
import { fileURLToPath } from 'url';
44
import { DefaultAzureCredential } from '@azure/identity';
5-
import { AgentsClient, ToolUtility, DoneEvent, ErrorEvent, ThreadMessage } from '@azure/ai-agents';
5+
import { ToolUtility, DoneEvent, ErrorEvent, ThreadMessage } from '@azure/ai-agents';
66
import { AIProjectClient } from '@azure/ai-projects';
77
import { config } from 'dotenv';
88
config();
@@ -42,44 +42,44 @@ async function runAgents() {
4242
// <create_and_run_agent>
4343
const endpoint = process.env.PROJECT_ENDPOINT as string;
4444
const deployment = process.env.MODEL_DEPLOYMENT_NAME || 'gpt-4o';
45-
const client = new AgentsClient(endpoint, new DefaultAzureCredential());
45+
const client = new AIProjectClient(endpoint, new DefaultAzureCredential());
4646

4747
// Create an Agent
48-
const agent = await client.createAgent(deployment, {
48+
const agent = await client.agents.createAgent(deployment, {
4949
name: 'my-agent',
5050
instructions: 'You are a helpful agent'
5151
});
5252
console.log(`\n==================== 🕵️ POEM AGENT ====================`);
5353

5454
// Create a thread and message
55-
const thread = await client.threads.create();
55+
const thread = await client.agents.threads.create();
5656
const prompt = 'Write me a poem about flowers';
5757
console.log(`\n---------------- 📝 User Prompt ---------------- \n${prompt}`);
58-
await client.messages.create(thread.id, 'user', prompt);
58+
await client.agents.messages.create(thread.id, 'user', prompt);
5959

6060
// Create run
61-
let run = await client.runs.create(thread.id, agent.id);
61+
let run = await client.agents.runs.create(thread.id, agent.id);
6262

6363
// Wait for run to complete
6464
console.log(`\n---------------- 🚦 Run Status ----------------`);
6565
while (['queued', 'in_progress', 'requires_action'].includes(run.status)) {
6666
// Avoid adding a lot of messages to the console
6767
await new Promise((resolve) => setTimeout(resolve, 1000));
68-
run = await client.runs.get(thread.id, run.id);
68+
run = await client.agents.runs.get(thread.id, run.id);
6969
console.log(`Run status: ${run.status}`);
7070
}
7171

7272
console.log('\n---------------- 📊 Token Usage ----------------');
7373
console.table([run.usage]);
7474

75-
const messagesIterator = await client.messages.list(thread.id);
75+
const messagesIterator = await client.agents.messages.list(thread.id);
7676
const assistantMessage = await getAssistantMessage(messagesIterator);
7777
console.log('\n---------------- 💬 Response ----------------');
7878
printAssistantMessage(assistantMessage);
7979

8080
// Clean up
8181
console.log(`\n---------------- 🧹 Clean Up Poem Agent ----------------`);
82-
await client.deleteAgent(agent.id);
82+
await client.agents.deleteAgent(agent.id);
8383
console.log(`Deleted Agent, Agent ID: ${agent.id}`);
8484
// </create_and_run_agent>
8585

@@ -92,11 +92,11 @@ async function runAgents() {
9292
fileStream.on('data', (chunk: string | Buffer) => {
9393
console.log(`Read ${chunk.length} bytes of data.`);
9494
});
95-
const file = await client.files.upload(fileStream, 'assistants', {
95+
const file = await client.agents.files.upload(fileStream, 'assistants', {
9696
fileName: 'product_info_1.md'
9797
});
9898
console.log(`Uploaded file, ID: ${file.id}`);
99-
const vectorStore = await client.vectorStores.create({
99+
const vectorStore = await client.agents.vectorStores.create({
100100
fileIds: [file.id],
101101
name: 'my_vectorstore'
102102
});
@@ -111,21 +111,21 @@ async function runAgents() {
111111

112112
// Create an Agent and a FileSearch tool
113113
const fileSearchTool = ToolUtility.createFileSearchTool([vectorStore.id]);
114-
const fileAgent = await client.createAgent(deployment, {
114+
const fileAgent = await client.agents.createAgent(deployment, {
115115
name: 'my-file-agent',
116116
instructions: 'You are a helpful assistant and can search information from uploaded files',
117117
tools: [fileSearchTool.definition],
118-
toolResources: fileSearchTool.resources,
118+
toolResources: fileSearchTool.resources
119119
});
120120

121121
// Create a thread and message
122-
const fileSearchThread = await client.threads.create({ toolResources: fileSearchTool.resources });
122+
const fileSearchThread = await client.agents.threads.create({ toolResources: fileSearchTool.resources });
123123
const filePrompt = 'What are the steps to setup the TrailMaster X4 Tent?';
124124
console.log(`\n---------------- 📝 User Prompt ---------------- \n${filePrompt}`);
125-
await client.messages.create(fileSearchThread.id, 'user', filePrompt);
125+
await client.agents.messages.create(fileSearchThread.id, 'user', filePrompt);
126126

127127
// Create run
128-
let fileSearchRun = await client.runs.create(fileSearchThread.id, fileAgent.id).stream();
128+
let fileSearchRun = await client.agents.runs.create(fileSearchThread.id, fileAgent.id).stream();
129129

130130
for await (const eventMessage of fileSearchRun) {
131131
if (eventMessage.event === DoneEvent.Done) {
@@ -136,16 +136,16 @@ async function runAgents() {
136136
}
137137
}
138138

139-
const fileSearchMessagesIterator = await client.messages.list(fileSearchThread.id);
139+
const fileSearchMessagesIterator = await client.agents.messages.list(fileSearchThread.id);
140140
const fileAssistantMessage = await getAssistantMessage(fileSearchMessagesIterator);
141141
console.log(`\n---------------- 💬 Response ---------------- \n`);
142142
printAssistantMessage(fileAssistantMessage);
143143

144144
// Clean up
145145
console.log(`\n---------------- 🧹 Clean Up File Agent ----------------`);
146-
await client.vectorStores.delete(vectorStore.id);
147-
await client.files.delete(file.id);
148-
await client.deleteAgent(fileAgent.id);
146+
client.agents.vectorStores.delete(vectorStore.id);
147+
client.agents.files.delete(file.id);
148+
client.agents.deleteAgent(fileAgent.id);
149149
console.log(`Deleted VectorStore, File, and FileAgent. FileAgent ID: ${fileAgent.id}`);
150150
// </create_filesearch_agent>
151151
}

0 commit comments

Comments
 (0)