@minded-ai/mindedjs 1.0.32 → 1.0.34
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/nodes/actionRunnerNode.d.ts.map +1 -1
- package/dist/nodes/actionRunnerNode.js +1 -0
- package/dist/nodes/actionRunnerNode.js.map +1 -1
- package/dist/nodes/addAppToolNode.d.ts +5 -5
- package/dist/nodes/addAppToolNode.d.ts.map +1 -1
- package/dist/nodes/addAppToolNode.js +30 -25
- package/dist/nodes/addAppToolNode.js.map +1 -1
- package/dist/nodes/addPromptNode.d.ts.map +1 -1
- package/dist/nodes/addPromptNode.js +42 -24
- package/dist/nodes/addPromptNode.js.map +1 -1
- package/dist/nodes/addToolNode.d.ts.map +1 -1
- package/dist/nodes/addToolNode.js +16 -38
- package/dist/nodes/addToolNode.js.map +1 -1
- 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/package.json +1 -1
- package/src/nodes/addPromptNode.ts +45 -27
- package/src/nodes/addToolNode.ts +15 -43
- package/src/utils/extractToolMemoryResponse.ts +15 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actionRunnerNode.d.ts","sourceRoot":"","sources":["../../src/nodes/actionRunnerNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAY,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAIzE,OAAO,EAAa,WAAW,EAAiB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAG9F,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,QAAA,MAAM,gBAAgB,GAAI,MAAM,EAAE,aAAa,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,UAAU,QAAQ,GAAG,WAAW,EAAE,KAAK,iBAAiB,EAAE,cAAc,MAAM,EAAE,UAAU,WAAW,EAAE,MACvJ,OAAO,OAAO,eAAe,CAAC,KAAK;;;;;
|
|
1
|
+
{"version":3,"file":"actionRunnerNode.d.ts","sourceRoot":"","sources":["../../src/nodes/actionRunnerNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAY,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAIzE,OAAO,EAAa,WAAW,EAAiB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAG9F,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,QAAA,MAAM,gBAAgB,GAAI,MAAM,EAAE,aAAa,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,UAAU,QAAQ,GAAG,WAAW,EAAE,KAAK,iBAAiB,EAAE,cAAc,MAAM,EAAE,UAAU,WAAW,EAAE,MACvJ,OAAO,OAAO,eAAe,CAAC,KAAK;;;;;EA2EpD,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -13,6 +13,7 @@ const actionRunnerTool = (matchedTool, toolNode, llm, addedPrompt, history) => {
|
|
|
13
13
|
const executeWrapper = async (input) => {
|
|
14
14
|
try {
|
|
15
15
|
const response = await matchedTool.execute({ input, memory: state.memory, triggerInvocations: state.triggerInvocations });
|
|
16
|
+
console.log("response", response);
|
|
16
17
|
return response || {};
|
|
17
18
|
}
|
|
18
19
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file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import { LLMProviders } from '../types/LLM.types';
|
|
4
4
|
export declare const addAppToolNode: ({ graph, node, llm, }: {
|
|
5
5
|
graph: PreCompiledGraph;
|
|
6
6
|
node: AppToolNode;
|
|
7
|
-
llm:
|
|
8
|
-
}) => void
|
|
7
|
+
llm: (typeof LLMProviders)[keyof typeof LLMProviders];
|
|
8
|
+
}) => Promise<void>;
|
|
9
9
|
//# sourceMappingURL=addAppToolNode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addAppToolNode.d.ts","sourceRoot":"","sources":["../../src/nodes/addAppToolNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"addAppToolNode.d.ts","sourceRoot":"","sources":["../../src/nodes/addAppToolNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,gBAAgB,EAAmB,MAAM,0BAA0B,CAAC;AAI7E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIlD,eAAO,MAAM,cAAc,GAAU,uBAIlC;IACC,KAAK,EAAE,gBAAgB,CAAC;IACxB,IAAI,EAAE,WAAW,CAAC;IAClB,GAAG,EAAE,CAAA,OAAO,YAAY,EAAC,MAAM,OAAO,YAAY,CAAC,CAAC;CACvD,kBA8BA,CAAC"}
|
|
@@ -1,34 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.addAppToolNode = void 0;
|
|
7
|
-
const
|
|
4
|
+
const tools_1 = require("@langchain/core/tools");
|
|
5
|
+
const messages_1 = require("@langchain/core/messages");
|
|
8
6
|
const appActionRunnerTool_1 = require("../internalTools/appActionRunnerTool");
|
|
9
7
|
const Agent_types_1 = require("../types/Agent.types");
|
|
10
|
-
const addAppToolNode = ({ graph, node, llm, }) => {
|
|
8
|
+
const addAppToolNode = async ({ graph, node, llm, }) => {
|
|
11
9
|
const appRunnerTool = (0, appActionRunnerTool_1.getAppActionRunnerTool)(node.name);
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
10
|
+
const callback = async (state) => {
|
|
11
|
+
console.log(`Executing tool node ${appRunnerTool.name}`);
|
|
12
|
+
const executeWrapper = async (input) => {
|
|
13
|
+
try {
|
|
14
|
+
const response = await appRunnerTool.execute({ input, memory: state.memory, triggerInvocations: state.triggerInvocations });
|
|
15
|
+
return response || {};
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
console.error('Error executing tool', error);
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const tool = (0, tools_1.tool)(executeWrapper, {
|
|
23
|
+
name: appRunnerTool.name,
|
|
24
|
+
description: appRunnerTool.description,
|
|
25
|
+
schema: appRunnerTool.input,
|
|
26
|
+
});
|
|
27
|
+
const prompt = `
|
|
28
|
+
Additional context:
|
|
29
|
+
workflow memory: ${JSON.stringify(state.memory)}
|
|
30
|
+
`;
|
|
31
|
+
const AIToolCallMessage = await llm.bindTools([tool], {
|
|
32
|
+
tool_choice: tool.name,
|
|
33
|
+
}).invoke([...state.messages, new messages_1.SystemMessage(prompt)]);
|
|
34
|
+
const toolCallMessage = await tool.invoke(AIToolCallMessage.tool_calls[0]);
|
|
35
|
+
return { messages: [AIToolCallMessage, toolCallMessage], history: [{ type: Agent_types_1.FlowHistoryType.APP_ACTION_INVOCATION, nodeTitle: node.name }] };
|
|
36
|
+
};
|
|
32
37
|
graph.addNode(node.name, callback);
|
|
33
38
|
};
|
|
34
39
|
exports.addAppToolNode = addAppToolNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addAppToolNode.js","sourceRoot":"","sources":["../../src/nodes/addAppToolNode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"addAppToolNode.js","sourceRoot":"","sources":["../../src/nodes/addAppToolNode.ts"],"names":[],"mappings":";;;AACA,iDAA8D;AAE9D,uDAAyD;AAIzD,8EAA8E;AAC9E,sDAAuD;AAEhD,MAAM,cAAc,GAAG,KAAK,EAAE,EACjC,KAAK,EACL,IAAI,EACJ,GAAG,GAKN,EAAE,EAAE;IACD,MAAM,aAAa,GAAG,IAAA,4CAAsB,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxD,MAAM,QAAQ,GAAiB,KAAK,EAAE,KAAmC,EAAE,EAAE;QACzE,OAAO,CAAC,GAAG,CAAC,uBAAuB,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;QAEzD,MAAM,cAAc,GAAG,KAAK,EAAE,KAA0C,EAAE,EAAE;YACxE,IAAI,CAAC;gBACD,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,CAAC,kBAAkB,EAAE,CAAC,CAAC;gBAC5H,OAAO,QAAQ,IAAI,EAAE,CAAC;YAC1B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;gBAC7C,MAAM,KAAK,CAAC;YAChB,CAAC;QACL,CAAC,CAAC;QACF,MAAM,IAAI,GAAG,IAAA,YAAa,EAAC,cAAc,EAAE;YACvC,IAAI,EAAE,aAAa,CAAC,IAAI;YACxB,WAAW,EAAE,aAAa,CAAC,WAAW;YACtC,MAAM,EAAE,aAAa,CAAC,KAAK;SAC9B,CAAC,CAAC;QACH,MAAM,MAAM,GAAG;;6BAEM,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC;SAChD,CAAC;QACF,MAAM,iBAAiB,GAAG,MAAM,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,EAAE;YAClD,WAAW,EAAE,IAAI,CAAC,IAAI;SACzB,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,QAAQ,EAAE,IAAI,wBAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC1D,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;QAC1E,OAAO,EAAE,QAAQ,EAAE,CAAC,iBAAiB,EAAE,eAAe,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,6BAAe,CAAC,qBAAqB,EAAE,SAAS,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;IAChJ,CAAC,CAAA;IACD,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACvC,CAAC,CAAC;AAtCW,QAAA,cAAc,kBAsCzB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addPromptNode.d.ts","sourceRoot":"","sources":["../../src/nodes/addPromptNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAmB,MAAM,0BAA0B,CAAC;AAE7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"addPromptNode.d.ts","sourceRoot":"","sources":["../../src/nodes/addPromptNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAmB,MAAM,0BAA0B,CAAC;AAE7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAEzE,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C,OAAO,EAAE,yBAAyB,EAAe,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAIrD,KAAK,mBAAmB,GAAG;IACzB,KAAK,EAAE,gBAAgB,CAAC;IACxB,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;CAChE,CAAC;AAEF,eAAO,MAAM,aAAa,GAAU,mCAAmC,mBAAmB,kBAqEzF,CAAC"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.addPromptNode = void 0;
|
|
4
|
-
const zod_1 = require("zod");
|
|
5
|
-
const prebuilt_1 = require("@langchain/langgraph/prebuilt");
|
|
6
7
|
const messages_1 = require("@langchain/core/messages");
|
|
7
8
|
const tools_1 = require("@langchain/core/tools");
|
|
8
9
|
const AgentEvents_1 = require("../events/AgentEvents");
|
|
9
10
|
const createLlmInstance_1 = require("../llm/createLlmInstance");
|
|
10
|
-
const
|
|
11
|
-
const uuid_1 = require("uuid");
|
|
11
|
+
const extractToolMemoryResponse_1 = __importDefault(require("../utils/extractToolMemoryResponse"));
|
|
12
12
|
const addPromptNode = async ({ graph, node, llm, tools, emit }) => {
|
|
13
13
|
const callback = async (state, { configurable }) => {
|
|
14
14
|
console.log(`Executing prompt node ${node.name}`);
|
|
@@ -20,34 +20,52 @@ const addPromptNode = async ({ graph, node, llm, tools, emit }) => {
|
|
|
20
20
|
description: tool.description,
|
|
21
21
|
schema: tool.input,
|
|
22
22
|
}));
|
|
23
|
-
const agent = (0, prebuilt_1.createReactAgent)({
|
|
24
|
-
checkpointer: new langgraph_1.MemorySaver(),
|
|
25
|
-
llm: llmToUse,
|
|
26
|
-
tools: globalTools,
|
|
27
|
-
responseFormat: zod_1.z.object({
|
|
28
|
-
waitForUserResponse: zod_1.z.boolean(),
|
|
29
|
-
done: zod_1.z.boolean(),
|
|
30
|
-
}),
|
|
31
|
-
});
|
|
32
23
|
const message = `
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
- Conversation history: ${state.messages.map((message) => `${message.getType()}: ${message.content}`).join('\n')}
|
|
24
|
+
Additional context:
|
|
25
|
+
${node.prompt ? `- User instructions: ${node.prompt}` : ''}
|
|
26
|
+
${state.memory ? `- Workflow memory: ${JSON.stringify(state.memory)}` : ''}
|
|
37
27
|
`;
|
|
38
|
-
const result = await
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
28
|
+
const result = await llmToUse.bindTools(globalTools).invoke([...state.messages, new messages_1.SystemMessage(message)]);
|
|
29
|
+
// Check if the result contains tool calls
|
|
30
|
+
const aiMessage = result;
|
|
31
|
+
if (aiMessage.tool_calls && aiMessage.tool_calls.length > 0) {
|
|
32
|
+
// Execute the tools
|
|
33
|
+
const toolResults = [];
|
|
34
|
+
let updatedMemory = { ...state.memory };
|
|
35
|
+
for (const toolCall of aiMessage.tool_calls) {
|
|
36
|
+
const matchedTool = globalTools.find((t) => t.name === toolCall.name);
|
|
37
|
+
if (matchedTool) {
|
|
38
|
+
try {
|
|
39
|
+
// Invoke the LangChain tool directly
|
|
40
|
+
const toolResult = await matchedTool.invoke(toolCall);
|
|
41
|
+
updatedMemory = { ...updatedMemory, ...(0, extractToolMemoryResponse_1.default)(toolResult) };
|
|
42
|
+
toolResults.push(toolResult);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.error(`Error executing tool ${toolCall.name}:`, error);
|
|
46
|
+
const errorMessage = new messages_1.ToolMessage({
|
|
47
|
+
content: JSON.stringify({ error: error instanceof Error ? error.message : String(error) }),
|
|
48
|
+
tool_call_id: toolCall.id,
|
|
49
|
+
});
|
|
50
|
+
toolResults.push(errorMessage);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Return the tool call message and tool results
|
|
55
|
+
return {
|
|
56
|
+
messages: [result, ...toolResults],
|
|
57
|
+
memory: updatedMemory,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (result.getType() === 'ai') {
|
|
43
61
|
await emit(AgentEvents_1.AgentEvents.AI_MESSAGE, {
|
|
44
|
-
message:
|
|
62
|
+
message: result.content,
|
|
45
63
|
memory: state.memory,
|
|
46
64
|
sessionId: configurable.thread_id,
|
|
47
65
|
});
|
|
48
66
|
}
|
|
49
67
|
return {
|
|
50
|
-
messages: [
|
|
68
|
+
messages: [result],
|
|
51
69
|
};
|
|
52
70
|
};
|
|
53
71
|
graph.addNode(node.name, callback);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addPromptNode.js","sourceRoot":"","sources":["../../src/nodes/addPromptNode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"addPromptNode.js","sourceRoot":"","sources":["../../src/nodes/addPromptNode.ts"],"names":[],"mappings":";;;;;;AAKA,uDAAiF;AAEjF,iDAA8D;AAC9D,uDAA+E;AAE/E,gEAA6D;AAC7D,mGAA2E;AAUpE,MAAM,aAAa,GAAG,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAuB,EAAE,EAAE;IAC5F,MAAM,QAAQ,GAAiB,KAAK,EAAE,KAAmC,EAAE,EAAE,Y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QAED,IAAI,MAAM,CAAC,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC,yBAAW,CAAC,UAAU,EAAE;gBACjC,OAAO,EAAE,MAAM,CAAC,OAAiB;gBACjC,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,SAAS,EAAE,YAAY,CAAC,SAAS;aAClC,CAAC,CAAC;QACL,CAAC;QAED,OAAO;YACL,QAAQ,EAAE,CAAC,MAAM,CAAC;SACnB,CAAC;IACJ,CAAC,CAAC;IACF,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACrC,CAAC,CAAC;AArEW,QAAA,aAAa,iBAqExB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addToolNode.d.ts","sourceRoot":"","sources":["../../src/nodes/addToolNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C,OAAO,EAAE,gBAAgB,EAAmB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"addToolNode.d.ts","sourceRoot":"","sources":["../../src/nodes/addToolNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C,OAAO,EAAE,gBAAgB,EAAmB,MAAM,0BAA0B,CAAC;AAI7E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,eAAO,MAAM,WAAW,GAAU,MAAM,EAAE,8BAKvC;IACD,KAAK,EAAE,gBAAgB,CAAC;IACxB,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;IACxB,GAAG,EAAE,CAAC,OAAO,YAAY,EAAE,MAAM,OAAO,YAAY,CAAC,CAAC;CACvD,kBAqCA,CAAC"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.addToolNode = void 0;
|
|
4
7
|
const tools_1 = require("@langchain/core/tools");
|
|
5
8
|
const messages_1 = require("@langchain/core/messages");
|
|
6
|
-
const
|
|
9
|
+
const extractToolMemoryResponse_1 = __importDefault(require("../utils/extractToolMemoryResponse"));
|
|
7
10
|
const addToolNode = async ({ graph, node, tools, llm, }) => {
|
|
8
11
|
const toolNode = node;
|
|
9
12
|
const matchedTool = tools.find((tool) => tool.name === toolNode.toolName);
|
|
@@ -22,50 +25,25 @@ const addToolNode = async ({ graph, node, tools, llm, }) => {
|
|
|
22
25
|
throw error;
|
|
23
26
|
}
|
|
24
27
|
};
|
|
25
|
-
const prompt = `
|
|
26
|
-
Context:
|
|
27
|
-
workflow memory: ${JSON.stringify(state.memory)}
|
|
28
|
-
|
|
29
|
-
Task:
|
|
30
|
-
Extract the necessary parameters for the tool "${matchedTool.name}" based on the context above and the previous messages.
|
|
31
|
-
|
|
32
|
-
${toolNode.prompt ? `Additional guidance for parameter extraction: ${toolNode.prompt}` : ''}
|
|
33
|
-
|
|
34
|
-
Important:
|
|
35
|
-
- Extract ONLY the parameters that match the schema
|
|
36
|
-
- Use your best judgment to fill in any missing values
|
|
37
|
-
- Do not include any parameters not defined in the schema
|
|
38
|
-
- Return a valid JSON object matching the schema exactly
|
|
39
|
-
`;
|
|
40
|
-
const structuredLlm = llm.withStructuredOutput(matchedTool.input);
|
|
41
|
-
const structuredResponse = await structuredLlm.invoke([...state.messages, new messages_1.SystemMessage(prompt)]);
|
|
42
28
|
const tool = (0, tools_1.tool)(executeWrapper, {
|
|
43
29
|
name: matchedTool.name,
|
|
44
30
|
description: matchedTool.description,
|
|
45
31
|
schema: matchedTool.input,
|
|
46
32
|
});
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
33
|
+
const prompt = `
|
|
34
|
+
Additional context:
|
|
35
|
+
workflow memory: ${JSON.stringify(state.memory)}
|
|
36
|
+
`;
|
|
37
|
+
const AIToolCallMessage = await llm
|
|
38
|
+
.bindTools([tool], {
|
|
39
|
+
tool_choice: tool.name,
|
|
40
|
+
})
|
|
41
|
+
.invoke([...state.messages, new messages_1.SystemMessage(prompt)]);
|
|
42
|
+
const toolCallMessage = await tool.invoke(AIToolCallMessage.tool_calls[0]);
|
|
43
|
+
const toolMemory = (0, extractToolMemoryResponse_1.default)(toolCallMessage);
|
|
44
|
+
return { memory: toolMemory, messages: [AIToolCallMessage, toolCallMessage] };
|
|
55
45
|
};
|
|
56
46
|
graph.addNode(node.name, callback);
|
|
57
47
|
};
|
|
58
48
|
exports.addToolNode = addToolNode;
|
|
59
|
-
const extractToolMemoryResponse = (toolMessage) => {
|
|
60
|
-
try {
|
|
61
|
-
const parsed = JSON.parse(toolMessage.content);
|
|
62
|
-
if (typeof parsed === 'object' && parsed !== null && 'memory' in parsed) {
|
|
63
|
-
return parsed.memory;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
console.error('Error parsing tool memory response', error);
|
|
68
|
-
}
|
|
69
|
-
return {};
|
|
70
|
-
};
|
|
71
49
|
//# sourceMappingURL=addToolNode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addToolNode.js","sourceRoot":"","sources":["../../src/nodes/addToolNode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"addToolNode.js","sourceRoot":"","sources":["../../src/nodes/addToolNode.ts"],"names":[],"mappings":";;;;;;AAEA,iDAA8D;AAE9D,uDAAsE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C,MAAM,CAAC;SAChD,CAAC;QACN,MAAM,iBAAiB,GAAG,MAAM,GAAG;aAChC,SAAS,CAAC,CAAC,IAAI,CAAC,EAAE;YACjB,WAAW,EAAE,IAAI,CAAC,IAAI;SACvB,CAAC;aACD,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,QAAQ,EAAE,IAAI,wBAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC1D,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3E,MAAM,UAAU,GAAG,IAAA,mCAAyB,EAAS,eAA8B,CAAC,CAAC;QACrF,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,iBAAiB,EAAE,eAAe,CAAC,EAAE,CAAC;IAChF,CAAC,CAAC;IACF,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACrC,CAAC,CAAC;AA/CW,QAAA,WAAW,eA+CtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractToolMemoryResponse.d.ts","sourceRoot":"","sources":["../../src/utils/extractToolMemoryResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,QAAA,MAAM,yBAAyB,GAAI,MAAM,EAAE,aAAa,WAAW,KAAG,OAAO,CAAC,MAAM,CAUnF,CAAC;AAEF,eAAe,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const extractToolMemoryResponse = (toolMessage) => {
|
|
4
|
+
try {
|
|
5
|
+
const parsed = JSON.parse(toolMessage.content);
|
|
6
|
+
if (typeof parsed === 'object' && parsed !== null && 'memory' in parsed) {
|
|
7
|
+
return parsed.memory;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
console.error('Error parsing tool memory response', error);
|
|
12
|
+
}
|
|
13
|
+
return {};
|
|
14
|
+
};
|
|
15
|
+
exports.default = extractToolMemoryResponse;
|
|
16
|
+
//# sourceMappingURL=extractToolMemoryResponse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractToolMemoryResponse.js","sourceRoot":"","sources":["../../src/utils/extractToolMemoryResponse.ts"],"names":[],"mappings":";;AAEA,MAAM,yBAAyB,GAAG,CAAS,WAAwB,EAAmB,EAAE;IACtF,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAiB,CAAC,CAAC;QACzD,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,QAAQ,IAAI,MAAM,EAAE,CAAC;YACxE,OAAO,MAAM,CAAC,MAAM,CAAC;QACvB,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAEF,kBAAe,yBAAyB,CAAC"}
|
package/package.json
CHANGED
|
@@ -3,15 +3,13 @@ import { PromptNode } from '../types/Flows.types';
|
|
|
3
3
|
import { PreCompiledGraph, stateAnnotation } from '../types/LangGraph.types';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { BaseLanguageModel } from '@langchain/core/language_models/base';
|
|
6
|
-
import {
|
|
7
|
-
import { SystemMessage } from '@langchain/core/messages';
|
|
6
|
+
import { SystemMessage, AIMessage, ToolMessage } from '@langchain/core/messages';
|
|
8
7
|
import { Tool } from '../types/Tools.types';
|
|
9
8
|
import { tool as langchainTool } from '@langchain/core/tools';
|
|
10
9
|
import { AgentEventRequestPayloads, AgentEvents } from '../events/AgentEvents';
|
|
11
10
|
import { EmitSignature } from '../types/Agent.types';
|
|
12
11
|
import { createLlmInstance } from '../llm/createLlmInstance';
|
|
13
|
-
import
|
|
14
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
12
|
+
import extractToolMemoryResponse from '../utils/extractToolMemoryResponse';
|
|
15
13
|
|
|
16
14
|
type AddPromptNodeParams = {
|
|
17
15
|
graph: PreCompiledGraph;
|
|
@@ -36,37 +34,57 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit }: AddPrompt
|
|
|
36
34
|
}),
|
|
37
35
|
);
|
|
38
36
|
|
|
39
|
-
const agent = createReactAgent({
|
|
40
|
-
checkpointer: new MemorySaver(),
|
|
41
|
-
llm: llmToUse,
|
|
42
|
-
tools: globalTools,
|
|
43
|
-
responseFormat: z.object({
|
|
44
|
-
waitForUserResponse: z.boolean(),
|
|
45
|
-
done: z.boolean(),
|
|
46
|
-
}),
|
|
47
|
-
});
|
|
48
37
|
const message = `
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
- Conversation history: ${state.messages.map((message) => `${message.getType()}: ${message.content}`).join('\n')}
|
|
38
|
+
Additional context:
|
|
39
|
+
${node.prompt ? `- User instructions: ${node.prompt}` : ''}
|
|
40
|
+
${state.memory ? `- Workflow memory: ${JSON.stringify(state.memory)}` : ''}
|
|
53
41
|
`;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
|
|
42
|
+
|
|
43
|
+
const result = await llmToUse.bindTools(globalTools).invoke([...state.messages, new SystemMessage(message)]);
|
|
44
|
+
|
|
45
|
+
// Check if the result contains tool calls
|
|
46
|
+
const aiMessage = result as AIMessage;
|
|
47
|
+
if (aiMessage.tool_calls && aiMessage.tool_calls.length > 0) {
|
|
48
|
+
// Execute the tools
|
|
49
|
+
const toolResults = [];
|
|
50
|
+
let updatedMemory = { ...state.memory };
|
|
51
|
+
|
|
52
|
+
for (const toolCall of aiMessage.tool_calls) {
|
|
53
|
+
const matchedTool = globalTools.find((t) => t.name === toolCall.name);
|
|
54
|
+
if (matchedTool) {
|
|
55
|
+
try {
|
|
56
|
+
// Invoke the LangChain tool directly
|
|
57
|
+
const toolResult = await matchedTool.invoke(toolCall);
|
|
58
|
+
updatedMemory = { ...updatedMemory, ...extractToolMemoryResponse(toolResult) };
|
|
59
|
+
toolResults.push(toolResult);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
console.error(`Error executing tool ${toolCall.name}:`, error);
|
|
62
|
+
const errorMessage = new ToolMessage({
|
|
63
|
+
content: JSON.stringify({ error: error instanceof Error ? error.message : String(error) }),
|
|
64
|
+
tool_call_id: toolCall.id!,
|
|
65
|
+
});
|
|
66
|
+
toolResults.push(errorMessage);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Return the tool call message and tool results
|
|
72
|
+
return {
|
|
73
|
+
messages: [result, ...toolResults],
|
|
74
|
+
memory: updatedMemory,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (result.getType() === 'ai') {
|
|
62
79
|
await emit(AgentEvents.AI_MESSAGE, {
|
|
63
|
-
message:
|
|
80
|
+
message: result.content as string,
|
|
64
81
|
memory: state.memory,
|
|
65
82
|
sessionId: configurable.thread_id,
|
|
66
83
|
});
|
|
67
84
|
}
|
|
85
|
+
|
|
68
86
|
return {
|
|
69
|
-
messages: [
|
|
87
|
+
messages: [result],
|
|
70
88
|
};
|
|
71
89
|
};
|
|
72
90
|
graph.addNode(node.name, callback);
|
package/src/nodes/addToolNode.ts
CHANGED
|
@@ -5,8 +5,8 @@ import { PreCompiledGraph, stateAnnotation } from '../types/LangGraph.types';
|
|
|
5
5
|
import { SystemMessage, ToolMessage } from '@langchain/core/messages';
|
|
6
6
|
import { RunnableLike } from '@langchain/core/runnables';
|
|
7
7
|
import { z } from 'zod';
|
|
8
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
9
8
|
import { LLMProviders } from '../types/LLM.types';
|
|
9
|
+
import extractToolMemoryResponse from '../utils/extractToolMemoryResponse';
|
|
10
10
|
|
|
11
11
|
export const addToolNode = async <Memory>({
|
|
12
12
|
graph,
|
|
@@ -17,7 +17,7 @@ export const addToolNode = async <Memory>({
|
|
|
17
17
|
graph: PreCompiledGraph;
|
|
18
18
|
node: ToolNode;
|
|
19
19
|
tools: Tool<any, any>[];
|
|
20
|
-
llm: typeof LLMProviders[keyof typeof LLMProviders];
|
|
20
|
+
llm: (typeof LLMProviders)[keyof typeof LLMProviders];
|
|
21
21
|
}) => {
|
|
22
22
|
const toolNode = node as ToolNode;
|
|
23
23
|
const matchedTool = tools.find((tool) => tool.name === toolNode.toolName);
|
|
@@ -36,51 +36,23 @@ export const addToolNode = async <Memory>({
|
|
|
36
36
|
throw error;
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
|
-
const prompt = `
|
|
40
|
-
Context:
|
|
41
|
-
workflow memory: ${JSON.stringify(state.memory)}
|
|
42
|
-
|
|
43
|
-
Task:
|
|
44
|
-
Extract the necessary parameters for the tool "${matchedTool.name}" based on the context above and the previous messages.
|
|
45
|
-
|
|
46
|
-
${toolNode.prompt ? `Additional guidance for parameter extraction: ${toolNode.prompt}` : ''}
|
|
47
|
-
|
|
48
|
-
Important:
|
|
49
|
-
- Extract ONLY the parameters that match the schema
|
|
50
|
-
- Use your best judgment to fill in any missing values
|
|
51
|
-
- Do not include any parameters not defined in the schema
|
|
52
|
-
- Return a valid JSON object matching the schema exactly
|
|
53
|
-
`;
|
|
54
|
-
const structuredLlm = llm.withStructuredOutput(matchedTool.input);
|
|
55
|
-
const structuredResponse = await structuredLlm.invoke([...state.messages, new SystemMessage(prompt)])
|
|
56
39
|
const tool = langchainTool(executeWrapper, {
|
|
57
40
|
name: matchedTool.name,
|
|
58
41
|
description: matchedTool.description,
|
|
59
42
|
schema: matchedTool.input,
|
|
60
43
|
});
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
44
|
+
const prompt = `
|
|
45
|
+
Additional context:
|
|
46
|
+
workflow memory: ${JSON.stringify(state.memory)}
|
|
47
|
+
`;
|
|
48
|
+
const AIToolCallMessage = await llm
|
|
49
|
+
.bindTools([tool], {
|
|
50
|
+
tool_choice: tool.name,
|
|
51
|
+
})
|
|
52
|
+
.invoke([...state.messages, new SystemMessage(prompt)]);
|
|
53
|
+
const toolCallMessage = await tool.invoke(AIToolCallMessage.tool_calls[0]);
|
|
54
|
+
const toolMemory = extractToolMemoryResponse<Memory>(toolCallMessage as ToolMessage);
|
|
55
|
+
return { memory: toolMemory, messages: [AIToolCallMessage, toolCallMessage] };
|
|
56
|
+
};
|
|
72
57
|
graph.addNode(node.name, callback);
|
|
73
58
|
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const extractToolMemoryResponse = <Memory>(toolMessage: ToolMessage): Partial<Memory> => {
|
|
77
|
-
try {
|
|
78
|
-
const parsed = JSON.parse(toolMessage.content as string);
|
|
79
|
-
if (typeof parsed === 'object' && parsed !== null && 'memory' in parsed) {
|
|
80
|
-
return parsed.memory;
|
|
81
|
-
}
|
|
82
|
-
} catch (error) {
|
|
83
|
-
console.error('Error parsing tool memory response', error);
|
|
84
|
-
}
|
|
85
|
-
return {};
|
|
86
|
-
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ToolMessage } from '@langchain/core/messages';
|
|
2
|
+
|
|
3
|
+
const extractToolMemoryResponse = <Memory>(toolMessage: ToolMessage): Partial<Memory> => {
|
|
4
|
+
try {
|
|
5
|
+
const parsed = JSON.parse(toolMessage.content as string);
|
|
6
|
+
if (typeof parsed === 'object' && parsed !== null && 'memory' in parsed) {
|
|
7
|
+
return parsed.memory;
|
|
8
|
+
}
|
|
9
|
+
} catch (error) {
|
|
10
|
+
console.error('Error parsing tool memory response', error);
|
|
11
|
+
}
|
|
12
|
+
return {};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default extractToolMemoryResponse;
|