@@ -146,17 +146,24 @@ export class GUIAgent<T extends Operator> extends BaseGUIAgent<
146
146
break ;
147
147
}
148
148
149
- if ( loopCnt >= maxLoopCount || snapshotErrCnt >= MAX_SNAPSHOT_ERR_CNT ) {
149
+ if ( loopCnt >= maxLoopCount ) {
150
150
Object . assign ( data , {
151
- status :
152
- loopCnt >= maxLoopCount ? StatusEnum . MAX_LOOP : StatusEnum . ERROR ,
153
- ...( snapshotErrCnt >= MAX_SNAPSHOT_ERR_CNT && {
154
- error : {
155
- code : ErrorStatusEnum . SCREENSHOT_ERROR ,
156
- error : 'Too many screenshot failures' ,
157
- stack : 'null' ,
158
- } ,
159
- } ) ,
151
+ status : StatusEnum . ERROR ,
152
+ ...this . guiAgentErrorParser (
153
+ null ,
154
+ ErrorStatusEnum . REACH_MAXLOOP_ERROR ,
155
+ ) ,
156
+ } ) ;
157
+ break ;
158
+ }
159
+
160
+ if ( snapshotErrCnt >= MAX_SNAPSHOT_ERR_CNT ) {
161
+ Object . assign ( data , {
162
+ status : StatusEnum . ERROR ,
163
+ ...this . guiAgentErrorParser (
164
+ null ,
165
+ ErrorStatusEnum . SCREENSHOT_RETRY_ERROR ,
166
+ ) ,
160
167
} ) ;
161
168
break ;
162
169
}
@@ -251,7 +258,19 @@ export class GUIAgent<T extends Operator> extends BaseGUIAgent<
251
258
parsedPredictions : [ ] ,
252
259
} ;
253
260
}
254
- throw error ;
261
+
262
+ Object . assign ( data , {
263
+ status : StatusEnum . ERROR ,
264
+ ...this . guiAgentErrorParser (
265
+ error ,
266
+ ErrorStatusEnum . INVOKE_RETRY_ERROR ,
267
+ ) ,
268
+ } ) ;
269
+
270
+ return {
271
+ prediction : '' ,
272
+ parsedPredictions : [ ] ,
273
+ } ;
255
274
}
256
275
} ,
257
276
{
@@ -260,14 +279,14 @@ export class GUIAgent<T extends Operator> extends BaseGUIAgent<
260
279
} ,
261
280
) ;
262
281
263
- logger . info ( '[GUIAgent Response] :' , prediction ) ;
282
+ logger . info ( '[GUIAgent] Response:' , prediction ) ;
264
283
logger . info (
265
- 'GUIAgent Parsed Predictions:' ,
284
+ '[ GUIAgent] Parsed Predictions:' ,
266
285
JSON . stringify ( parsedPredictions ) ,
267
286
) ;
268
287
269
288
if ( ! prediction ) {
270
- logger . error ( '[GUIAgent Response Empty] :' , prediction ) ;
289
+ logger . error ( '[GUIAgent] Response Empty:' , prediction ) ;
271
290
continue ;
272
291
}
273
292
@@ -302,27 +321,32 @@ export class GUIAgent<T extends Operator> extends BaseGUIAgent<
302
321
for ( const parsedPrediction of parsedPredictions ) {
303
322
const actionType = parsedPrediction . action_type ;
304
323
305
- logger . info ( 'GUIAgent Action:' , actionType ) ;
324
+ logger . info ( '[ GUIAgent] Action:' , actionType ) ;
306
325
307
326
// handle internal action spaces
308
327
if ( actionType === INTERNAL_ACTION_SPACES_ENUM . ERROR_ENV ) {
309
328
Object . assign ( data , {
310
329
status : StatusEnum . ERROR ,
311
- error : {
312
- code : ErrorStatusEnum . ENVIRONMENT_ERROR ,
313
- error : 'The environment error occurred when parsing the action' ,
314
- stack : 'null' ,
315
- } ,
330
+ error : this . guiAgentErrorParser (
331
+ null ,
332
+ ErrorStatusEnum . ENVIRONMENT_ERROR ,
333
+ ) ,
316
334
} ) ;
317
335
break ;
318
336
} else if ( actionType === INTERNAL_ACTION_SPACES_ENUM . MAX_LOOP ) {
319
- data . status = StatusEnum . MAX_LOOP ;
337
+ Object . assign ( data , {
338
+ status : StatusEnum . ERROR ,
339
+ error : this . guiAgentErrorParser (
340
+ null ,
341
+ ErrorStatusEnum . REACH_MAXLOOP_ERROR ,
342
+ ) ,
343
+ } ) ;
320
344
break ;
321
345
}
322
346
323
347
if ( ! signal ?. aborted && ! this . isStopped ) {
324
348
logger . info (
325
- 'GUIAgent Action Inputs:' ,
349
+ '[ GUIAgent] Action Inputs:' ,
326
350
parsedPrediction . action_inputs ,
327
351
parsedPrediction . action_type ,
328
352
) ;
@@ -342,7 +366,14 @@ export class GUIAgent<T extends Operator> extends BaseGUIAgent<
342
366
onRetry : retry ?. execute ?. onRetry ,
343
367
} ,
344
368
) . catch ( ( e ) => {
345
- logger . error ( 'GUIAgent execute error' , e ) ;
369
+ logger . error ( '[GUIAgent] execute error' , e ) ;
370
+ Object . assign ( data , {
371
+ status : StatusEnum . ERROR ,
372
+ ...this . guiAgentErrorParser (
373
+ e ,
374
+ ErrorStatusEnum . EXECUTE_RETRY_ERROR ,
375
+ ) ,
376
+ } ) ;
346
377
} ) ;
347
378
348
379
if ( executeOutput && executeOutput ?. status ) {
@@ -371,21 +402,23 @@ export class GUIAgent<T extends Operator> extends BaseGUIAgent<
371
402
}
372
403
}
373
404
} catch ( error ) {
374
- logger . error ( '[GUIAgent] run, catch error' , error ) ;
405
+ logger . error ( '[GUIAgent] Catch error' , error ) ;
375
406
if (
376
407
error instanceof Error &&
377
408
( error . name === 'AbortError' || error . message ?. includes ( 'aborted' ) )
378
409
) {
379
- logger . info ( 'Request was aborted' ) ;
410
+ logger . info ( '[GUIAgent] Catch: request was aborted' ) ;
380
411
data . status = StatusEnum . USER_STOPPED ;
381
412
return ;
382
413
}
383
414
384
415
data . status = StatusEnum . ERROR ;
385
- data . error = this . guiAgentErrorParser ( error as Error ) as GUIAgentError ;
416
+ data . error = this . guiAgentErrorParser ( error ) ;
386
417
387
418
throw error ;
388
419
} finally {
420
+ logger . info ( '[GUIAgent] Finally: status' , data . status ) ;
421
+
389
422
if ( data . status === StatusEnum . USER_STOPPED ) {
390
423
await operator . execute ( {
391
424
prediction : '' ,
@@ -401,18 +434,18 @@ export class GUIAgent<T extends Operator> extends BaseGUIAgent<
401
434
factors : [ 0 , 0 ] ,
402
435
} ) ;
403
436
}
437
+
404
438
await onData ?.( { data : { ...data , conversations : [ ] } } ) ;
439
+
405
440
if ( data . status === StatusEnum . ERROR ) {
406
441
onError ?.( {
407
442
data,
408
443
error : data . error || {
409
444
code : ErrorStatusEnum . UNKNOWN_ERROR ,
410
445
error : 'Unkown error occurred' ,
411
- stack : 'null' ,
412
446
} ,
413
447
} ) ;
414
448
}
415
- logger . info ( '[GUIAgent] finally: status' , data . status ) ;
416
449
}
417
450
}
418
451
@@ -448,7 +481,10 @@ export class GUIAgent<T extends Operator> extends BaseGUIAgent<
448
481
) ;
449
482
}
450
483
451
- private guiAgentErrorParser ( error : unknown ) : GUIAgentError {
484
+ private guiAgentErrorParser (
485
+ error : unknown ,
486
+ type : ErrorStatusEnum | null = null ,
487
+ ) : GUIAgentError {
452
488
if (
453
489
error instanceof Error &&
454
490
'status' in error &&
@@ -459,14 +495,56 @@ export class GUIAgent<T extends Operator> extends BaseGUIAgent<
459
495
) {
460
496
return {
461
497
code : ErrorStatusEnum . MODEL_SERVICE_ERROR ,
462
- error : error . message ,
498
+ error : error . error ,
463
499
stack : error . stack ,
500
+ detail : JSON . stringify ( error ) ,
501
+ } ;
502
+ }
503
+
504
+ if ( type === ErrorStatusEnum . REACH_MAXLOOP_ERROR ) {
505
+ return {
506
+ code : ErrorStatusEnum . REACH_MAXLOOP_ERROR ,
507
+ error : 'Has reached max loop count' ,
464
508
} ;
465
509
}
510
+
511
+ if ( type === ErrorStatusEnum . SCREENSHOT_RETRY_ERROR ) {
512
+ return {
513
+ code : ErrorStatusEnum . SCREENSHOT_RETRY_ERROR ,
514
+ error : 'Too many screenshot failures' ,
515
+ } ;
516
+ }
517
+
518
+ if ( type === ErrorStatusEnum . INVOKE_RETRY_ERROR ) {
519
+ return {
520
+ code : ErrorStatusEnum . INVOKE_RETRY_ERROR ,
521
+ error : 'Too many model invoke failures' ,
522
+ stack : 'null' ,
523
+ detail : JSON . stringify ( error ) ,
524
+ } ;
525
+ }
526
+
527
+ if ( type === ErrorStatusEnum . EXECUTE_RETRY_ERROR ) {
528
+ return {
529
+ code : ErrorStatusEnum . EXECUTE_RETRY_ERROR ,
530
+ error : 'Too many action execute failures' ,
531
+ stack : 'null' ,
532
+ detail : JSON . stringify ( error ) ,
533
+ } ;
534
+ }
535
+
536
+ if ( type === ErrorStatusEnum . ENVIRONMENT_ERROR ) {
537
+ return {
538
+ code : ErrorStatusEnum . ENVIRONMENT_ERROR ,
539
+ error : 'The environment error occurred when parsing the action' ,
540
+ } ;
541
+ }
542
+
466
543
return {
467
544
code : ErrorStatusEnum . UNKNOWN_ERROR ,
468
545
error : 'Unkown error occurred' ,
469
- stack : JSON . stringify ( error ) ,
546
+ stack : 'null' ,
547
+ detail : JSON . stringify ( error ) ,
470
548
} ;
471
549
}
472
550
}
0 commit comments