@@ -2,7 +2,7 @@ import fs from 'fs';
22import path from 'path' ;
33import { fileURLToPath } from 'url' ;
44import { DefaultAzureCredential } from '@azure/identity' ;
5- import { AgentsClient , ToolUtility , DoneEvent , ErrorEvent } from '@azure/ai-agents' ;
5+ import { ToolUtility , DoneEvent , ErrorEvent } from '@azure/ai-agents' ;
66import { AIProjectClient } from '@azure/ai-projects' ;
77import { config } from 'dotenv' ;
88config ( ) ;
@@ -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+ }
0 commit comments