@minded-ai/mindedjs 1.0.150 → 2.0.0-beta1
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.
- package/dist/agent.d.ts +2 -2
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +31 -53
- package/dist/agent.js.map +1 -1
- package/dist/cli/index.js +0 -0
- package/dist/edges/createLogicalRouter.d.ts.map +1 -1
- package/dist/edges/createLogicalRouter.js +4 -18
- package/dist/edges/createLogicalRouter.js.map +1 -1
- package/dist/events/AgentEvents.d.ts +5 -14
- package/dist/events/AgentEvents.d.ts.map +1 -1
- package/dist/guidelines/guidelinesManager.d.ts +37 -0
- package/dist/guidelines/guidelinesManager.d.ts.map +1 -0
- package/dist/guidelines/guidelinesManager.js +172 -0
- package/dist/guidelines/guidelinesManager.js.map +1 -0
- package/dist/internalTools/documentExtraction.d.ts +69 -0
- package/dist/internalTools/documentExtraction.d.ts.map +1 -0
- package/dist/internalTools/documentExtraction.js +65 -0
- package/dist/internalTools/documentExtraction.js.map +1 -0
- package/dist/internalTools/libraryActionRunnerTool.d.ts.map +1 -1
- package/dist/internalTools/libraryActionRunnerTool.js +0 -1
- package/dist/internalTools/libraryActionRunnerTool.js.map +1 -1
- package/dist/internalTools/managedDocumentParser/managedDocumentParser.d.ts +10 -0
- package/dist/internalTools/managedDocumentParser/managedDocumentParser.d.ts.map +1 -0
- package/dist/internalTools/managedDocumentParser/managedDocumentParser.js +80 -0
- package/dist/internalTools/managedDocumentParser/managedDocumentParser.js.map +1 -0
- package/dist/internalTools/retell.d.ts +12 -0
- package/dist/internalTools/retell.d.ts.map +1 -0
- package/dist/internalTools/retell.js +44 -0
- package/dist/internalTools/retell.js.map +1 -0
- package/dist/internalTools/sendPlaceholderMessage.d.ts +14 -0
- package/dist/internalTools/sendPlaceholderMessage.d.ts.map +1 -0
- package/dist/internalTools/sendPlaceholderMessage.js +51 -0
- package/dist/internalTools/sendPlaceholderMessage.js.map +1 -0
- package/dist/interrupts/BaseInterruptSessionManager.d.ts +2 -2
- package/dist/interrupts/BaseInterruptSessionManager.d.ts.map +1 -1
- package/dist/interrupts/BaseInterruptSessionManager.js +1 -7
- package/dist/interrupts/BaseInterruptSessionManager.js.map +1 -1
- package/dist/nodes/addAppToolNode.d.ts.map +1 -1
- package/dist/nodes/addAppToolNode.js +24 -18
- package/dist/nodes/addAppToolNode.js.map +1 -1
- package/dist/nodes/addBrowserTaskNode.d.ts.map +1 -1
- package/dist/nodes/addBrowserTaskNode.js +30 -27
- package/dist/nodes/addBrowserTaskNode.js.map +1 -1
- package/dist/nodes/addBrowserTaskRunNode.d.ts.map +1 -1
- package/dist/nodes/addBrowserTaskRunNode.js +18 -20
- package/dist/nodes/addBrowserTaskRunNode.js.map +1 -1
- package/dist/nodes/addJumpToNode.d.ts.map +1 -1
- package/dist/nodes/addJumpToNode.js +8 -9
- package/dist/nodes/addJumpToNode.js.map +1 -1
- package/dist/nodes/addJunctionNode.d.ts.map +1 -1
- package/dist/nodes/addJunctionNode.js +8 -9
- package/dist/nodes/addJunctionNode.js.map +1 -1
- package/dist/nodes/addPromptNode.d.ts.map +1 -1
- package/dist/nodes/addPromptNode.js +40 -58
- package/dist/nodes/addPromptNode.js.map +1 -1
- package/dist/nodes/addToolNode.d.ts.map +1 -1
- package/dist/nodes/addToolNode.js +33 -20
- package/dist/nodes/addToolNode.js.map +1 -1
- package/dist/nodes/addToolRunNode.d.ts.map +1 -1
- package/dist/nodes/addToolRunNode.js +15 -21
- package/dist/nodes/addToolRunNode.js.map +1 -1
- package/dist/nodes/addTriggerNode.js +9 -11
- package/dist/nodes/addTriggerNode.js.map +1 -1
- package/dist/nodes/compilePrompt.d.ts.map +1 -1
- package/dist/nodes/compilePrompt.js +2 -0
- package/dist/nodes/compilePrompt.js.map +1 -1
- package/dist/pii-gateway/gateway.d.ts +17 -0
- package/dist/pii-gateway/gateway.d.ts.map +1 -0
- package/dist/pii-gateway/gateway.js +77 -0
- package/dist/pii-gateway/gateway.js.map +1 -0
- package/dist/pii-gateway/index.d.ts +4 -0
- package/dist/pii-gateway/index.d.ts.map +1 -0
- package/dist/pii-gateway/index.js +14 -0
- package/dist/pii-gateway/index.js.map +1 -0
- package/dist/pii-gateway/proxy.d.ts +80 -0
- package/dist/pii-gateway/proxy.d.ts.map +1 -0
- package/dist/pii-gateway/proxy.js +106 -0
- package/dist/pii-gateway/proxy.js.map +1 -0
- package/dist/pii-gateway/types.d.ts +27 -0
- package/dist/pii-gateway/types.d.ts.map +1 -0
- package/dist/pii-gateway/types.js +3 -0
- package/dist/pii-gateway/types.js.map +1 -0
- package/dist/platform/mindedChatOpenAI.d.ts +5 -0
- package/dist/platform/mindedChatOpenAI.d.ts.map +1 -0
- package/dist/platform/mindedChatOpenAI.js +23 -0
- package/dist/platform/mindedChatOpenAI.js.map +1 -0
- package/dist/platform/mindedCheckpointSaver.js.map +1 -1
- package/dist/platform/mindedUtils.d.ts +1 -0
- package/dist/platform/mindedUtils.d.ts.map +1 -0
- package/dist/platform/mindedUtils.js +2 -0
- package/dist/platform/mindedUtils.js.map +1 -0
- package/dist/platform/parallelAzureChatOpenAI.d.ts +39 -0
- package/dist/platform/parallelAzureChatOpenAI.d.ts.map +1 -0
- package/dist/platform/parallelAzureChatOpenAI.js +114 -0
- package/dist/platform/parallelAzureChatOpenAI.js.map +1 -0
- package/dist/platform/parallelChatOpenAI.d.ts +38 -0
- package/dist/platform/parallelChatOpenAI.d.ts.map +1 -0
- package/dist/platform/parallelChatOpenAI.js +111 -0
- package/dist/platform/parallelChatOpenAI.js.map +1 -0
- package/dist/platform/parallelMindedChatOpenAI.d.ts +39 -0
- package/dist/platform/parallelMindedChatOpenAI.d.ts.map +1 -0
- package/dist/platform/parallelMindedChatOpenAI.js +111 -0
- package/dist/platform/parallelMindedChatOpenAI.js.map +1 -0
- package/dist/platform/piiGateway/proxy.d.ts +20 -0
- package/dist/platform/piiGateway/proxy.d.ts.map +1 -0
- package/dist/platform/piiGateway/proxy.js +24 -0
- package/dist/platform/piiGateway/proxy.js.map +1 -0
- package/dist/platform/toolExecutor.d.ts.map +1 -1
- package/dist/platform/toolExecutor.js +4 -20
- package/dist/platform/toolExecutor.js.map +1 -1
- package/dist/playbooks/playbooks.d.ts +1 -1
- package/dist/playbooks/playbooks.d.ts.map +1 -1
- package/dist/playbooks/playbooks.js +1 -1
- package/dist/playbooks/playbooks.js.map +1 -1
- package/dist/toolsLibrary/classifier.d.ts.map +1 -1
- package/dist/toolsLibrary/classifier.js +5 -9
- package/dist/toolsLibrary/classifier.js.map +1 -1
- package/dist/toolsLibrary/extraction.d.ts.map +1 -1
- package/dist/toolsLibrary/extraction.js +5 -9
- package/dist/toolsLibrary/extraction.js.map +1 -1
- package/dist/toolsLibrary/parseDocument.d.ts.map +1 -1
- package/dist/toolsLibrary/parseDocument.js +6 -14
- package/dist/toolsLibrary/parseDocument.js.map +1 -1
- package/dist/types/Agent.d.ts +2 -0
- package/dist/types/Agent.d.ts.map +1 -0
- package/dist/types/Agent.js +18 -0
- package/dist/types/Agent.js.map +1 -0
- package/dist/types/Agent.types.d.ts +1 -1
- package/dist/types/Agent.types.d.ts.map +1 -1
- package/dist/types/Flows.d.ts +2 -0
- package/dist/types/Flows.d.ts.map +1 -0
- package/dist/types/Flows.js +18 -0
- package/dist/types/Flows.js.map +1 -0
- package/dist/types/LLM.d.ts +2 -0
- package/dist/types/LLM.d.ts.map +1 -0
- package/dist/types/LLM.js +18 -0
- package/dist/types/LLM.js.map +1 -0
- package/dist/types/LangGraph.d.ts +2 -0
- package/dist/types/LangGraph.d.ts.map +1 -0
- package/dist/types/LangGraph.js +18 -0
- package/dist/types/LangGraph.js.map +1 -0
- package/dist/types/LangGraph.types.d.ts.map +1 -1
- package/dist/types/LangGraph.types.js +30 -42
- package/dist/types/LangGraph.types.js.map +1 -1
- package/dist/types/Platform.d.ts +2 -0
- package/dist/types/Platform.d.ts.map +1 -0
- package/dist/types/Platform.js +18 -0
- package/dist/types/Platform.js.map +1 -0
- package/dist/types/Tools.d.ts +2 -0
- package/dist/types/Tools.d.ts.map +1 -0
- package/dist/types/Tools.js +18 -0
- package/dist/types/Tools.js.map +1 -0
- package/dist/types/Tools.types.d.ts +2 -7
- package/dist/types/Tools.types.d.ts.map +1 -1
- package/dist/types/Triggers.d.ts +2 -0
- package/dist/types/Triggers.d.ts.map +1 -0
- package/dist/types/Triggers.js +18 -0
- package/dist/types/Triggers.js.map +1 -0
- package/dist/types/Triggers.types.d.ts +25 -0
- package/dist/types/Triggers.types.d.ts.map +1 -0
- package/dist/types/Triggers.types.js +3 -0
- package/dist/types/Triggers.types.js.map +1 -0
- package/dist/types/Voice.d.ts +2 -0
- package/dist/types/Voice.d.ts.map +1 -0
- package/dist/types/Voice.js +18 -0
- package/dist/types/Voice.js.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +25 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/LogicalConditionDebugger.d.ts +57 -0
- package/dist/utils/LogicalConditionDebugger.d.ts.map +1 -0
- package/dist/utils/LogicalConditionDebugger.js +143 -0
- package/dist/utils/LogicalConditionDebugger.js.map +1 -0
- package/dist/utils/documentProcessor.d.ts +87 -0
- package/dist/utils/documentProcessor.d.ts.map +1 -0
- package/dist/utils/documentProcessor.js +726 -0
- package/dist/utils/documentProcessor.js.map +1 -0
- package/dist/utils/extractStateMemoryResponse.d.ts +0 -4
- package/dist/utils/extractStateMemoryResponse.d.ts.map +1 -1
- package/dist/utils/extractStateMemoryResponse.js +87 -89
- package/dist/utils/extractStateMemoryResponse.js.map +1 -1
- package/dist/utils/extractToolGuidelineParams.d.ts +4 -0
- package/dist/utils/extractToolGuidelineParams.d.ts.map +1 -0
- package/dist/utils/extractToolGuidelineParams.js +20 -0
- package/dist/utils/extractToolGuidelineParams.js.map +1 -0
- package/dist/utils/extractToolMemoryResponse.d.ts +4 -0
- package/dist/utils/extractToolMemoryResponse.d.ts.map +1 -0
- package/dist/utils/extractToolMemoryResponse.js +16 -0
- package/dist/utils/extractToolMemoryResponse.js.map +1 -0
- package/dist/utils/parseAttachments.d.ts +14 -0
- package/dist/utils/parseAttachments.d.ts.map +1 -0
- package/dist/utils/parseAttachments.js +54 -0
- package/dist/utils/parseAttachments.js.map +1 -0
- package/docs/sdk/agent-api.md +1 -1
- package/package.json +1 -1
- package/src/agent.ts +35 -61
- package/src/edges/createLogicalRouter.ts +4 -19
- package/src/events/AgentEvents.ts +5 -14
- package/src/internalTools/libraryActionRunnerTool.ts +0 -1
- package/src/interrupts/BaseInterruptSessionManager.ts +3 -9
- package/src/nodes/addAppToolNode.ts +19 -11
- package/src/nodes/addBrowserTaskNode.ts +22 -16
- package/src/nodes/addBrowserTaskRunNode.ts +10 -9
- package/src/nodes/addJumpToNode.ts +5 -4
- package/src/nodes/addJunctionNode.ts +5 -4
- package/src/nodes/addPromptNode.ts +39 -47
- package/src/nodes/addToolNode.ts +34 -20
- package/src/nodes/addToolRunNode.ts +15 -15
- package/src/nodes/addTriggerNode.ts +5 -5
- package/src/nodes/compilePrompt.ts +3 -0
- package/src/platform/mindedCheckpointSaver.ts +13 -13
- package/src/platform/toolExecutor.ts +4 -20
- package/src/playbooks/playbooks.ts +2 -2
- package/src/toolsLibrary/classifier.ts +6 -9
- package/src/toolsLibrary/extraction.ts +6 -9
- package/src/toolsLibrary/parseDocument.ts +7 -14
- package/src/types/Agent.types.ts +1 -1
- package/src/types/LangGraph.types.ts +30 -41
- package/src/types/Tools.types.ts +2 -7
- package/src/utils/extractStateMemoryResponse.ts +0 -94
|
@@ -9,7 +9,6 @@ import { tool as langchainTool } from '@langchain/core/tools';
|
|
|
9
9
|
import { AgentEventRequestPayloads, AgentEvents } from '../events/AgentEvents';
|
|
10
10
|
import { EmitSignature, HistoryStep } from '../types/Agent.types';
|
|
11
11
|
import { createLlmInstance } from '../llm/createLlmInstance';
|
|
12
|
-
import extractToolStateResponse from '../utils/extractStateMemoryResponse';
|
|
13
12
|
import { Agent } from '../agent';
|
|
14
13
|
import { logger } from '../utils/logger';
|
|
15
14
|
import { combinePlaybooks } from '../playbooks/playbooks';
|
|
@@ -41,19 +40,28 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
|
|
|
41
40
|
}),
|
|
42
41
|
);
|
|
43
42
|
|
|
44
|
-
const combinedPlaybooks = combinePlaybooks(agent.playbooks) || '';
|
|
45
|
-
|
|
46
43
|
// Get edges for the current node and format them
|
|
47
44
|
const edges = agent.flows?.flatMap((flow: any) => flow.edges) || [];
|
|
48
45
|
const nodeEdges = edges.filter((edge: any) => edge.source === node.name);
|
|
49
46
|
const currentPromptNode = getCurrentPromptNode(node, nodeEdges);
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
|
|
48
|
+
let finalMessage = currentPromptNode;
|
|
49
|
+
const combinedPlaybooks = combinePlaybooks(agent.playbooks);
|
|
50
|
+
if (combinedPlaybooks) {
|
|
51
|
+
finalMessage = combinedPlaybooks + '\n\n' + currentPromptNode;
|
|
52
|
+
}
|
|
53
|
+
const compiledPrompt = compilePrompt(finalMessage, { memory: state.memory });
|
|
54
|
+
const systemMessage = new SystemMessage(compiledPrompt);
|
|
55
|
+
if (state.messages.length === 0 || state.messages[0].getType() === 'system') {
|
|
56
|
+
state.messages[0] = systemMessage;
|
|
57
|
+
} else {
|
|
58
|
+
state.messages.unshift(systemMessage);
|
|
59
|
+
}
|
|
52
60
|
|
|
53
61
|
const startTime = Date.now();
|
|
54
|
-
const result: AIMessage = await llmToUse.bindTools(scopedTools).invoke(
|
|
55
|
-
await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId);
|
|
62
|
+
const result: AIMessage = await llmToUse.bindTools(scopedTools).invoke(state.messages);
|
|
56
63
|
const endTime = Date.now();
|
|
64
|
+
await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId);
|
|
57
65
|
logger.debug({
|
|
58
66
|
msg: '[Model] Model execution time',
|
|
59
67
|
executionTimeMs: endTime - startTime,
|
|
@@ -64,7 +72,6 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
|
|
|
64
72
|
if (result.tool_calls && result.tool_calls.length > 0) {
|
|
65
73
|
// Execute the tools
|
|
66
74
|
const toolResults = [];
|
|
67
|
-
let stateUpdates = {};
|
|
68
75
|
|
|
69
76
|
for (const toolCall of result.tool_calls) {
|
|
70
77
|
const matchedTool = scopedTools.find((t) => t.name === toolCall.name);
|
|
@@ -111,13 +118,6 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
|
|
|
111
118
|
}),
|
|
112
119
|
],
|
|
113
120
|
});
|
|
114
|
-
const toolStateUpdate = extractToolStateResponse(toolResult);
|
|
115
|
-
// Properly merge memory and other state updates
|
|
116
|
-
stateUpdates = {
|
|
117
|
-
...stateUpdates,
|
|
118
|
-
...toolStateUpdate,
|
|
119
|
-
memory: { ...(stateUpdates as any).memory, ...(toolStateUpdate as any).memory },
|
|
120
|
-
};
|
|
121
121
|
toolResults.push(toolResult);
|
|
122
122
|
} catch (err: any) {
|
|
123
123
|
if (err?.name === 'GraphInterrupt') throw err;
|
|
@@ -144,56 +144,48 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
|
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
147
|
+
state.messages.push(result, ...toolResults);
|
|
148
|
+
state.history.push(
|
|
149
|
+
createHistoryStep<HistoryStep>(state.history, {
|
|
150
|
+
type: NodeType.TOOL,
|
|
151
|
+
nodeId: node.name,
|
|
152
|
+
nodeDisplayName: node.displayName,
|
|
153
|
+
raw: result,
|
|
154
|
+
messageIds: [result.id!],
|
|
155
|
+
}),
|
|
156
|
+
...toolResults.map((toolResult) =>
|
|
152
157
|
createHistoryStep<HistoryStep>(state.history, {
|
|
153
158
|
type: NodeType.TOOL,
|
|
154
159
|
nodeId: node.name,
|
|
155
160
|
nodeDisplayName: node.displayName,
|
|
156
|
-
raw:
|
|
157
|
-
messageIds: [
|
|
161
|
+
raw: toolResult,
|
|
162
|
+
messageIds: [toolResult.id!],
|
|
158
163
|
}),
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
nodeId: node.name,
|
|
163
|
-
nodeDisplayName: node.displayName,
|
|
164
|
-
raw: toolResult,
|
|
165
|
-
messageIds: [toolResult.id!],
|
|
166
|
-
}),
|
|
167
|
-
),
|
|
168
|
-
],
|
|
169
|
-
};
|
|
164
|
+
),
|
|
165
|
+
);
|
|
166
|
+
return state;
|
|
170
167
|
}
|
|
171
168
|
|
|
172
169
|
// Model text response
|
|
173
170
|
state.goto = null;
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
stateForAIMessage.goto = null;
|
|
177
|
-
stateForAIMessage.messages.push(result);
|
|
178
|
-
let stateUpdate: any = { goto: null, messages: [result] };
|
|
171
|
+
state.messages.push(result);
|
|
172
|
+
|
|
179
173
|
if (result.getType() === 'ai') {
|
|
180
174
|
logger.info({ msg: `[Model] Response`, content: result.content, sessionId: state.sessionId, node: node.displayName });
|
|
181
|
-
|
|
182
|
-
const handlerResult = results.find((r) => r !== undefined);
|
|
183
|
-
if (handlerResult && handlerResult.state) {
|
|
184
|
-
stateUpdate = { ...stateUpdate, ...handlerResult.state };
|
|
185
|
-
}
|
|
175
|
+
await emit(AgentEvents.AI_MESSAGE, { message: result.content as string, state });
|
|
186
176
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
177
|
+
|
|
178
|
+
state.history.push(
|
|
179
|
+
createHistoryStep<HistoryStep>(state.history, {
|
|
190
180
|
type: NodeType.PROMPT_NODE,
|
|
191
181
|
nodeId: node.name,
|
|
192
182
|
nodeDisplayName: node.displayName,
|
|
193
183
|
raw: result.content,
|
|
194
184
|
messageIds: [result.id!],
|
|
195
185
|
}),
|
|
196
|
-
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
return state;
|
|
197
189
|
};
|
|
198
190
|
graph.addNode(node.name, callback);
|
|
199
191
|
};
|
package/src/nodes/addToolNode.ts
CHANGED
|
@@ -40,31 +40,45 @@ export const addToolNode = async ({
|
|
|
40
40
|
schema: matchedTool.input,
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
const combinedPlaybooks = combinePlaybooks(agent.playbooks)
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
const combinedPlaybooks = combinePlaybooks(agent.playbooks);
|
|
44
|
+
const toolPrompt = node.prompt;
|
|
45
|
+
|
|
46
|
+
let finalMessage = toolPrompt;
|
|
47
|
+
if (combinedPlaybooks) {
|
|
48
|
+
if (toolPrompt) {
|
|
49
|
+
finalMessage = combinedPlaybooks + '\n\n' + toolPrompt;
|
|
50
|
+
} else {
|
|
51
|
+
finalMessage = combinedPlaybooks;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (finalMessage) {
|
|
55
|
+
const compiledPrompt = compilePrompt(finalMessage, { memory: state.memory });
|
|
56
|
+
const systemMessage = new SystemMessage(compiledPrompt);
|
|
57
|
+
if (state.messages.length === 0 || state.messages[0].getType() === 'system') {
|
|
58
|
+
state.messages[0] = systemMessage;
|
|
59
|
+
} else {
|
|
60
|
+
state.messages.unshift(systemMessage);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
47
63
|
|
|
48
64
|
const startTime = Date.now();
|
|
49
|
-
const AIToolCallMessage: AIMessage = await llm
|
|
50
|
-
.bindTools([tool], {
|
|
51
|
-
tool_choice: tool.name,
|
|
52
|
-
})
|
|
53
|
-
.invoke([...state.messages, new SystemMessage(systemPrompt)]);
|
|
65
|
+
const AIToolCallMessage: AIMessage = await llm.bindTools([tool], { tool_choice: tool.name }).invoke(state.messages);
|
|
54
66
|
const endTime = Date.now();
|
|
55
67
|
logger.debug({ msg: '[Tool] Model execution time', tool: matchedTool.name, executionTimeMs: endTime - startTime });
|
|
56
68
|
await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
69
|
+
state.goto = null;
|
|
70
|
+
state.messages.push(AIToolCallMessage);
|
|
71
|
+
|
|
72
|
+
const historyMsg = createHistoryStep<HistoryStep>(state.history, {
|
|
73
|
+
type: NodeType.TOOL,
|
|
74
|
+
nodeId: node.name,
|
|
75
|
+
nodeDisplayName: node.displayName,
|
|
76
|
+
raw: AIToolCallMessage.tool_calls?.[0] || '',
|
|
77
|
+
messageIds: [AIToolCallMessage.id!],
|
|
78
|
+
});
|
|
79
|
+
state.history.push(historyMsg);
|
|
80
|
+
|
|
81
|
+
return state;
|
|
68
82
|
};
|
|
69
83
|
graph.addNode(node.name, callback);
|
|
70
84
|
};
|
|
@@ -4,13 +4,12 @@ import { Tool } from '../types/Tools.types';
|
|
|
4
4
|
import { LLMProviders } from '../types/LLM.types';
|
|
5
5
|
import { internalNodesSuffix, NodeType, ToolNode } from '../types/Flows.types';
|
|
6
6
|
import { tool as langchainTool } from '@langchain/core/tools';
|
|
7
|
-
import { ToolMessage } from '@langchain/core/messages';
|
|
8
7
|
import { z } from 'zod';
|
|
9
|
-
import extractToolStateResponse from '../utils/extractStateMemoryResponse';
|
|
10
8
|
import { Agent } from '../agent';
|
|
11
9
|
import { logger } from '../utils/logger';
|
|
12
|
-
import { createHistoryStep } from '../utils/history';
|
|
13
10
|
import { HistoryStep } from '../types/Agent.types';
|
|
11
|
+
import { createHistoryStep } from '../utils/history';
|
|
12
|
+
import { ToolMessage } from '@langchain/core/messages';
|
|
14
13
|
|
|
15
14
|
type AddToolRunNodeParams = {
|
|
16
15
|
graph: PreCompiledGraph;
|
|
@@ -37,7 +36,7 @@ export const addToolRunNode = async ({ graph, tools, toolNode, attachedToNodeNam
|
|
|
37
36
|
const response = await matchedTool.execute({ input, state, agent });
|
|
38
37
|
const endTime = Date.now();
|
|
39
38
|
logger.debug({ msg: '[Tool] Tool execution time', tool: matchedTool.name, executionTimeMs: endTime - startTime });
|
|
40
|
-
return response
|
|
39
|
+
return response as ToolMessage;
|
|
41
40
|
} catch (err) {
|
|
42
41
|
logger.error({ message: '[Tool] Error executing tool', err, node: toolNode.displayName });
|
|
43
42
|
throw err;
|
|
@@ -54,25 +53,26 @@ export const addToolRunNode = async ({ graph, tools, toolNode, attachedToNodeNam
|
|
|
54
53
|
throw new Error('Tool call not found');
|
|
55
54
|
}
|
|
56
55
|
const toolCallMessage = await tool.invoke(toolCallObj.tool_calls[0]);
|
|
57
|
-
const toolStateUpdate = extractToolStateResponse(toolCallMessage as ToolMessage);
|
|
58
56
|
|
|
59
|
-
//
|
|
60
|
-
|
|
57
|
+
// Add the tool message to the state
|
|
58
|
+
state.messages.push(toolCallMessage);
|
|
61
59
|
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
goto: null,
|
|
66
|
-
...toolStateUpdate,
|
|
67
|
-
messages: updatedMessages,
|
|
68
|
-
history: createHistoryStep<HistoryStep>(state.history, {
|
|
60
|
+
// Add history step
|
|
61
|
+
state.history.push(
|
|
62
|
+
createHistoryStep<HistoryStep>(state.history, {
|
|
69
63
|
type: NodeType.TOOL,
|
|
70
64
|
nodeId: toolNode.name,
|
|
71
65
|
nodeDisplayName: toolNode.displayName,
|
|
72
66
|
raw: toolCallMessage,
|
|
73
67
|
messageIds: [toolCallObj.tool_calls[0].id],
|
|
74
68
|
}),
|
|
75
|
-
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
// Clear goto if it was set
|
|
72
|
+
state.goto = null;
|
|
73
|
+
|
|
74
|
+
// Return the entire modified state
|
|
75
|
+
return state;
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
graph.addNode(buildToolRunNodeName(attachedToNodeName), callback);
|
|
@@ -9,18 +9,18 @@ export const addTriggerNode = async ({ graph, node }: { graph: PreCompiledGraph;
|
|
|
9
9
|
const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
|
|
10
10
|
logger.debug({ msg: `[Trigger] Executing trigger node`, node: node.displayName });
|
|
11
11
|
if (node.triggerType === TriggerType.MANUAL) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
state.goto = null;
|
|
13
|
+
state.history.push(
|
|
14
|
+
createHistoryStep<HistoryStep>(state.history, {
|
|
15
15
|
type: NodeType.TRIGGER,
|
|
16
16
|
nodeId: node.name,
|
|
17
17
|
nodeDisplayName: node.displayName,
|
|
18
18
|
raw: '',
|
|
19
19
|
messageIds: [],
|
|
20
20
|
}),
|
|
21
|
-
|
|
21
|
+
);
|
|
22
22
|
}
|
|
23
|
-
return
|
|
23
|
+
return state;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
graph.addNode(node.name, callback);
|
|
@@ -6,6 +6,9 @@ import { logger } from '../utils/logger';
|
|
|
6
6
|
*/
|
|
7
7
|
export function compilePrompt(prompt: string, params: Record<string, any> = {}): string {
|
|
8
8
|
try {
|
|
9
|
+
// Define system parameters
|
|
10
|
+
params.system = { currentTime: new Date().toISOString() };
|
|
11
|
+
|
|
9
12
|
// First, render with EJS
|
|
10
13
|
let compiledPrompt = ejs.render(prompt, params);
|
|
11
14
|
|
|
@@ -49,21 +49,21 @@ export class MindedCheckpointSaver extends BaseCheckpointSaver<number> {
|
|
|
49
49
|
// Re-serialize and deserialize metadata to restore class information
|
|
50
50
|
const metadata = tuple.metadata
|
|
51
51
|
? (() => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
const [metadataType, serializedMetadata] = this.serde.dumpsTyped(tuple.metadata);
|
|
53
|
+
return this.serde.loadsTyped(metadataType, serializedMetadata) as CheckpointMetadata;
|
|
54
|
+
})()
|
|
55
55
|
: undefined;
|
|
56
56
|
|
|
57
57
|
// Re-serialize and deserialize pending writes to restore class information
|
|
58
58
|
const pendingWrites: CheckpointPendingWrite[] = tuple.pendingWrites
|
|
59
59
|
? await Promise.all(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
tuple.pendingWrites.map(async (write) => {
|
|
61
|
+
const [taskId, channel, value] = write;
|
|
62
|
+
const [valueType, serializedValue] = this.serde.dumpsTyped(value);
|
|
63
|
+
const deserializedValue = await this.serde.loadsTyped(valueType, serializedValue);
|
|
64
|
+
return [taskId, channel, deserializedValue] as CheckpointPendingWrite;
|
|
65
|
+
}),
|
|
66
|
+
)
|
|
67
67
|
: [];
|
|
68
68
|
|
|
69
69
|
return {
|
|
@@ -93,9 +93,9 @@ export class MindedCheckpointSaver extends BaseCheckpointSaver<number> {
|
|
|
93
93
|
// Re-serialize and deserialize metadata to restore class information
|
|
94
94
|
const metadata = tuple.metadata
|
|
95
95
|
? (() => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
const [metadataType, serializedMetadata] = this.serde.dumpsTyped(tuple.metadata);
|
|
97
|
+
return this.serde.loadsTyped(metadataType, serializedMetadata) as CheckpointMetadata;
|
|
98
|
+
})()
|
|
99
99
|
: undefined;
|
|
100
100
|
|
|
101
101
|
yield {
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { Tool } from '../types/Tools.types';
|
|
2
2
|
import { Agent } from '../agent';
|
|
3
3
|
import { logger } from '../utils/logger';
|
|
4
|
-
import extractToolStateResponse from '../utils/extractStateMemoryResponse';
|
|
5
|
-
import { ToolMessage } from '@langchain/core/messages';
|
|
6
4
|
|
|
7
5
|
export interface ToolExecutionRequest {
|
|
8
6
|
toolName: string;
|
|
@@ -70,7 +68,7 @@ export class ToolExecutor {
|
|
|
70
68
|
state.cdpUrl = cdpUrl;
|
|
71
69
|
}
|
|
72
70
|
|
|
73
|
-
|
|
71
|
+
await tool.execute({
|
|
74
72
|
input: toolParams,
|
|
75
73
|
state,
|
|
76
74
|
agent: this.agent,
|
|
@@ -83,25 +81,11 @@ export class ToolExecutor {
|
|
|
83
81
|
executionTimeMs: endTime - startTime,
|
|
84
82
|
});
|
|
85
83
|
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
let result = response;
|
|
89
|
-
|
|
90
|
-
// If the response is a ToolMessage, extract state updates
|
|
91
|
-
if (response && typeof response === 'object' && 'content' in response) {
|
|
92
|
-
const toolMessage = response as ToolMessage;
|
|
93
|
-
stateUpdate = extractToolStateResponse(toolMessage);
|
|
94
|
-
// Extract the content as the result
|
|
95
|
-
result = { result: toolMessage.content };
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Update the session state if there are state changes
|
|
99
|
-
if (Object.keys(stateUpdate).length > 0) {
|
|
100
|
-
await this.agent.updateState({ sessionId, state: stateUpdate });
|
|
101
|
-
}
|
|
84
|
+
// Always update the session state after tool execution req
|
|
85
|
+
await this.agent.updateState({ sessionId, state });
|
|
102
86
|
|
|
103
87
|
return {
|
|
104
|
-
|
|
88
|
+
state,
|
|
105
89
|
};
|
|
106
90
|
} catch (err) {
|
|
107
91
|
logger.error({
|
|
@@ -183,9 +183,9 @@ function getAllYamlFiles(dir: string): string[] {
|
|
|
183
183
|
/**
|
|
184
184
|
* Combine playbooks into a single string
|
|
185
185
|
*/
|
|
186
|
-
export function combinePlaybooks(playbooks: Playbook[]): string {
|
|
186
|
+
export function combinePlaybooks(playbooks: Playbook[]): string | undefined {
|
|
187
187
|
if (playbooks.length === 0) {
|
|
188
|
-
return
|
|
188
|
+
return undefined;
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
// Combine all playbooks into sections
|
|
@@ -191,17 +191,14 @@ const classifierTool: Tool<typeof schema, any> = {
|
|
|
191
191
|
confidence: result.confidence,
|
|
192
192
|
});
|
|
193
193
|
|
|
194
|
+
state.memory.lastClassification = {
|
|
195
|
+
content: content.substring(0, 100) + (content.length > 100 ? '...' : ''),
|
|
196
|
+
result,
|
|
197
|
+
timestamp: new Date().toISOString(),
|
|
198
|
+
};
|
|
199
|
+
|
|
194
200
|
return {
|
|
195
201
|
result,
|
|
196
|
-
state: {
|
|
197
|
-
memory: {
|
|
198
|
-
lastClassification: {
|
|
199
|
-
content: content.substring(0, 100) + (content.length > 100 ? '...' : ''),
|
|
200
|
-
result,
|
|
201
|
-
timestamp: new Date().toISOString(),
|
|
202
|
-
},
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
202
|
};
|
|
206
203
|
} catch (err) {
|
|
207
204
|
logger.error({
|
|
@@ -369,17 +369,14 @@ const extractionTool: Tool<typeof schema, any> = {
|
|
|
369
369
|
resultKeys: Object.keys(result),
|
|
370
370
|
});
|
|
371
371
|
|
|
372
|
+
state.memory.lastExtraction = {
|
|
373
|
+
content: content.substring(0, 100) + (content.length > 100 ? '...' : ''),
|
|
374
|
+
result,
|
|
375
|
+
timestamp: new Date().toISOString(),
|
|
376
|
+
};
|
|
377
|
+
|
|
372
378
|
return {
|
|
373
379
|
result,
|
|
374
|
-
state: {
|
|
375
|
-
memory: {
|
|
376
|
-
lastExtraction: {
|
|
377
|
-
content: content.substring(0, 100) + (content.length > 100 ? '...' : ''),
|
|
378
|
-
result,
|
|
379
|
-
timestamp: new Date().toISOString(),
|
|
380
|
-
},
|
|
381
|
-
},
|
|
382
|
-
},
|
|
383
380
|
};
|
|
384
381
|
} catch (err) {
|
|
385
382
|
logger.error({
|
|
@@ -101,18 +101,15 @@ const parseDocumentTool: Tool<typeof schema, any> = {
|
|
|
101
101
|
// Extract from document using the SDK's document extraction capabilities
|
|
102
102
|
const result = await extractFromDocument(extractionOptions);
|
|
103
103
|
|
|
104
|
+
state.memory.lastParsedDocument = {
|
|
105
|
+
source: combinedInput.documentPath || combinedInput.documentUrl || 'content',
|
|
106
|
+
extractedAt: new Date().toISOString(),
|
|
107
|
+
extractedRaw: !!combinedInput.extractRaw,
|
|
108
|
+
};
|
|
109
|
+
|
|
104
110
|
// Return only the extracted data, not the metadata as requested
|
|
105
111
|
return {
|
|
106
112
|
result: result.data,
|
|
107
|
-
state: {
|
|
108
|
-
memory: {
|
|
109
|
-
lastParsedDocument: {
|
|
110
|
-
source: combinedInput.documentPath || combinedInput.documentUrl || 'content',
|
|
111
|
-
extractedAt: new Date().toISOString(),
|
|
112
|
-
extractedRaw: !!combinedInput.extractRaw,
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
113
|
};
|
|
117
114
|
} catch (err) {
|
|
118
115
|
logger.error({
|
|
@@ -121,13 +118,9 @@ const parseDocumentTool: Tool<typeof schema, any> = {
|
|
|
121
118
|
err,
|
|
122
119
|
});
|
|
123
120
|
|
|
121
|
+
state.memory.documentParsingError = err instanceof Error ? err.message : String(err);
|
|
124
122
|
return {
|
|
125
123
|
result: `Failed to parse document: ${err instanceof Error ? err.message : String(err)}`,
|
|
126
|
-
state: {
|
|
127
|
-
memory: {
|
|
128
|
-
documentParsingError: err instanceof Error ? err.message : String(err),
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
124
|
};
|
|
132
125
|
}
|
|
133
126
|
},
|
package/src/types/Agent.types.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { NodeType } from './Flows.types';
|
|
|
5
5
|
export type EmitSignature<Memory, E extends keyof AgentEventRequestPayloads<Memory>> = (
|
|
6
6
|
event: E,
|
|
7
7
|
payload: AgentEventRequestPayloads<Memory>[E],
|
|
8
|
-
) => Promise<AgentEventResponsePayloads
|
|
8
|
+
) => Promise<AgentEventResponsePayloads[E][]>;
|
|
9
9
|
|
|
10
10
|
export type MindedSDKConfig = {
|
|
11
11
|
flows: string[];
|
|
@@ -4,36 +4,12 @@ import { HistoryStep, SessionType } from './Agent.types';
|
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { logger } from '../utils/logger';
|
|
6
6
|
|
|
7
|
-
// Define default values once
|
|
8
|
-
const STATE_DEFAULTS = {
|
|
9
|
-
messages: [] as BaseMessage[],
|
|
10
|
-
history: [] as HistoryStep[],
|
|
11
|
-
sessionId: '',
|
|
12
|
-
goto: null as string | null | undefined,
|
|
13
|
-
sessionType: SessionType.TEXT,
|
|
14
|
-
scenario: {} as Record<string, string | boolean>,
|
|
15
|
-
cdpUrl: null as string | null,
|
|
16
|
-
};
|
|
17
|
-
|
|
18
7
|
export const createStateAnnotation = <Memory = any>(memorySchema?: z.ZodSchema<Memory>) =>
|
|
19
8
|
Annotation.Root({
|
|
20
9
|
messages: Annotation<Array<BaseMessage>>({
|
|
21
|
-
default: () =>
|
|
22
|
-
reducer
|
|
23
|
-
|
|
24
|
-
for (const message of newMessages) {
|
|
25
|
-
if (message.additional_kwargs?.update) {
|
|
26
|
-
const index = res.findIndex((m) => m.id && m.id === message.id);
|
|
27
|
-
if (index !== -1) {
|
|
28
|
-
res[index].content = message.content;
|
|
29
|
-
res[index].additional_kwargs = { ...res[index].additional_kwargs, ...message.additional_kwargs };
|
|
30
|
-
}
|
|
31
|
-
} else {
|
|
32
|
-
res.push(message);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return res;
|
|
36
|
-
},
|
|
10
|
+
default: () => [] as BaseMessage[],
|
|
11
|
+
// Direct replacement - no reducer, just replace the entire value
|
|
12
|
+
reducer: (_, newValue) => newValue,
|
|
37
13
|
}),
|
|
38
14
|
memory: Annotation<Memory>({
|
|
39
15
|
default: () => {
|
|
@@ -47,32 +23,39 @@ export const createStateAnnotation = <Memory = any>(memorySchema?: z.ZodSchema<M
|
|
|
47
23
|
}
|
|
48
24
|
return {} as Memory;
|
|
49
25
|
},
|
|
50
|
-
|
|
26
|
+
// Direct replacement - no reducer, just replace the entire value
|
|
27
|
+
reducer: (_, newValue) => newValue,
|
|
51
28
|
}),
|
|
52
29
|
history: Annotation<Array<HistoryStep>>({
|
|
53
|
-
default: () =>
|
|
54
|
-
reducer
|
|
30
|
+
default: () => [] as HistoryStep[],
|
|
31
|
+
// Direct replacement - no reducer, just replace the entire value
|
|
32
|
+
reducer: (_, newValue) => newValue,
|
|
55
33
|
}),
|
|
56
34
|
sessionId: Annotation<string>({
|
|
57
|
-
default: () =>
|
|
58
|
-
reducer
|
|
35
|
+
default: () => '',
|
|
36
|
+
// Direct replacement - no reducer, just replace the entire value
|
|
37
|
+
reducer: (_, newValue) => newValue,
|
|
59
38
|
}),
|
|
60
39
|
goto: Annotation<string | null | undefined>({
|
|
61
|
-
default: () =>
|
|
62
|
-
reducer
|
|
40
|
+
default: () => null as string | null | undefined,
|
|
41
|
+
// Direct replacement - no reducer, just replace the entire value
|
|
42
|
+
reducer: (_, newValue) => newValue,
|
|
63
43
|
}),
|
|
64
44
|
sessionType: Annotation<SessionType>({
|
|
65
|
-
default: () =>
|
|
66
|
-
reducer
|
|
45
|
+
default: () => SessionType.TEXT,
|
|
46
|
+
// Direct replacement - no reducer, just replace the entire value
|
|
47
|
+
reducer: (_, newValue) => newValue,
|
|
67
48
|
}),
|
|
68
49
|
scenario: Annotation<Record<string, string | boolean>>({
|
|
69
|
-
default: () =>
|
|
70
|
-
reducer
|
|
50
|
+
default: () => ({} as Record<string, string | boolean>),
|
|
51
|
+
// Direct replacement - no reducer, just replace the entire value
|
|
52
|
+
reducer: (_, newValue) => newValue,
|
|
71
53
|
}),
|
|
72
54
|
// Available only when executing browser-use
|
|
73
55
|
cdpUrl: Annotation<string | null>({
|
|
74
|
-
default: () =>
|
|
75
|
-
reducer
|
|
56
|
+
default: () => null as string | null,
|
|
57
|
+
// Direct replacement - no reducer, just replace the entire value
|
|
58
|
+
reducer: (_, newValue) => newValue,
|
|
76
59
|
}),
|
|
77
60
|
});
|
|
78
61
|
|
|
@@ -83,7 +66,13 @@ export const getInitialState = <Memory = any>(memorySchema?: z.ZodSchema<Memory>
|
|
|
83
66
|
const memory = memorySchema ? memorySchema.parse({}) : ({} as Memory);
|
|
84
67
|
|
|
85
68
|
return {
|
|
86
|
-
|
|
69
|
+
messages: [],
|
|
70
|
+
history: [],
|
|
71
|
+
sessionId: '',
|
|
72
|
+
goto: null,
|
|
73
|
+
sessionType: SessionType.TEXT,
|
|
74
|
+
scenario: {},
|
|
75
|
+
cdpUrl: null,
|
|
87
76
|
memory,
|
|
88
77
|
} as State<Memory>;
|
|
89
78
|
};
|
package/src/types/Tools.types.ts
CHANGED
|
@@ -2,13 +2,8 @@ import { z } from 'zod';
|
|
|
2
2
|
import { Agent } from '../';
|
|
3
3
|
import { State } from './LangGraph.types';
|
|
4
4
|
|
|
5
|
-
// Type for state updates that allows partial memory
|
|
6
|
-
type StateUpdate<Memory = any> = Omit<Partial<State<Memory>>, 'memory'> & {
|
|
7
|
-
memory?: Partial<Memory>;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
5
|
// Valid return type for new API
|
|
11
|
-
export type ToolReturnType
|
|
6
|
+
export type ToolReturnType = { result?: any } | void;
|
|
12
7
|
|
|
13
8
|
export interface Tool<Input extends z.ZodSchema, Memory = any> {
|
|
14
9
|
name: string;
|
|
@@ -16,7 +11,7 @@ export interface Tool<Input extends z.ZodSchema, Memory = any> {
|
|
|
16
11
|
input: Input;
|
|
17
12
|
isGlobal?: boolean;
|
|
18
13
|
allowExecutionRequests?: boolean;
|
|
19
|
-
execute: (input: ToolExecuteInput<Input, Memory>) => Promise<ToolReturnType
|
|
14
|
+
execute: (input: ToolExecuteInput<Input, Memory>) => Promise<ToolReturnType>;
|
|
20
15
|
}
|
|
21
16
|
|
|
22
17
|
export interface ToolExecuteInput<Input extends z.ZodSchema, Memory = any> {
|