Skip to content

Commit 204af30

Browse files
committed
agent tool error
1 parent 8a56a95 commit 204af30

File tree

8 files changed

+483
-36
lines changed

8 files changed

+483
-36
lines changed

agent-message-2.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"data": {
3+
"id": "run_h1AAJ25FuI0sXKEpqfKwJC6K",
4+
"object": "thread.run",
5+
"created_at": 1749046155,
6+
"assistant_id": "asst_VHRy7r1EEu11x4jbkNlD9BZ6",
7+
"thread_id": "thread_oLHxCoMn8WG6JwYWC6NkEkWt",
8+
"status": "queued",
9+
"started_at": null,
10+
"expires_at": 1749046755,
11+
"cancelled_at": null,
12+
"failed_at": null,
13+
"completed_at": null,
14+
"required_action": null,
15+
"last_error": null,
16+
"model": "gpt-4o",
17+
"instructions": "You are a helpful agent",
18+
"tools": [
19+
{
20+
"type": "code_interpreter"
21+
}
22+
],
23+
"tool_resources": {
24+
"code_interpreter": {
25+
"file_ids": []
26+
}
27+
},
28+
"metadata": {},
29+
"temperature": 1,
30+
"top_p": 1,
31+
"max_completion_tokens": null,
32+
"max_prompt_tokens": null,
33+
"truncation_strategy": {
34+
"type": "auto",
35+
"last_messages": null
36+
},
37+
"incomplete_details": null,
38+
"usage": null,
39+
"response_format": "auto",
40+
"tool_choice": "auto",
41+
"parallel_tool_calls": true
42+
},
43+
"event": "thread.run.queued"
44+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"data": {
3+
"id": "step_3jvJW2ljvo9BiGrjI7dWLnTD",
4+
"object": "thread.run.step",
5+
"created_at": 1749049871,
6+
"run_id": "run_2JDnauXAoaz9zUO3po6dDQVo",
7+
"assistant_id": "asst_T7EVn6EY9SffNjBSWfPquRCl",
8+
"thread_id": "thread_m9EbMt50BauuWS1U73onUcEa",
9+
"type": "message_creation",
10+
"status": "failed",
11+
"cancelled_at": null,
12+
"completed_at": null,
13+
"expires_at": 1749050464,
14+
"failed_at": 1749049876,
15+
"last_error": {
16+
"code": "rate_limit_exceeded",
17+
"message": "Rate limit is exceeded. Try again in 50 seconds."
18+
},
19+
"step_details": {
20+
"type": "message_creation",
21+
"message_creation": {
22+
"message_id": "msg_GbuHVL7n2sK2ynWy6pcovMP8"
23+
}
24+
},
25+
"usage": {
26+
"prompt_tokens": 1490,
27+
"completion_tokens": 37,
28+
"total_tokens": 1527,
29+
"prompt_token_details": {
30+
"cached_tokens": 0
31+
}
32+
}
33+
},
34+
"event": "thread.run.step.failed"
35+
}

agent-message.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"data": {
3+
"id": "msg_h52NoePFcWOOjIm4iKqdlh1O",
4+
"object": "thread.message",
5+
"created_at": 1749046163,
6+
"assistant_id": "asst_VHRy7r1EEu11x4jbkNlD9BZ6",
7+
"thread_id": "thread_oLHxCoMn8WG6JwYWC6NkEkWt",
8+
"run_id": "run_h1AAJ25FuI0sXKEpqfKwJC6K",
9+
"status": "completed",
10+
"incomplete_details": null,
11+
"incomplete_at": null,
12+
"completed_at": 1749046164,
13+
"role": "assistant",
14+
"content": [
15+
{
16+
"type": "text",
17+
"text": {
18+
"value": "The data has been filtered for companies in the transportation industry. Four companies were found:\n\n1. Consolidated Messenger: Operating profit = 290.7\n2. Northwind Traders: Operating profit = 9166.0\n3. Tailwind Traders: Operating profit = 164.9\n4. Wide World Importers: Operating profit = 473.6\n\nNow, I'll proceed to generate the bar chart illustrating this data.",
19+
"annotations": []
20+
}
21+
}
22+
],
23+
"attachments": [],
24+
"metadata": {}
25+
},
26+
"event": "thread.message.completed"
27+
}

output.txt

Lines changed: 319 additions & 0 deletions
Large diffs are not rendered by default.

quickstarts/ai-agents/ts/az-cli-roles-dina.sh

Lines changed: 0 additions & 24 deletions
This file was deleted.

quickstarts/ai-agents/ts/data/niftyList.csv

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
name,revenue,operating_expenses,operating_profit,operating_profit_margin,depreciation,interest,profit_before_tax,tax,net_profit,EPS,profit_TTM,EPS_TTM,industry,sector
1+
name,revenue,operating_expenses,operating_profit,operating_profit_margin,depreciation,interest,profit_before_tax,tax,net_profit,EPS,profit_TTM,EPS_TTM,sector,industry
22
"Adatum Corporation","1,057","847.4","192.1","18.48%","12.9","0.7","195.9","49.8","146.1","129.7","535.9","475.7","Technology","Information Technology"
33
"Adventure Works Cycles","4,644.8","3,885.4","549.3","12.39%","212.8","28.9","517.7","131.5","387.9","20.7","1,202.7","64","Retail","Consumer Discretionary"
44
"Alpine Ski House","1,357.1","912.7","382.1","29.51%","24.5","7.4","412.5","88.4","323.1","34.3","1,216.1","128.9","Hospitality/Leisure","Consumer Discretionary"
5-
"Bellows College","4,65","4,305.4","325","7.02%","41.3","26.6","276.7","73.8","202.9","7.3","767.5","27.7","Education","Consumer Discretionary"
5+
"Bellows College","4,650","4,305.4","325","7.02%","41.3","26.6","276.7","73.8","202.9","7.3","767.5","27.7","Education","Consumer Discretionary"
66
"Best For You Organics Company","2,956.5","1,026.7","647.7","25.59%","0","1,282.1","533.4","131.5","401.8","6","1,606.2","24","Food & Beverage","Consumer Staples"
77
"Boulder Innovations","6,951.9","2,982.4","3,664","55.13%","974.5","520.1","2,474.9","759","1,747.8","8.1","6,337","29.3","Technology","Information Technology"
88
"Contoso","3,766.5","2,169.3","1,504.6","40.95%","432.1","640.8","369.9","84.9","275.9","2.5","1,315.1","11.8","Technology","Information Technology"
@@ -12,7 +12,7 @@ name,revenue,operating_expenses,operating_profit,operating_profit_margin,depreci
1212
"Fabrikam","1,605.1","1,386.7","208.2","13.06%","67.6","15.7","135.1","-1.9","136.6","7","531.7","27","Technology","Information Technology"
1313
"Fabrikam Residences","3,503.4","2,693.4","746.7","21.71%","73.9","30.3","648","33.1","620.5","51.9","1,432.9","119.9","Real Estate","Real Estate"
1414
"First Up Consultants","2,988.6","2,556.9","402.5","13.60%","115.7","6.2","309.8","83.5","226.3","13.2","779.8","45.7","Professional services","Industrials"
15-
"Fourth Coffee","7,9","6,122.1","1,301.8","17.54%","380.9","61.2","1,335.7","352.5","793","4","2,777.9","14","Food & Beverage","Consumer Staples"
15+
"Fourth Coffee","7,900","6,122.1","1,301.8","17.54%","380.9","61.2","1,335.7","352.5","983.2","4","2,777.9","14","Food & Beverage","Consumer Staples"
1616
"Graphic Design Institute","4,869.1","4,219.4","627.5","12.95%","163.4","111.3","376.9","130.2","232.9","16.2","697.5","48.5","Education","Consumer Discretionary"
1717
"Humongous Insurance","6,304.9","5,119.8","1,159.8","18.47%","360.3","132.8","679.9","205.8","474.3","7.5","1,590.7","25","Financial services","Financials"
1818
"Lakeshore Retail","11,463","9,558.6","1,870.4","16.37%","226.6","715.1","924.4","358","526","1.8","2,141.5","7.3","Retail","Consumer Discretionary"
@@ -23,10 +23,10 @@ name,revenue,operating_expenses,operating_profit,operating_profit_margin,depreci
2323
"Munson's Pickles and Preserves Farm","1,312","1,184.5","94","7.35%","14.3","0.2","113","30.5","74.2","5.5","336.4","24.7","Food & Beverage","Consumer Staples"
2424
"Nod Publishers","12,661.3","11,619.4","1,005","7.96%","174.4","15.6","851.9","228.6","623.6","9.6","2,332.1","35.8","Publishing","Communication Services"
2525
"Northwind Traders","33,122.2","9,207.3","9,166","33.43%","0","14,749","8,313.8","2,096.1","6,204.1","20.1","13,121","42.6","Transportation","Industrials"
26-
"Proseware","11,206.8","8,708.1","2,130.1","19.65%","91.8","6.5","2,400.4","564","2,02","71.4","6,841.6","241.8","Technology","Information Technology"
26+
"Proseware","11,206.8","8,708.1","2,130.1","19.65%","91.8","6.5","2,400.4","564","1,836.4","71.4","6,841.6","241.8","Technology","Information Technology"
2727
"Relecloud","13,381.8","2,851.5","9,449.7","70.63%","158.5","4,537.1","4,757.6","1,207","3,550.8","58.7","13,118.5","216.7","Technology","Information Technology"
28-
"School of Fine Art","26,022.7","14,992.2","9,949.9","38.24%","208.8","4,449.1","5,292","1,536.5","1,929","12.1","7,422.6","46.6","Education","Consumer Discretionary"
29-
"Southridge Video","240.1","33.5","191.2","85.08%","8.4","0.2","197.9","73.9","1,491.2","134","5,545.1","498.3","Entertainment","Communication Services"
28+
"School of Fine Art","26,022.7","14,992.2","9,949.9","38.24%","208.8","4,449.1","5,292","1,536.5","3,755.5","12.1","7,422.6","46.6","Education","Consumer Discretionary"
29+
"Southridge Video","240.1","33.5","191.2","85.08%","8.4","0.2","197.9","73.9","124.0","134","5,545.1","498.3","Entertainment","Communication Services"
3030
"Tailspin Toys","2,360.3","1,720.5","532.7","23.64%","160.4","23.9","455.5","108.1","347.4","18","1,047.5","54.2","Retail","Consumer Discretionary"
3131
"Tailwind Traders","1,649","1,374.6","164.9","10.71%","41.2","17.2","215.9","56.6","166.3","8.2","540.5","26.8","Transportation","Industrials"
3232
"Trey Research","35,766","8,430.4","9,807.9","33.52%","0","17,527.7","6,022.8","1,679.7","4,458.4","8.5","18,602.9","35.9","R&D","Information Technology"

quickstarts/ai-agents/ts/src/codeInterpreterWithStreaming.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,16 @@ const modelDeploymentName = process.env["MODEL_DEPLOYMENT_NAME"] || "gpt-4o";
3434

3535
export async function main(): Promise<void> {
3636
// Create an Azure AI Client
37-
const client = new AgentsClient(projectEndpoint, new DefaultAzureCredential());
37+
const client = new AgentsClient(projectEndpoint, new DefaultAzureCredential(), {
38+
retryOptions: {
39+
maxRetries: 3,
40+
retryDelayInMs: 2000
41+
}
42+
});
3843

3944
// Upload file and wait for it to be processed
4045
const filePath = "./data/niftyList.csv";
46+
console.log(`Uploading file from path: ${filePath}`);
4147
const localFileStream = fs.createReadStream(filePath);
4248
const localFile = await client.files.upload(localFileStream, "assistants", {
4349
fileName: "myLocalFile",
@@ -65,7 +71,7 @@ export async function main(): Promise<void> {
6571
const message = await client.messages.create(
6672
thread.id,
6773
"user",
68-
"Could you please create a bar chart in the USA transportation industry for the operating profit from the uploaded CSV file and provide the file to me? If you can't create an image file, please provide the data in a text format and say what is wrong with the data to stop you from generating the image.",
74+
"Could you please create a bar chart to explain the operating profit for companies related to the transportation area from the uploaded CSV file and provide the file to me?",
6975
);
7076

7177
console.log(`Created message, message ID: ${message.id}`);
@@ -101,7 +107,34 @@ export async function main(): Promise<void> {
101107
console.log("Stream completed.");
102108
break;
103109
default:
104-
console.log(`Unknown event type: ${eventMessage.event}`);
110+
111+
console.log(`Unhandled event type: ${JSON.stringify(eventMessage)}`);
112+
113+
let waitSeconds = 1000;
114+
115+
if (eventMessage.event.includes("thread.message")) {
116+
const messageType = eventMessage.event;
117+
const message = eventMessage?.data?.content?.forEach((contentPart) => {
118+
if (contentPart.type === "text") {
119+
120+
const message: string = contentPart.text?.value || "No text";
121+
122+
if( message.includes("Rate limit is exceeded. Try again in ")) {
123+
const regex = /Rate limit is exceeded. Try again in (\d+) seconds/;
124+
const match = message.match(regex);
125+
if (match && match[1]) {
126+
waitSeconds = parseInt(match[1], 10) * 1000; // Convert seconds to milliseconds
127+
console.log(`Rate limit exceeded, waiting for ${waitSeconds} milliseconds`);
128+
return new Promise((resolve) => setTimeout(resolve, waitSeconds));
129+
}
130+
} else {
131+
132+
return contentPart?.text?.value + ", " || "no text, ";
133+
}
134+
}
135+
});
136+
console.log(`${messageType} received:: ${eventMessage?.event}`);
137+
}
105138
break;
106139
}
107140
}
@@ -122,9 +155,9 @@ export async function main(): Promise<void> {
122155
const assistantMessage = messagesArray.find((msg) => msg.role === "assistant");
123156
if (assistantMessage) {
124157
// Look for an image file in the assistant's message
125-
const imageFileOutput = assistantMessage.content.find(content =>
158+
const imageFileOutput = assistantMessage.content.find(content =>
126159
content.type === "image_file" && content.imageFile?.fileId);
127-
160+
128161
if (imageFileOutput) {
129162
try {
130163
// Save the newly created file

quickstarts/ai-agents/ts/src/index.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,14 @@ async function downloadGeneratedFiles(
230230
}
231231

232232
const imageFileName = path.resolve(
233+
"./data/" + (await client.files.get(imageFileId)).filename + "ImageFile.png",
234+
);
235+
console.log(`Image file name : ${imageFileName}`);
236+
237+
const fileContent = await (await client.files.getContent(imageFileId).asNodeStream()).body;
238+
if (!fileContent) {
239+
console.log("No file content available");
240+
return;
233241
}
234242

235243
const chunks = [];
@@ -275,7 +283,12 @@ async function cleanupResources(
275283
async function main() {
276284
try {
277285
// Create an Azure AI Client
278-
const client = new AgentsClient(projectEndpoint, new DefaultAzureCredential());
286+
const client = new AgentsClient(projectEndpoint, new DefaultAzureCredential(), {
287+
retryOptions: {
288+
maxRetries: 3, // number of retry attempts
289+
retryDelayInMs: 2000 // delay between retries in milliseconds
290+
}
291+
});
279292

280293
// Step 1: Setup agent and resources
281294
const { agent, thread, localFile } = await setupAgentAndResources(client);

0 commit comments

Comments
 (0)