@@ -864,7 +864,7 @@ export class TaskExecutor {
864864 }
865865
866866 private createTypeQueryTask (
867- type : 'Query' | 'Boolean' | 'Number' | 'String' | 'Assert' ,
867+ type : 'Query' | 'Boolean' | 'Number' | 'String' | 'Assert' | 'WaitFor' ,
868868 demand : InsightExtractParam ,
869869 modelConfig : IModelConfig ,
870870 opt ?: InsightExtractOption ,
@@ -906,10 +906,14 @@ export class TaskExecutor {
906906 const ifTypeRestricted = type !== 'Query' ;
907907 let demandInput = demand ;
908908 let keyOfResult = 'result' ;
909- if ( ifTypeRestricted && type === 'Assert' ) {
909+ if ( ifTypeRestricted && ( type === 'Assert' || type === 'WaitFor' ) ) {
910910 keyOfResult = 'StatementIsTruthy' ;
911+ const booleanPrompt =
912+ type === 'Assert'
913+ ? `Boolean, whether the following statement is true: ${ demand } `
914+ : `Boolean, the user wants to do some 'wait for' operation, please check whether the following statement is true: ${ demand } ` ;
911915 demandInput = {
912- [ keyOfResult ] : `Boolean, whether the following statement is true: ${ demand } ` ,
916+ [ keyOfResult ] : booleanPrompt ,
913917 } ;
914918 } else if ( ifTypeRestricted ) {
915919 demandInput = {
@@ -931,7 +935,7 @@ export class TaskExecutor {
931935 outputResult = data ;
932936 } else {
933937 assert (
934- data ?. [ keyOfResult ] !== undefined ,
938+ type !== 'WaitFor' ? data ?. [ keyOfResult ] !== undefined : true ,
935939 'No result in query data' ,
936940 ) ;
937941 outputResult = ( data as any ) [ keyOfResult ] ;
@@ -940,7 +944,7 @@ export class TaskExecutor {
940944
941945 return {
942946 output : outputResult ,
943- log : { dump : insightDump , isWaitForAssert : opt ?. isWaitForAssert } ,
947+ log : insightDump ,
944948 usage,
945949 thought,
946950 } ;
@@ -992,21 +996,6 @@ export class TaskExecutor {
992996 } ;
993997 }
994998
995- async assert (
996- assertion : TUserPrompt ,
997- modelConfig : IModelConfig ,
998- opt ?: InsightExtractOption ,
999- ) : Promise < ExecutionResult < boolean > > {
1000- const { textPrompt, multimodalPrompt } = parsePrompt ( assertion ) ;
1001- return await this . createTypeQueryExecution < boolean > (
1002- 'Assert' ,
1003- textPrompt ,
1004- modelConfig ,
1005- opt ,
1006- multimodalPrompt ,
1007- ) ;
1008- }
1009-
1010999 private async appendErrorPlan (
10111000 taskExecutor : Executor ,
10121001 errorMsg : string ,
@@ -1074,15 +1063,13 @@ export class TaskExecutor {
10741063 const overallStartTime = Date . now ( ) ;
10751064 let startTime = Date . now ( ) ;
10761065 let errorThought = '' ;
1077- let hitError = false ;
10781066 while ( Date . now ( ) - overallStartTime < timeoutMs ) {
10791067 startTime = Date . now ( ) ;
10801068 const queryTask = await this . createTypeQueryTask (
1081- 'Assert ' ,
1069+ 'WaitFor ' ,
10821070 textPrompt ,
10831071 modelConfig ,
10841072 {
1085- isWaitForAssert : true ,
10861073 doNotThrowError : true ,
10871074 } ,
10881075 multimodalPrompt ,
@@ -1096,20 +1083,6 @@ export class TaskExecutor {
10961083 }
10971084 | undefined ;
10981085
1099- // If executor enters error state, stop polling immediately
1100- if ( taskExecutor . isInErrorState ( ) ) {
1101- errorThought =
1102- taskExecutor . latestErrorTask ( ) ?. errorMessage ||
1103- `Error occurred during waitFor: ${ textPrompt } ` ;
1104- hitError = true ;
1105- break ;
1106- }
1107-
1108- if ( ! result ) {
1109- errorThought = `No result from assertion: ${ textPrompt } ` ;
1110- break ;
1111- }
1112-
11131086 if ( result ?. output ) {
11141087 return {
11151088 output : undefined ,
@@ -1119,6 +1092,7 @@ export class TaskExecutor {
11191092
11201093 errorThought =
11211094 result ?. thought ||
1095+ ( ! result && `No result from assertion: ${ textPrompt } ` ) ||
11221096 `unknown error when waiting for assertion: ${ textPrompt } ` ;
11231097 const now = Date . now ( ) ;
11241098 if ( now - startTime < checkIntervalMs ) {
@@ -1128,15 +1102,6 @@ export class TaskExecutor {
11281102 }
11291103 }
11301104
1131- // If executor is already in error state, don't try to append error plan
1132- // Just return the executor with existing error information
1133- if ( hitError ) {
1134- return {
1135- output : undefined ,
1136- executor : taskExecutor ,
1137- } ;
1138- }
1139-
11401105 return this . appendErrorPlan (
11411106 taskExecutor ,
11421107 `waitFor timeout: ${ errorThought } ` ,
0 commit comments