@minded-ai/mindedjs 2.0.1-beta-4 → 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,10 +89,9 @@ 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
- for (const toolCall of result.tool_calls) {
93
+ for (let toolIndex = 0; toolIndex < result.tool_calls.length; toolIndex++) {
94
+ const toolCall = result.tool_calls[toolIndex];
107
95
  const matchedTool = scopedTools.find((t) => t.name === toolCall.name);
108
96
  logger_1.logger.info({
109
97
  msg: `[Model] Calling tool inside prompt node`,
@@ -113,102 +101,28 @@ const addPromptNode = async ({ graph, node, llm, tools, emit, agent }) => {
113
101
  node: node.displayName,
114
102
  });
115
103
  if (matchedTool) {
116
- try {
117
- // Invoke the LangChain tool directly
118
- const toolStartTime = Date.now();
119
- const toolResult = await matchedTool.invoke(toolCall);
120
- const toolEndTime = Date.now();
121
- logger_1.logger.debug({
122
- msg: `[Tool] Tool result inside prompt node`,
123
- tool: matchedTool === null || matchedTool === void 0 ? void 0 : matchedTool.name,
124
- result: toolResult,
125
- executionTimeMs: toolEndTime - toolStartTime,
126
- sessionId: state.sessionId,
127
- node: node.displayName,
128
- });
129
- // Add the tool result directly to allMessages
130
- newMessages.push(toolResult);
131
- // Check for queue after tool call
132
- const systemMessageId = (0, uuid_1.v4)();
133
- await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId, {
134
- ...state,
135
- messages: [
136
- ...state.messages,
137
- ...newMessages,
138
- new messages_1.SystemMessage({
139
- id: systemMessageId,
140
- content: 'you called tool when the user send a new message, Consider calling the function again after user message is processed',
141
- }),
142
- ],
143
- history: [
144
- ...state.history,
145
- ...newHistory,
146
- (0, history_1.createHistoryStep)(state.history, {
147
- type: Flows_types_1.NodeType.TOOL,
148
- nodeId: node.name,
149
- nodeDisplayName: node.displayName,
150
- raw: toolResult,
151
- messageIds: [toolResult.id, systemMessageId],
152
- }),
153
- ],
154
- });
155
- // In v2.0, tools update state by reference, no need to extract state updates
156
- newHistory.push((0, history_1.createHistoryStep)(state.history, {
157
- type: Flows_types_1.NodeType.TOOL,
158
- nodeId: node.name,
159
- nodeDisplayName: node.displayName,
160
- raw: toolResult,
161
- messageIds: [toolResult.id],
162
- }));
163
- }
164
- catch (err) {
165
- if ((err === null || err === void 0 ? void 0 : err.name) === 'GraphInterrupt')
166
- throw err;
167
- logger_1.logger.error({
168
- msg: `[Tool] Error executing tool inside prompt node`,
169
- tool: toolCall.name,
170
- err,
171
- sessionId: state.sessionId,
172
- node: node.displayName,
173
- });
174
- const errorMessage = new messages_1.ToolMessage({
175
- content: JSON.stringify({ error: err instanceof Error ? err.message : String(err) }),
176
- tool_call_id: toolCall.id,
177
- });
178
- // Add the error message directly to allMessages
179
- newMessages.push(errorMessage);
180
- // Check for queue after tool error
181
- const errorSystemMessageId = (0, uuid_1.v4)();
182
- await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId, {
183
- ...state,
184
- messages: [
185
- ...state.messages,
186
- ...newMessages,
187
- new messages_1.SystemMessage({
188
- id: errorSystemMessageId,
189
- content: 'Tool execution failed. Consider handling the error or calling another function if needed.',
190
- }),
191
- ],
192
- history: [
193
- ...state.history,
194
- ...newHistory,
195
- (0, history_1.createHistoryStep)(state.history, {
196
- type: Flows_types_1.NodeType.TOOL,
197
- nodeId: node.name,
198
- nodeDisplayName: node.displayName,
199
- raw: errorMessage,
200
- messageIds: [errorMessage.id, errorSystemMessageId],
201
- }),
202
- ],
203
- });
204
- newHistory.push((0, history_1.createHistoryStep)(state.history, {
205
- type: Flows_types_1.NodeType.TOOL,
206
- nodeId: node.name,
207
- nodeDisplayName: node.displayName,
208
- raw: errorMessage,
209
- messageIds: [errorMessage.id],
210
- }));
211
- }
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
+ }));
212
126
  }
213
127
  else {
214
128
  logger_1.logger.error({
@@ -224,8 +138,8 @@ const addPromptNode = async ({ graph, node, llm, tools, emit, agent }) => {
224
138
  tool_call_id: toolCall.id, // This MUST match the tool_call_id from the AI message
225
139
  name: toolCall.name,
226
140
  });
227
- newMessages.push(missingToolMessage);
228
- newHistory.push((0, history_1.createHistoryStep)(state.history, {
141
+ state.messages.push(missingToolMessage);
142
+ state.history.push((0, history_1.createHistoryStep)(state.history, {
229
143
  type: Flows_types_1.NodeType.TOOL,
230
144
  nodeId: node.name,
231
145
  nodeDisplayName: node.displayName,
@@ -234,28 +148,22 @@ const addPromptNode = async ({ graph, node, llm, tools, emit, agent }) => {
234
148
  }));
235
149
  }
236
150
  }
237
- // Validate that we have responses for ALL tool calls
238
- const toolResponseCount = newMessages.length - toolResponseStartIndex;
239
- if (toolResponseCount !== result.tool_calls.length) {
240
- logger_1.logger.error({
241
- msg: '[Model] Tool response count mismatch',
242
- expectedCount: result.tool_calls.length,
243
- actualCount: toolResponseCount,
244
- toolCallIds: result.tool_calls.map((tc) => tc.id),
245
- sessionId: state.sessionId,
246
- node: node.displayName,
247
- });
248
- }
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
+ });
249
163
  // If humanInTheLoop is false, return immediately after tool execution
250
164
  if (!useAgenticLoop) {
251
- // In v2.0, modify state directly
252
- state.messages.push(...newMessages);
253
- state.history.push(...newHistory);
254
165
  return state;
255
166
  }
256
- // Otherwise, prepare for next iteration
257
- // allMessages now contains all the new messages from this iteration
258
- currentMessages = [...state.messages, ...newMessages];
259
167
  // Continue the loop to see what the model wants to do next
260
168
  continue;
261
169
  }
@@ -268,7 +176,7 @@ const addPromptNode = async ({ graph, node, llm, tools, emit, agent }) => {
268
176
  // Process the final AI message if we have one
269
177
  if (finalAIMessage) {
270
178
  // Add the final AI message to our messages first
271
- newMessages.push(finalAIMessage);
179
+ state.messages.push(finalAIMessage);
272
180
  if (finalAIMessage.getType() === 'ai') {
273
181
  logger_1.logger.info({
274
182
  msg: `[Model] Response`,
@@ -276,8 +184,6 @@ const addPromptNode = async ({ graph, node, llm, tools, emit, agent }) => {
276
184
  sessionId: state.sessionId,
277
185
  node: node.displayName,
278
186
  });
279
- // First add all messages to state
280
- state.messages.push(...newMessages);
281
187
  // In v2.0, emit AI_MESSAGE for handlers to process
282
188
  // Handlers will modify state directly by reference
283
189
  await emit(AgentEvents_1.AgentEvents.AI_MESSAGE, {
@@ -287,29 +193,23 @@ const addPromptNode = async ({ graph, node, llm, tools, emit, agent }) => {
287
193
  }
288
194
  // Set goto to null
289
195
  state.goto = null;
290
- newHistory.push((0, history_1.createHistoryStep)(state.history, {
196
+ state.history.push((0, history_1.createHistoryStep)(state.history, {
291
197
  type: Flows_types_1.NodeType.PROMPT_NODE,
292
198
  nodeId: node.name,
293
199
  nodeDisplayName: node.displayName,
294
200
  raw: finalAIMessage.content,
295
201
  messageIds: [finalAIMessage.id],
296
202
  }));
297
- // History is added to state
298
- state.history.push(...newHistory);
299
203
  return state;
300
204
  }
301
205
  // If we hit the loop limit without a final AI message, return what we have
302
- if (loopCount > MAX_LOOP_ITERATIONS && newMessages.length > 0) {
206
+ if (loopCount > MAX_LOOP_ITERATIONS) {
303
207
  logger_1.logger.warn({
304
208
  msg: '[Model] Returning accumulated messages after hitting loop limit',
305
- messageCount: newMessages.length,
306
209
  sessionId: state.sessionId,
307
210
  node: node.displayName,
308
211
  });
309
212
  state.goto = null;
310
- // In v2.0, modify state directly
311
- state.messages.push(...newMessages);
312
- state.history.push(...newHistory);
313
213
  return state;
314
214
  }
315
215
  // This should only be reached in unexpected cases
@@ -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;AAU7B,MAAM,aAAa,GAAG,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAuB,EAAE,EAAE;IACnG,MAAM,QAAQ,GAAiB,KAAK,EAAE,KAAmC,EAAE,EAAE;;QAC3E,MAAM,KAAK,CAAC,uBAAuB,CAAC,sBAAsB,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAC5E,eAAM,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,8BAA8B,EAAE,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC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kB,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-4",
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,6 +15,7 @@ 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
+
18
19
  type AddPromptNodeParams = {
19
20
  graph: PreCompiledGraph;
20
21
  node: PromptNode;
@@ -68,9 +69,6 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
68
69
  * When humanInTheLoop is false: Return immediately after tool execution without
69
70
  * additional LLM invocations.
70
71
  */
71
- const newMessages: any[] = [];
72
- const newHistory: any[] = [];
73
- let currentMessages = [...state.messages];
74
72
  let finalAIMessage: AIMessage | null = null;
75
73
  let loopCount = 0;
76
74
  const MAX_LOOP_ITERATIONS = 10;
@@ -90,20 +88,12 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
90
88
  }
91
89
  const startTime = Date.now();
92
90
 
93
- const result: AIMessage = await llmToUse.bindTools(scopedTools).invoke([new SystemMessage(compiledPrompt), ...currentMessages]);
94
-
91
+ const result: AIMessage = await llmToUse.bindTools(scopedTools).invoke(state.messages);
95
92
  // Always pass accumulated state to interrupt manager
96
93
  // Pass the accumulated messages from this prompt node execution
97
94
  // If empty, pass undefined to avoid empty state updates
98
- const interruptState =
99
- newMessages.length > 0 || newHistory.length > 0
100
- ? {
101
- ...state,
102
- messages: [...state.messages, ...newMessages],
103
- history: [...state.history, ...newHistory],
104
- }
105
- : undefined;
106
- await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId, interruptState);
95
+
96
+ await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId, state);
107
97
 
108
98
  const endTime = Date.now();
109
99
 
@@ -116,9 +106,8 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
116
106
 
117
107
  // Check if the result contains tool calls
118
108
  if (result.tool_calls && result.tool_calls.length > 0) {
119
- // Add the tool call message
120
- newMessages.push(result);
121
- newHistory.push(
109
+ state.messages.push(result);
110
+ state.history.push(
122
111
  createHistoryStep<HistoryStep>(state.history, {
123
112
  type: NodeType.TOOL,
124
113
  nodeId: node.name,
@@ -129,11 +118,9 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
129
118
  );
130
119
 
131
120
  // Execute the tools
132
- // Track how many tool responses we've added for validation
133
- const toolResponseStartIndex = newMessages.length;
134
-
135
121
  // Ensure we process ALL tool calls, even if some fail
136
- for (const toolCall of result.tool_calls) {
122
+ for (let toolIndex = 0; toolIndex < result.tool_calls.length; toolIndex++) {
123
+ const toolCall = result.tool_calls[toolIndex];
137
124
  const matchedTool = scopedTools.find((t) => t.name === toolCall.name);
138
125
  logger.info({
139
126
  msg: `[Model] Calling tool inside prompt node`,
@@ -144,112 +131,34 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
144
131
  });
145
132
 
146
133
  if (matchedTool) {
147
- try {
148
- // Invoke the LangChain tool directly
149
- const toolStartTime = Date.now();
150
- const toolResult = await matchedTool.invoke(toolCall);
151
- const toolEndTime = Date.now();
152
-
153
- logger.debug({
154
- msg: `[Tool] Tool result inside prompt node`,
155
- tool: matchedTool?.name,
156
- result: toolResult,
157
- executionTimeMs: toolEndTime - toolStartTime,
158
- sessionId: state.sessionId,
159
- node: node.displayName,
160
- });
161
-
162
- // Add the tool result directly to allMessages
163
- newMessages.push(toolResult);
164
-
165
- // Check for queue after tool call
166
- const systemMessageId = uuidv4();
167
- await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId, {
168
- ...state,
169
- messages: [
170
- ...state.messages,
171
- ...newMessages,
172
- new SystemMessage({
173
- id: systemMessageId,
174
- content:
175
- 'you called tool when the user send a new message, Consider calling the function again after user message is processed',
176
- }),
177
- ],
178
- history: [
179
- ...state.history,
180
- ...newHistory,
181
- createHistoryStep<HistoryStep>(state.history, {
182
- type: NodeType.TOOL,
183
- nodeId: node.name,
184
- nodeDisplayName: node.displayName,
185
- raw: toolResult,
186
- messageIds: [toolResult.id!, systemMessageId],
187
- }),
188
- ],
189
- });
190
-
191
- // In v2.0, tools update state by reference, no need to extract state updates
192
-
193
- newHistory.push(
194
- createHistoryStep<HistoryStep>(state.history, {
195
- type: NodeType.TOOL,
196
- nodeId: node.name,
197
- nodeDisplayName: node.displayName,
198
- raw: toolResult,
199
- messageIds: [toolResult.id!],
200
- }),
201
- );
202
- } catch (err: any) {
203
- if (err?.name === 'GraphInterrupt') throw err;
204
- logger.error({
205
- msg: `[Tool] Error executing tool inside prompt node`,
206
- tool: toolCall.name,
207
- err,
208
- sessionId: state.sessionId,
209
- node: node.displayName,
210
- });
211
- const errorMessage = new ToolMessage({
212
- content: JSON.stringify({ error: err instanceof Error ? err.message : String(err) }),
213
- tool_call_id: toolCall.id!,
214
- });
215
-
216
- // Add the error message directly to allMessages
217
- newMessages.push(errorMessage);
218
-
219
- // Check for queue after tool error
220
- const errorSystemMessageId = uuidv4();
221
- await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId, {
222
- ...state,
223
- messages: [
224
- ...state.messages,
225
- ...newMessages,
226
- new SystemMessage({
227
- id: errorSystemMessageId,
228
- content: 'Tool execution failed. Consider handling the error or calling another function if needed.',
229
- }),
230
- ],
231
- history: [
232
- ...state.history,
233
- ...newHistory,
234
- createHistoryStep<HistoryStep>(state.history, {
235
- type: NodeType.TOOL,
236
- nodeId: node.name,
237
- nodeDisplayName: node.displayName,
238
- raw: errorMessage,
239
- messageIds: [errorMessage.id!, errorSystemMessageId],
240
- }),
241
- ],
242
- });
243
- newHistory.push(
244
- createHistoryStep<HistoryStep>(state.history, {
245
- type: NodeType.TOOL,
246
- nodeId: node.name,
247
- nodeDisplayName: node.displayName,
248
- raw: errorMessage,
249
- messageIds: [errorMessage.id!],
250
- }),
251
- );
252
- }
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
+ );
253
162
  } else {
254
163
  logger.error({
255
164
  msg: `[Tool] Model called tool but it was not found inside prompt node`,
@@ -266,8 +175,8 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
266
175
  name: toolCall.name,
267
176
  });
268
177
 
269
- newMessages.push(missingToolMessage);
270
- newHistory.push(
178
+ state.messages.push(missingToolMessage);
179
+ state.history.push(
271
180
  createHistoryStep<HistoryStep>(state.history, {
272
181
  type: NodeType.TOOL,
273
182
  nodeId: node.name,
@@ -278,32 +187,25 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
278
187
  );
279
188
  }
280
189
  }
281
-
282
- // Validate that we have responses for ALL tool calls
283
- const toolResponseCount = newMessages.length - toolResponseStartIndex;
284
- if (toolResponseCount !== result.tool_calls.length) {
285
- logger.error({
286
- msg: '[Model] Tool response count mismatch',
287
- expectedCount: result.tool_calls.length,
288
- actualCount: toolResponseCount,
289
- toolCallIds: result.tool_calls.map((tc) => tc.id),
290
- sessionId: state.sessionId,
291
- node: node.displayName,
292
- });
293
- }
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
+ });
294
203
 
295
204
  // If humanInTheLoop is false, return immediately after tool execution
296
205
  if (!useAgenticLoop) {
297
- // In v2.0, modify state directly
298
- state.messages.push(...newMessages);
299
- state.history.push(...newHistory);
300
206
  return state;
301
207
  }
302
208
 
303
- // Otherwise, prepare for next iteration
304
- // allMessages now contains all the new messages from this iteration
305
- currentMessages = [...state.messages, ...newMessages];
306
-
307
209
  // Continue the loop to see what the model wants to do next
308
210
  continue;
309
211
  } else {
@@ -316,7 +218,7 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
316
218
  // Process the final AI message if we have one
317
219
  if (finalAIMessage) {
318
220
  // Add the final AI message to our messages first
319
- newMessages.push(finalAIMessage);
221
+ state.messages.push(finalAIMessage);
320
222
 
321
223
  if (finalAIMessage.getType() === 'ai') {
322
224
  logger.info({
@@ -326,9 +228,6 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
326
228
  node: node.displayName,
327
229
  });
328
230
 
329
- // First add all messages to state
330
- state.messages.push(...newMessages);
331
-
332
231
  // In v2.0, emit AI_MESSAGE for handlers to process
333
232
  // Handlers will modify state directly by reference
334
233
  await emit(AgentEvents.AI_MESSAGE, {
@@ -340,7 +239,7 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
340
239
  // Set goto to null
341
240
  state.goto = null;
342
241
 
343
- newHistory.push(
242
+ state.history.push(
344
243
  createHistoryStep<HistoryStep>(state.history, {
345
244
  type: NodeType.PROMPT_NODE,
346
245
  nodeId: node.name,
@@ -350,26 +249,18 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
350
249
  }),
351
250
  );
352
251
 
353
- // History is added to state
354
- state.history.push(...newHistory);
355
-
356
252
  return state;
357
253
  }
358
254
 
359
255
  // If we hit the loop limit without a final AI message, return what we have
360
- if (loopCount > MAX_LOOP_ITERATIONS && newMessages.length > 0) {
256
+ if (loopCount > MAX_LOOP_ITERATIONS) {
361
257
  logger.warn({
362
258
  msg: '[Model] Returning accumulated messages after hitting loop limit',
363
- messageCount: newMessages.length,
364
259
  sessionId: state.sessionId,
365
260
  node: node.displayName,
366
261
  });
367
262
 
368
263
  state.goto = null;
369
- // In v2.0, modify state directly
370
- state.messages.push(...newMessages);
371
- state.history.push(...newHistory);
372
-
373
264
  return state;
374
265
  }
375
266