MCPcopy Index your code
hub / github.com/simstudioai/sim / generateRouterPrompt

Function generateRouterPrompt

apps/sim/blocks/blocks/router.ts:47–101  ·  view source on GitHub ↗
(prompt: string, targetBlocks?: TargetBlock[])

Source from the content-addressed store, hash-verified

45 * Generates the system prompt for the legacy router (block-based).
46 */
47export 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
50Key Instructions:
511. You MUST choose exactly ONE destination from the IDs of the blocks in the workflow. The destination must be a valid block id.
52
532. 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
62Available Target Blocks:
63${targetBlocks
64 .map(
65 (block) => `
66ID: ${block.id}
67Type: ${block.type}
68Title: ${block.title}
69Description: ${block.description}
70System Prompt: ${JSON.stringify(block.subBlocks?.systemPrompt || '')}
71Configuration: ${JSON.stringify(block.subBlocks, null, 2)}
72${block.currentState ? `Current State: ${JSON.stringify(block.currentState, null, 2)}` : ''}
73---`
74 )
75 .join('\n')}
76
77Routing Instructions:
781. 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
852. 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
94Routing Request: ${prompt}
95
96Response Format:
97Return ONLY the destination id as a single word, lowercase, no punctuation or explanation.
98Example: "2acd9007-27e8-4510-a487-73d3b825e7c1"
99
100Remember: 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).

Callers 3

blocks.test.tsFile · 0.90
executeLegacyMethod · 0.90
router.tsFile · 0.85

Calls 1

joinMethod · 0.80

Tested by

no test coverage detected