Added case for when evaluator does not have any target blocks

This commit is contained in:
Waleed Latif
2025-02-12 12:13:05 -08:00
parent ec2150ac3b
commit 3fb861b85a
2 changed files with 35 additions and 3 deletions
+11 -3
View File
@@ -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}
+24
View File
@@ -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}`)