diff --git a/blocks/blocks/evaluator.ts b/blocks/blocks/evaluator.ts index ce2d345386..c4eb746a7d 100644 --- a/blocks/blocks/evaluator.ts +++ b/blocks/blocks/evaluator.ts @@ -59,8 +59,17 @@ ${content} Criteria: ${evaluationCriteria}` - const targetBlocksInfo = targetBlocks - ? ` + // If no target blocks, just return the evaluation without routing + if (!targetBlocks || targetBlocks.length === 0) { + return `${basePrompt} + +Response Format: +Return ONLY "end" to indicate no further routing is needed. + +Remember: Your response must be ONLY the word "end" - no additional text, formatting, or explanation.` + } + + const targetBlocksInfo = ` Available Destinations: ${targetBlocks .map( @@ -79,7 +88,6 @@ ${ : `- Score greater than or equal to 0.85: Choose success path block - Score less than 0.85: Choose failure path block` }` - : '' return `${basePrompt}${targetBlocksInfo} diff --git a/executor/index.ts b/executor/index.ts index 4d107f858b..9c24506c3f 100644 --- a/executor/index.ts +++ b/executor/index.ts @@ -720,6 +720,30 @@ export class Executor { const chosenBlockId = response.content.trim().toLowerCase() + // Handle case where evaluator has no targets + if (chosenBlockId === 'end') { + const result = { + content: evaluatorConfig.content, + model: response.model, + tokens: { + prompt: response.tokens?.prompt || 0, + completion: response.tokens?.completion || 0, + total: response.tokens?.total || 0, + }, + selectedPath: { + blockId: '', + blockType: '', + blockTitle: '', + }, + } + + context.blockStates.set(block.id, { + response: result, + }) + + return result + } + const chosenBlock = targetBlocks.find((b) => b.id === chosenBlockId) if (!chosenBlock) { throw new Error(`Invalid evaluation decision: ${chosenBlockId}`)