(prompt: string, targetBlocks?: TargetBlock[])
| 45 | * Generates the system prompt for the legacy router (block-based). |
| 46 | */ |
| 47 | export const generateRouterPrompt = (prompt: string, targetBlocks?: TargetBlock[]): string => { |
| 48 | const basePrompt = `You are an intelligent routing agent responsible for directing workflow requests to the most appropriate block. Your task is to analyze the input and determine the single most suitable destination based on the request. |
| 49 | |
| 50 | Key Instructions: |
| 51 | 1. You MUST choose exactly ONE destination from the IDs of the blocks in the workflow. The destination must be a valid block id. |
| 52 | |
| 53 | 2. Analysis Framework: |
| 54 | - Carefully evaluate the intent and requirements of the request |
| 55 | - Consider the primary action needed |
| 56 | - Match the core functionality with the most appropriate destination` |
| 57 | |
| 58 | // If we have target blocks, add their information to the prompt |
| 59 | const targetBlocksInfo = targetBlocks |
| 60 | ? ` |
| 61 | |
| 62 | Available Target Blocks: |
| 63 | ${targetBlocks |
| 64 | .map( |
| 65 | (block) => ` |
| 66 | ID: ${block.id} |
| 67 | Type: ${block.type} |
| 68 | Title: ${block.title} |
| 69 | Description: ${block.description} |
| 70 | System Prompt: ${JSON.stringify(block.subBlocks?.systemPrompt || '')} |
| 71 | Configuration: ${JSON.stringify(block.subBlocks, null, 2)} |
| 72 | ${block.currentState ? `Current State: ${JSON.stringify(block.currentState, null, 2)}` : ''} |
| 73 | ---` |
| 74 | ) |
| 75 | .join('\n')} |
| 76 | |
| 77 | Routing Instructions: |
| 78 | 1. Analyze the input request carefully against each block's: |
| 79 | - Primary purpose (from title, description, and system prompt) |
| 80 | - Look for keywords in the system prompt that match the user's request |
| 81 | - Configuration settings |
| 82 | - Current state (if available) |
| 83 | - Processing capabilities |
| 84 | |
| 85 | 2. Selection Criteria: |
| 86 | - Choose the block that best matches the input's requirements |
| 87 | - Consider the block's specific functionality and constraints |
| 88 | - Factor in any relevant current state or configuration |
| 89 | - Prioritize blocks that can handle the input most effectively` |
| 90 | : '' |
| 91 | |
| 92 | return `${basePrompt}${targetBlocksInfo} |
| 93 | |
| 94 | Routing Request: ${prompt} |
| 95 | |
| 96 | Response Format: |
| 97 | Return ONLY the destination id as a single word, lowercase, no punctuation or explanation. |
| 98 | Example: "2acd9007-27e8-4510-a487-73d3b825e7c1" |
| 99 | |
| 100 | Remember: Your response must be ONLY the block ID - no additional text, formatting, or explanation.` |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Generates the system prompt for the port-based router (v2). |
no test coverage detected