@minded-ai/mindedjs 2.0.1-beta-5 → 2.0.1-beta-6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"createPromptRouter.d.ts","sourceRoot":"","sources":["../../src/edges/createPromptRouter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAEzE,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AA8C3D,eAAO,MAAM,kBAAkB,yFAO5B;IACD,KAAK,EAAE,mBAAmB,EAAE,CAAC;IAC7B,GAAG,EAAE,iBAAiB,CAAC;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,aACsB,OAAO,eAAe,CAAC,KAAK,oBAoJlD,CAAC"}
1
+ {"version":3,"file":"createPromptRouter.d.ts","sourceRoot":"","sources":["../../src/edges/createPromptRouter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAEzE,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AA+C3D,eAAO,MAAM,kBAAkB,yFAO5B;IACD,KAAK,EAAE,mBAAmB,EAAE,CAAC;IAC7B,GAAG,EAAE,iBAAiB,CAAC;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,aACsB,OAAO,eAAe,CAAC,KAAK,oBA8JlD,CAAC"}
@@ -4,16 +4,17 @@ exports.createPromptRouter = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const messages_1 = require("@langchain/core/messages");
6
6
  const logger_1 = require("../utils/logger");
7
+ const compilePrompt_1 = require("../nodes/compilePrompt");
7
8
  const ROUTER_PROMPT = `
8
9
  You are a routing agent that decides which node to take in a flow based on the current state.
9
10
  Based on the conversation history and memory state, you should classify the next step for the conversation.
10
11
  Each step has a nodeId and a condition. You should decide to move to the right step based on the condition.
11
12
 
12
13
  Here are the available options and their conditions:
13
- {steps}
14
+ <%= steps %>
14
15
 
15
16
  Recent messages:
16
- {messages}
17
+ <%= messages %>
17
18
 
18
19
  You MUST respond with the exact nodeId from the options above. Do not use step numbers or any other identifiers.
19
20
 
@@ -31,10 +32,10 @@ Based on the conversation history and memory state, you should classify the next
31
32
  Each step has a nodeId and a condition. You should decide to move to the right step based on the condition.
32
33
 
33
34
  Here are the available options and their conditions:
34
- {steps}
35
+ <%= steps %>
35
36
 
36
37
  Recent messages:
37
- {messages}
38
+ <%= messages %>
38
39
 
39
40
  You MUST respond with the exact nodeId from the options above. Do not use step numbers or any other identifiers.
40
41
 
@@ -69,7 +70,13 @@ const createPromptRouter = ({ edges, llm, includeReasoning = true, maxRetries =
69
70
  stepsStr = `- Node: "${currentNodeName}" (stay in current node)\n`;
70
71
  }
71
72
  // Add the edge options
72
- stepsStr += edges.map((edge) => `- Node: "${edge.target}" - Condition: "${edge.prompt}"`).join('\n');
73
+ stepsStr += edges
74
+ .map((edge) => {
75
+ // Compile edge prompts with EJS to support templates in conditions
76
+ const compiledPrompt = (0, compilePrompt_1.compilePrompt)(edge.prompt || '', { memory: state.memory });
77
+ return `- Node: "${edge.target}" - Condition: "${compiledPrompt}"`;
78
+ })
79
+ .join('\n');
73
80
  // Prepare recent messages (last 10 messages for context)
74
81
  const recentMessages = state.messages.slice(-10);
75
82
  const messagesStr = recentMessages
@@ -80,9 +87,13 @@ const createPromptRouter = ({ edges, llm, includeReasoning = true, maxRetries =
80
87
  })
81
88
  .join('\n');
82
89
  // Select prompt based on reasoning preference
83
- let routerPrompt = includeReasoning ? ROUTER_PROMPT : ROUTER_PROMPT_WITHOUT_REASONING;
84
- // Replace placeholders in prompt
85
- routerPrompt = routerPrompt.replace('{steps}', stepsStr).replace('{messages}', messagesStr);
90
+ const promptTemplate = includeReasoning ? ROUTER_PROMPT : ROUTER_PROMPT_WITHOUT_REASONING;
91
+ // Compile prompt with EJS and parameters
92
+ const routerPrompt = (0, compilePrompt_1.compilePrompt)(promptTemplate, {
93
+ steps: stepsStr,
94
+ messages: messagesStr,
95
+ memory: state.memory,
96
+ });
86
97
  // Define response schema
87
98
  const responseSchema = includeReasoning
88
99
  ? zod_1.z.object({
@@ -1 +1 @@
1
- {"version":3,"file":"createPromptRouter.js","sourceRoot":"","sources":["../../src/edges/createPromptRouter.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAGxB,uDAAyD;AAEzD,4CAAyC;AAEzC,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;CAoBrB,CAAC;AAEF,MAAM,+BAA+B,GAAG;;;;;;;;;;;;;;;;;;;CAmBvC,CAAC;AAEK,MAAM,kBAAkB,GAAG,CAAC,EACjC,KAAK,EACL,GAAG,EACH,gBAAgB,GAAG,IAAI,EACvB,UAAU,GAAG,CAAC,EACd,oBAAoB,GAAG,KAAK,EAC5B,eAAe,GAQhB,EAAE,EAAE;IACH,OAAO,KAAK,EAAE,KAAmC,EAAE,EAAE;;QACnD,eAAM,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,kCAAkC,EAAE,eAAe,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;QAE9G,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;YACf,eAAM,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,0BAA0B,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,KAA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,IAAI,EAAE,UAAU,CAAC;IACjB,GAAG,EAAE,iBAAiB,CAAC;IACvB,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;IACxB,IAAI,EAAE,aAAa,CAAC,GAAG,EAAE,MAAM,yBAAyB,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/D,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEF,eAAO,MAAM,aAAa,6CAAoD,mBAAmB,kBAmPhG,CAAC"}
@@ -50,9 +50,6 @@ const addPromptNode = async ({ graph, node, llm, tools, emit, agent }) => {
50
50
  * When humanInTheLoop is false: Return immediately after tool execution without
51
51
  * additional LLM invocations.
52
52
  */
53
- const newMessages = [];
54
- const newHistory = [];
55
- let currentMessages = [...state.messages];
56
53
  let finalAIMessage = null;
57
54
  let loopCount = 0;
58
55
  const MAX_LOOP_ITERATIONS = 10;
@@ -69,18 +66,11 @@ const addPromptNode = async ({ graph, node, llm, tools, emit, agent }) => {
69
66
  break;
70
67
  }
71
68
  const startTime = Date.now();
72
- const result = await llmToUse.bindTools(scopedTools).invoke([new messages_1.SystemMessage(compiledPrompt), ...currentMessages]);
69
+ const result = await llmToUse.bindTools(scopedTools).invoke(state.messages);
73
70
  // Always pass accumulated state to interrupt manager
74
71
  // Pass the accumulated messages from this prompt node execution
75
72
  // If empty, pass undefined to avoid empty state updates
76
- const interruptState = newMessages.length > 0 || newHistory.length > 0
77
- ? {
78
- ...state,
79
- messages: [...state.messages, ...newMessages],
80
- history: [...state.history, ...newHistory],
81
- }
82
- : undefined;
83
- await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId, interruptState);
73
+ await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId, state);
84
74
  const endTime = Date.now();
85
75
  logger_1.logger.debug({
86
76
  msg: '[Model] Model execution time',
@@ -90,9 +80,8 @@ const addPromptNode = async ({ graph, node, llm, tools, emit, agent }) => {
90
80
  });
91
81
  // Check if the result contains tool calls
92
82
  if (result.tool_calls && result.tool_calls.length > 0) {
93
- // Add the tool call message
94
- newMessages.push(result);
95
- newHistory.push((0, history_1.createHistoryStep)(state.history, {
83
+ state.messages.push(result);
84
+ state.history.push((0, history_1.createHistoryStep)(state.history, {
96
85
  type: Flows_types_1.NodeType.TOOL,
97
86
  nodeId: node.name,
98
87
  nodeDisplayName: node.displayName,
@@ -100,8 +89,6 @@ const addPromptNode = async ({ graph, node, llm, tools, emit, agent }) => {
100
89
  messageIds: [result.id],
101
90
  }));
102
91
  // Execute the tools
103
- // Track how many tool responses we've added for validation
104
- const toolResponseStartIndex = newMessages.length;
105
92
  // Ensure we process ALL tool calls, even if some fail
106
93
  for (let toolIndex = 0; toolIndex < result.tool_calls.length; toolIndex++) {
107
94
  const toolCall = result.tool_calls[toolIndex];
@@ -114,106 +101,28 @@ const addPromptNode = async ({ graph, node, llm, tools, emit, agent }) => {
114
101
  node: node.displayName,
115
102
  });
116
103
  if (matchedTool) {
117
- try {
118
- // Invoke the LangChain tool directly
119
- const toolStartTime = Date.now();
120
- const toolResult = await matchedTool.invoke(toolCall);
121
- const toolEndTime = Date.now();
122
- logger_1.logger.debug({
123
- msg: `[Tool] Tool result inside prompt node`,
124
- tool: matchedTool === null || matchedTool === void 0 ? void 0 : matchedTool.name,
125
- result: toolResult,
126
- executionTimeMs: toolEndTime - toolStartTime,
127
- sessionId: state.sessionId,
128
- node: node.displayName,
129
- });
130
- // Add the tool result directly to allMessages
131
- newMessages.push(toolResult);
132
- // Check for queue after tool call
133
- const systemMessageId = (0, uuid_1.v4)();
134
- const skippedToolMessages = generateSkippedToolMessages(result.tool_calls, toolIndex + 1);
135
- await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId, {
136
- ...state,
137
- messages: [
138
- ...state.messages,
139
- ...newMessages,
140
- ...skippedToolMessages,
141
- new messages_1.SystemMessage({
142
- id: systemMessageId,
143
- content: 'you called tools when the user send a new message, Consider calling the tools again after user message is processed',
144
- }),
145
- ],
146
- history: [
147
- ...state.history,
148
- ...newHistory,
149
- (0, history_1.createHistoryStep)(state.history, {
150
- type: Flows_types_1.NodeType.TOOL,
151
- nodeId: node.name,
152
- nodeDisplayName: node.displayName,
153
- raw: toolResult,
154
- messageIds: [toolResult.id, systemMessageId],
155
- }),
156
- ],
157
- });
158
- // In v2.0, tools update state by reference, no need to extract state updates
159
- newHistory.push((0, history_1.createHistoryStep)(state.history, {
160
- type: Flows_types_1.NodeType.TOOL,
161
- nodeId: node.name,
162
- nodeDisplayName: node.displayName,
163
- raw: toolResult,
164
- messageIds: [toolResult.id],
165
- }));
166
- }
167
- catch (err) {
168
- if ((err === null || err === void 0 ? void 0 : err.name) === 'GraphInterrupt')
169
- throw err;
170
- logger_1.logger.error({
171
- msg: `[Tool] Error executing tool inside prompt node`,
172
- tool: toolCall.name,
173
- err,
174
- sessionId: state.sessionId,
175
- node: node.displayName,
176
- });
177
- const errorMessage = new messages_1.ToolMessage({
178
- content: JSON.stringify({ error: err instanceof Error ? err.message : String(err) }),
179
- tool_call_id: toolCall.id,
180
- });
181
- // Add the error message directly to allMessages
182
- newMessages.push(errorMessage);
183
- // Check for queue after tool error
184
- const errorSystemMessageId = (0, uuid_1.v4)();
185
- const skippedToolMessages = generateSkippedToolMessages(result.tool_calls, toolIndex + 1);
186
- await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId, {
187
- ...state,
188
- messages: [
189
- ...state.messages,
190
- ...newMessages,
191
- ...skippedToolMessages,
192
- new messages_1.SystemMessage({
193
- id: errorSystemMessageId,
194
- content: 'Tool execution failed. Consider handling the error or calling another tool if needed.',
195
- }),
196
- ],
197
- history: [
198
- ...state.history,
199
- ...newHistory,
200
- (0, history_1.createHistoryStep)(state.history, {
201
- type: Flows_types_1.NodeType.TOOL,
202
- nodeId: node.name,
203
- nodeDisplayName: node.displayName,
204
- raw: errorMessage,
205
- messageIds: [errorMessage.id, errorSystemMessageId],
206
- }),
207
- ],
208
- });
209
- newHistory.push((0, history_1.createHistoryStep)(state.history, {
210
- type: Flows_types_1.NodeType.TOOL,
211
- nodeId: node.name,
212
- nodeDisplayName: node.displayName,
213
- raw: errorMessage,
214
- messageIds: [errorMessage.id],
215
- }));
216
- }
104
+ // Invoke the LangChain tool directly
105
+ const toolStartTime = Date.now();
106
+ const toolResult = await matchedTool.invoke(toolCall);
107
+ const toolEndTime = Date.now();
108
+ logger_1.logger.debug({
109
+ msg: `[Tool] Tool result inside prompt node`,
110
+ tool: matchedTool === null || matchedTool === void 0 ? void 0 : matchedTool.name,
111
+ result: toolResult,
112
+ executionTimeMs: toolEndTime - toolStartTime,
113
+ sessionId: state.sessionId,
114
+ node: node.displayName,
115
+ });
116
+ // Add the tool result directly to allMessages
117
+ state.messages.push(toolResult);
118
+ // In v2.0, tools update state by reference, no need to extract state updates
119
+ state.history.push((0, history_1.createHistoryStep)(state.history, {
120
+ type: Flows_types_1.NodeType.TOOL,
121
+ nodeId: node.name,
122
+ nodeDisplayName: node.displayName,
123
+ raw: toolResult,
124
+ messageIds: [toolResult.id],
125
+ }));
217
126
  }
218
127
  else {
219
128
  logger_1.logger.error({
@@ -229,8 +138,8 @@ const addPromptNode = async ({ graph, node, llm, tools, emit, agent }) => {
229
138
  tool_call_id: toolCall.id, // This MUST match the tool_call_id from the AI message
230
139
  name: toolCall.name,
231
140
  });
232
- newMessages.push(missingToolMessage);
233
- newHistory.push((0, history_1.createHistoryStep)(state.history, {
141
+ state.messages.push(missingToolMessage);
142
+ state.history.push((0, history_1.createHistoryStep)(state.history, {
234
143
  type: Flows_types_1.NodeType.TOOL,
235
144
  nodeId: node.name,
236
145
  nodeDisplayName: node.displayName,
@@ -239,28 +148,22 @@ const addPromptNode = async ({ graph, node, llm, tools, emit, agent }) => {
239
148
  }));
240
149
  }
241
150
  }
242
- // Validate that we have responses for ALL tool calls
243
- const toolResponseCount = newMessages.length - toolResponseStartIndex;
244
- if (toolResponseCount !== result.tool_calls.length) {
245
- logger_1.logger.error({
246
- msg: '[Model] Tool response count mismatch',
247
- expectedCount: result.tool_calls.length,
248
- actualCount: toolResponseCount,
249
- toolCallIds: result.tool_calls.map((tc) => tc.id),
250
- sessionId: state.sessionId,
251
- node: node.displayName,
252
- });
253
- }
151
+ // Check for queue after tool call
152
+ const systemMessageId = (0, uuid_1.v4)();
153
+ await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId, {
154
+ ...state,
155
+ messages: [
156
+ ...state.messages,
157
+ new messages_1.SystemMessage({
158
+ id: systemMessageId,
159
+ content: 'you called tools when the user send a new message, Consider calling the tools again after user message is processed',
160
+ }),
161
+ ],
162
+ });
254
163
  // If humanInTheLoop is false, return immediately after tool execution
255
164
  if (!useAgenticLoop) {
256
- // In v2.0, modify state directly
257
- state.messages.push(...newMessages);
258
- state.history.push(...newHistory);
259
165
  return state;
260
166
  }
261
- // Otherwise, prepare for next iteration
262
- // allMessages now contains all the new messages from this iteration
263
- currentMessages = [...state.messages, ...newMessages];
264
167
  // Continue the loop to see what the model wants to do next
265
168
  continue;
266
169
  }
@@ -273,7 +176,7 @@ const addPromptNode = async ({ graph, node, llm, tools, emit, agent }) => {
273
176
  // Process the final AI message if we have one
274
177
  if (finalAIMessage) {
275
178
  // Add the final AI message to our messages first
276
- newMessages.push(finalAIMessage);
179
+ state.messages.push(finalAIMessage);
277
180
  if (finalAIMessage.getType() === 'ai') {
278
181
  logger_1.logger.info({
279
182
  msg: `[Model] Response`,
@@ -281,8 +184,6 @@ const addPromptNode = async ({ graph, node, llm, tools, emit, agent }) => {
281
184
  sessionId: state.sessionId,
282
185
  node: node.displayName,
283
186
  });
284
- // First add all messages to state
285
- state.messages.push(...newMessages);
286
187
  // In v2.0, emit AI_MESSAGE for handlers to process
287
188
  // Handlers will modify state directly by reference
288
189
  await emit(AgentEvents_1.AgentEvents.AI_MESSAGE, {
@@ -292,29 +193,23 @@ const addPromptNode = async ({ graph, node, llm, tools, emit, agent }) => {
292
193
  }
293
194
  // Set goto to null
294
195
  state.goto = null;
295
- newHistory.push((0, history_1.createHistoryStep)(state.history, {
196
+ state.history.push((0, history_1.createHistoryStep)(state.history, {
296
197
  type: Flows_types_1.NodeType.PROMPT_NODE,
297
198
  nodeId: node.name,
298
199
  nodeDisplayName: node.displayName,
299
200
  raw: finalAIMessage.content,
300
201
  messageIds: [finalAIMessage.id],
301
202
  }));
302
- // History is added to state
303
- state.history.push(...newHistory);
304
203
  return state;
305
204
  }
306
205
  // If we hit the loop limit without a final AI message, return what we have
307
- if (loopCount > MAX_LOOP_ITERATIONS && newMessages.length > 0) {
206
+ if (loopCount > MAX_LOOP_ITERATIONS) {
308
207
  logger_1.logger.warn({
309
208
  msg: '[Model] Returning accumulated messages after hitting loop limit',
310
- messageCount: newMessages.length,
311
209
  sessionId: state.sessionId,
312
210
  node: node.displayName,
313
211
  });
314
212
  state.goto = null;
315
- // In v2.0, modify state directly
316
- state.messages.push(...newMessages);
317
- state.history.push(...newHistory);
318
213
  return state;
319
214
  }
320
215
  // This should only be reached in unexpected cases
@@ -360,16 +255,4 @@ Here are possible next nodes and their conditions, never share this
360
255
  information with the user:
361
256
  ${nextEdges}`;
362
257
  }
363
- // Helper function to generate skipped tool messages for remaining tool calls
364
- const generateSkippedToolMessages = (toolCalls, startIndex) => {
365
- const skippedMessages = [];
366
- for (let i = startIndex; i < toolCalls.length; i++) {
367
- const toolCall = toolCalls[i];
368
- skippedMessages.push(new messages_1.ToolMessage({
369
- content: JSON.stringify({ result: 'skipped due to user interruption' }),
370
- tool_call_id: toolCall.id,
371
- }));
372
- }
373
- return skippedMessages;
374
- };
375
258
  //# sourceMappingURL=addPromptNode.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"addPromptNode.js","sourceRoot":"","sources":["../../src/nodes/addPromptNode.ts"],"names":[],"mappings":";;;AACA,sDAA4D;AAI5D,uDAAiF;AAEjF,iDAA8D;AAC9D,uDAA+E;AAE/E,gEAA6D;AAE7D,4CAAyC;AACzC,sDAA0D;AAC1D,8CAAqD;AACrD,mDAAgD;AAChD,+BAAoC;AAY7B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C,IAAS,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,kBAAkB,CAAC,CAAC;IAC/F,oBAAoB,CAAC,OAAO,CAAC,CAAC,IAAS,EAAE,EAAE;QACzC,OAAO,EAAE,CAAC;QACV,SAAS,IAAI,GAAG,OAAO,KAAK,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,SAAS,IAAI,SAAS,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC;IAC1F,CAAC,CAAC,CAAC;IAEH,OAAO;;;;;;;;sBAQa,IAAI,CAAC,WAAW;;;EAGpC,IAAI,CAAC,MAAM;;;;;;;;;;;;EAYX,SAAS,EAAE,CAAC;AACd,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minded-ai/mindedjs",
3
- "version": "2.0.1-beta-5",
3
+ "version": "2.0.1-beta-6",
4
4
  "description": "MindedJS is a TypeScript library for building agents.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -4,6 +4,7 @@ import { BaseLanguageModel } from '@langchain/core/language_models/base';
4
4
  import { SystemMessage } from '@langchain/core/messages';
5
5
  import { stateAnnotation } from '../types/LangGraph.types';
6
6
  import { logger } from '../utils/logger';
7
+ import { compilePrompt } from '../nodes/compilePrompt';
7
8
 
8
9
  const ROUTER_PROMPT = `
9
10
  You are a routing agent that decides which node to take in a flow based on the current state.
@@ -11,10 +12,10 @@ Based on the conversation history and memory state, you should classify the next
11
12
  Each step has a nodeId and a condition. You should decide to move to the right step based on the condition.
12
13
 
13
14
  Here are the available options and their conditions:
14
- {steps}
15
+ <%= steps %>
15
16
 
16
17
  Recent messages:
17
- {messages}
18
+ <%= messages %>
18
19
 
19
20
  You MUST respond with the exact nodeId from the options above. Do not use step numbers or any other identifiers.
20
21
 
@@ -33,10 +34,10 @@ Based on the conversation history and memory state, you should classify the next
33
34
  Each step has a nodeId and a condition. You should decide to move to the right step based on the condition.
34
35
 
35
36
  Here are the available options and their conditions:
36
- {steps}
37
+ <%= steps %>
37
38
 
38
39
  Recent messages:
39
- {messages}
40
+ <%= messages %>
40
41
 
41
42
  You MUST respond with the exact nodeId from the options above. Do not use step numbers or any other identifiers.
42
43
 
@@ -90,7 +91,13 @@ export const createPromptRouter = ({
90
91
  }
91
92
 
92
93
  // Add the edge options
93
- stepsStr += edges.map((edge) => `- Node: "${edge.target}" - Condition: "${edge.prompt}"`).join('\n');
94
+ stepsStr += edges
95
+ .map((edge) => {
96
+ // Compile edge prompts with EJS to support templates in conditions
97
+ const compiledPrompt = compilePrompt(edge.prompt || '', { memory: state.memory });
98
+ return `- Node: "${edge.target}" - Condition: "${compiledPrompt}"`;
99
+ })
100
+ .join('\n');
94
101
 
95
102
  // Prepare recent messages (last 10 messages for context)
96
103
  const recentMessages = state.messages.slice(-10);
@@ -103,10 +110,14 @@ export const createPromptRouter = ({
103
110
  .join('\n');
104
111
 
105
112
  // Select prompt based on reasoning preference
106
- let routerPrompt = includeReasoning ? ROUTER_PROMPT : ROUTER_PROMPT_WITHOUT_REASONING;
107
-
108
- // Replace placeholders in prompt
109
- routerPrompt = routerPrompt.replace('{steps}', stepsStr).replace('{messages}', messagesStr);
113
+ const promptTemplate = includeReasoning ? ROUTER_PROMPT : ROUTER_PROMPT_WITHOUT_REASONING;
114
+
115
+ // Compile prompt with EJS and parameters
116
+ const routerPrompt = compilePrompt(promptTemplate, {
117
+ steps: stepsStr,
118
+ messages: messagesStr,
119
+ memory: state.memory,
120
+ });
110
121
 
111
122
  // Define response schema
112
123
  const responseSchema = includeReasoning
@@ -15,7 +15,6 @@ import { combinePlaybooks } from '../playbooks/playbooks';
15
15
  import { createHistoryStep } from '../utils/history';
16
16
  import { compilePrompt } from './compilePrompt';
17
17
  import { v4 as uuidv4 } from 'uuid';
18
- import { ToolCall } from '@langchain/core/dist/messages/tool';
19
18
 
20
19
  type AddPromptNodeParams = {
21
20
  graph: PreCompiledGraph;
@@ -70,9 +69,6 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
70
69
  * When humanInTheLoop is false: Return immediately after tool execution without
71
70
  * additional LLM invocations.
72
71
  */
73
- const newMessages: any[] = [];
74
- const newHistory: any[] = [];
75
- let currentMessages = [...state.messages];
76
72
  let finalAIMessage: AIMessage | null = null;
77
73
  let loopCount = 0;
78
74
  const MAX_LOOP_ITERATIONS = 10;
@@ -92,19 +88,12 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
92
88
  }
93
89
  const startTime = Date.now();
94
90
 
95
- const result: AIMessage = await llmToUse.bindTools(scopedTools).invoke([new SystemMessage(compiledPrompt), ...currentMessages]);
91
+ const result: AIMessage = await llmToUse.bindTools(scopedTools).invoke(state.messages);
96
92
  // Always pass accumulated state to interrupt manager
97
93
  // Pass the accumulated messages from this prompt node execution
98
94
  // If empty, pass undefined to avoid empty state updates
99
- const interruptState =
100
- newMessages.length > 0 || newHistory.length > 0
101
- ? {
102
- ...state,
103
- messages: [...state.messages, ...newMessages],
104
- history: [...state.history, ...newHistory],
105
- }
106
- : undefined;
107
- await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId, interruptState);
95
+
96
+ await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId, state);
108
97
 
109
98
  const endTime = Date.now();
110
99
 
@@ -117,9 +106,8 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
117
106
 
118
107
  // Check if the result contains tool calls
119
108
  if (result.tool_calls && result.tool_calls.length > 0) {
120
- // Add the tool call message
121
- newMessages.push(result);
122
- newHistory.push(
109
+ state.messages.push(result);
110
+ state.history.push(
123
111
  createHistoryStep<HistoryStep>(state.history, {
124
112
  type: NodeType.TOOL,
125
113
  nodeId: node.name,
@@ -130,9 +118,6 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
130
118
  );
131
119
 
132
120
  // Execute the tools
133
- // Track how many tool responses we've added for validation
134
- const toolResponseStartIndex = newMessages.length;
135
-
136
121
  // Ensure we process ALL tool calls, even if some fail
137
122
  for (let toolIndex = 0; toolIndex < result.tool_calls.length; toolIndex++) {
138
123
  const toolCall = result.tool_calls[toolIndex];
@@ -146,116 +131,34 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
146
131
  });
147
132
 
148
133
  if (matchedTool) {
149
- try {
150
- // Invoke the LangChain tool directly
151
- const toolStartTime = Date.now();
152
- const toolResult = await matchedTool.invoke(toolCall);
153
- const toolEndTime = Date.now();
154
-
155
- logger.debug({
156
- msg: `[Tool] Tool result inside prompt node`,
157
- tool: matchedTool?.name,
158
- result: toolResult,
159
- executionTimeMs: toolEndTime - toolStartTime,
160
- sessionId: state.sessionId,
161
- node: node.displayName,
162
- });
163
-
164
- // Add the tool result directly to allMessages
165
- newMessages.push(toolResult);
166
-
167
- // Check for queue after tool call
168
- const systemMessageId = uuidv4();
169
- const skippedToolMessages = generateSkippedToolMessages(result.tool_calls, toolIndex + 1);
170
- await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId, {
171
- ...state,
172
- messages: [
173
- ...state.messages,
174
- ...newMessages,
175
- ...skippedToolMessages,
176
- new SystemMessage({
177
- id: systemMessageId,
178
- content:
179
- 'you called tools when the user send a new message, Consider calling the tools again after user message is processed',
180
- }),
181
- ],
182
- history: [
183
- ...state.history,
184
- ...newHistory,
185
- createHistoryStep<HistoryStep>(state.history, {
186
- type: NodeType.TOOL,
187
- nodeId: node.name,
188
- nodeDisplayName: node.displayName,
189
- raw: toolResult,
190
- messageIds: [toolResult.id!, systemMessageId],
191
- }),
192
- ],
193
- });
194
-
195
- // In v2.0, tools update state by reference, no need to extract state updates
196
-
197
- newHistory.push(
198
- createHistoryStep<HistoryStep>(state.history, {
199
- type: NodeType.TOOL,
200
- nodeId: node.name,
201
- nodeDisplayName: node.displayName,
202
- raw: toolResult,
203
- messageIds: [toolResult.id!],
204
- }),
205
- );
206
- } catch (err: any) {
207
- if (err?.name === 'GraphInterrupt') throw err;
208
- logger.error({
209
- msg: `[Tool] Error executing tool inside prompt node`,
210
- tool: toolCall.name,
211
- err,
212
- sessionId: state.sessionId,
213
- node: node.displayName,
214
- });
215
- const errorMessage = new ToolMessage({
216
- content: JSON.stringify({ error: err instanceof Error ? err.message : String(err) }),
217
- tool_call_id: toolCall.id!,
218
- });
219
-
220
- // Add the error message directly to allMessages
221
- newMessages.push(errorMessage);
222
-
223
- // Check for queue after tool error
224
- const errorSystemMessageId = uuidv4();
225
- const skippedToolMessages = generateSkippedToolMessages(result.tool_calls, toolIndex + 1);
226
- await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId, {
227
- ...state,
228
- messages: [
229
- ...state.messages,
230
- ...newMessages,
231
- ...skippedToolMessages,
232
- new SystemMessage({
233
- id: errorSystemMessageId,
234
- content: 'Tool execution failed. Consider handling the error or calling another tool if needed.',
235
- }),
236
- ],
237
- history: [
238
- ...state.history,
239
- ...newHistory,
240
- createHistoryStep<HistoryStep>(state.history, {
241
- type: NodeType.TOOL,
242
- nodeId: node.name,
243
- nodeDisplayName: node.displayName,
244
- raw: errorMessage,
245
- messageIds: [errorMessage.id!, errorSystemMessageId],
246
- }),
247
- ],
248
- });
249
- newHistory.push(
250
- createHistoryStep<HistoryStep>(state.history, {
251
- type: NodeType.TOOL,
252
- nodeId: node.name,
253
- nodeDisplayName: node.displayName,
254
- raw: errorMessage,
255
- messageIds: [errorMessage.id!],
256
- }),
257
- );
258
- }
134
+ // Invoke the LangChain tool directly
135
+ const toolStartTime = Date.now();
136
+ const toolResult = await matchedTool.invoke(toolCall);
137
+ const toolEndTime = Date.now();
138
+
139
+ logger.debug({
140
+ msg: `[Tool] Tool result inside prompt node`,
141
+ tool: matchedTool?.name,
142
+ result: toolResult,
143
+ executionTimeMs: toolEndTime - toolStartTime,
144
+ sessionId: state.sessionId,
145
+ node: node.displayName,
146
+ });
147
+
148
+ // Add the tool result directly to allMessages
149
+ state.messages.push(toolResult);
150
+
151
+ // In v2.0, tools update state by reference, no need to extract state updates
152
+
153
+ state.history.push(
154
+ createHistoryStep<HistoryStep>(state.history, {
155
+ type: NodeType.TOOL,
156
+ nodeId: node.name,
157
+ nodeDisplayName: node.displayName,
158
+ raw: toolResult,
159
+ messageIds: [toolResult.id!],
160
+ }),
161
+ );
259
162
  } else {
260
163
  logger.error({
261
164
  msg: `[Tool] Model called tool but it was not found inside prompt node`,
@@ -272,8 +175,8 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
272
175
  name: toolCall.name,
273
176
  });
274
177
 
275
- newMessages.push(missingToolMessage);
276
- newHistory.push(
178
+ state.messages.push(missingToolMessage);
179
+ state.history.push(
277
180
  createHistoryStep<HistoryStep>(state.history, {
278
181
  type: NodeType.TOOL,
279
182
  nodeId: node.name,
@@ -284,32 +187,25 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
284
187
  );
285
188
  }
286
189
  }
287
-
288
- // Validate that we have responses for ALL tool calls
289
- const toolResponseCount = newMessages.length - toolResponseStartIndex;
290
- if (toolResponseCount !== result.tool_calls.length) {
291
- logger.error({
292
- msg: '[Model] Tool response count mismatch',
293
- expectedCount: result.tool_calls.length,
294
- actualCount: toolResponseCount,
295
- toolCallIds: result.tool_calls.map((tc) => tc.id),
296
- sessionId: state.sessionId,
297
- node: node.displayName,
298
- });
299
- }
190
+ // Check for queue after tool call
191
+ const systemMessageId = uuidv4();
192
+ await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId, {
193
+ ...state,
194
+ messages: [
195
+ ...state.messages,
196
+ new SystemMessage({
197
+ id: systemMessageId,
198
+ content:
199
+ 'you called tools when the user send a new message, Consider calling the tools again after user message is processed',
200
+ }),
201
+ ],
202
+ });
300
203
 
301
204
  // If humanInTheLoop is false, return immediately after tool execution
302
205
  if (!useAgenticLoop) {
303
- // In v2.0, modify state directly
304
- state.messages.push(...newMessages);
305
- state.history.push(...newHistory);
306
206
  return state;
307
207
  }
308
208
 
309
- // Otherwise, prepare for next iteration
310
- // allMessages now contains all the new messages from this iteration
311
- currentMessages = [...state.messages, ...newMessages];
312
-
313
209
  // Continue the loop to see what the model wants to do next
314
210
  continue;
315
211
  } else {
@@ -322,7 +218,7 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
322
218
  // Process the final AI message if we have one
323
219
  if (finalAIMessage) {
324
220
  // Add the final AI message to our messages first
325
- newMessages.push(finalAIMessage);
221
+ state.messages.push(finalAIMessage);
326
222
 
327
223
  if (finalAIMessage.getType() === 'ai') {
328
224
  logger.info({
@@ -332,9 +228,6 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
332
228
  node: node.displayName,
333
229
  });
334
230
 
335
- // First add all messages to state
336
- state.messages.push(...newMessages);
337
-
338
231
  // In v2.0, emit AI_MESSAGE for handlers to process
339
232
  // Handlers will modify state directly by reference
340
233
  await emit(AgentEvents.AI_MESSAGE, {
@@ -346,7 +239,7 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
346
239
  // Set goto to null
347
240
  state.goto = null;
348
241
 
349
- newHistory.push(
242
+ state.history.push(
350
243
  createHistoryStep<HistoryStep>(state.history, {
351
244
  type: NodeType.PROMPT_NODE,
352
245
  nodeId: node.name,
@@ -356,26 +249,18 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
356
249
  }),
357
250
  );
358
251
 
359
- // History is added to state
360
- state.history.push(...newHistory);
361
-
362
252
  return state;
363
253
  }
364
254
 
365
255
  // If we hit the loop limit without a final AI message, return what we have
366
- if (loopCount > MAX_LOOP_ITERATIONS && newMessages.length > 0) {
256
+ if (loopCount > MAX_LOOP_ITERATIONS) {
367
257
  logger.warn({
368
258
  msg: '[Model] Returning accumulated messages after hitting loop limit',
369
- messageCount: newMessages.length,
370
259
  sessionId: state.sessionId,
371
260
  node: node.displayName,
372
261
  });
373
262
 
374
263
  state.goto = null;
375
- // In v2.0, modify state directly
376
- state.messages.push(...newMessages);
377
- state.history.push(...newHistory);
378
-
379
264
  return state;
380
265
  }
381
266
 
@@ -424,18 +309,3 @@ Here are possible next nodes and their conditions, never share this
424
309
  information with the user:
425
310
  ${nextEdges}`;
426
311
  }
427
-
428
- // Helper function to generate skipped tool messages for remaining tool calls
429
- const generateSkippedToolMessages = (toolCalls: ToolCall[], startIndex: number): ToolMessage[] => {
430
- const skippedMessages: ToolMessage[] = [];
431
- for (let i = startIndex; i < toolCalls.length; i++) {
432
- const toolCall = toolCalls[i];
433
- skippedMessages.push(
434
- new ToolMessage({
435
- content: JSON.stringify({ result: 'skipped due to user interruption' }),
436
- tool_call_id: toolCall.id!,
437
- }),
438
- );
439
- }
440
- return skippedMessages;
441
- };