@minded-ai/mindedjs 2.0.19 → 2.0.20
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":"addAppToolNode.d.ts","sourceRoot":"","sources":["../../src/nodes/addAppToolNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAY,MAAM,sBAAsB,CAAC;AAE7D,OAAO,EAAE,gBAAgB,EAAmB,MAAM,0BAA0B,CAAC;AAI7E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAGjC,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAK5C,eAAO,MAAM,cAAc,GAAU,qCAMlC;IACD,KAAK,EAAE,gBAAgB,CAAC;IACxB,IAAI,EAAE,WAAW,CAAC;IAClB,GAAG,EAAE,CAAC,OAAO,YAAY,EAAE,MAAM,OAAO,YAAY,CAAC,CAAC;IACtD,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;CACzB,
|
|
1
|
+
{"version":3,"file":"addAppToolNode.d.ts","sourceRoot":"","sources":["../../src/nodes/addAppToolNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAY,MAAM,sBAAsB,CAAC;AAE7D,OAAO,EAAE,gBAAgB,EAAmB,MAAM,0BAA0B,CAAC;AAI7E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAGjC,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAK5C,eAAO,MAAM,cAAc,GAAU,qCAMlC;IACD,KAAK,EAAE,gBAAgB,CAAC;IACxB,IAAI,EAAE,WAAW,CAAC;IAClB,GAAG,EAAE,CAAC,OAAO,YAAY,EAAE,MAAM,OAAO,YAAY,CAAC,CAAC;IACtD,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;CACzB,kBAkGA,CAAC"}
|
|
@@ -10,7 +10,6 @@ const playbooks_1 = require("../playbooks/playbooks");
|
|
|
10
10
|
const compilePrompt_1 = require("./compilePrompt");
|
|
11
11
|
const messages_2 = require("@langchain/core/messages");
|
|
12
12
|
const addAppToolNode = async ({ graph, node, llm, agent, tools, }) => {
|
|
13
|
-
const cleanedParameters = Object.fromEntries(Object.entries(node.parameters || {}).filter(([, value]) => value !== ''));
|
|
14
13
|
// Find the tool from the tools array by name
|
|
15
14
|
const appRunnerTool = tools.find((tool) => tool.name === node.displayName);
|
|
16
15
|
if (!appRunnerTool) {
|
|
@@ -18,6 +17,20 @@ const addAppToolNode = async ({ graph, node, llm, agent, tools, }) => {
|
|
|
18
17
|
}
|
|
19
18
|
const callback = async (state) => {
|
|
20
19
|
logger_1.logger.debug({ msg: `[Node] Executing tool node`, node: appRunnerTool.name });
|
|
20
|
+
// Compile parameters with variable injection support
|
|
21
|
+
const compiledParameters = {};
|
|
22
|
+
const compileContext = { state, memory: state.memory, env: process.env };
|
|
23
|
+
for (const [key, value] of Object.entries(node.parameters || {})) {
|
|
24
|
+
if (value !== '') {
|
|
25
|
+
// If the value is a string, compile it to allow variable injection
|
|
26
|
+
if (typeof value === 'string') {
|
|
27
|
+
compiledParameters[key] = (0, compilePrompt_1.compilePrompt)(value, compileContext);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
compiledParameters[key] = value;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
21
34
|
const executeWrapper = async (input) => {
|
|
22
35
|
try {
|
|
23
36
|
const response = await appRunnerTool.execute({ input, state, agent });
|
|
@@ -34,6 +47,8 @@ const addAppToolNode = async ({ graph, node, llm, agent, tools, }) => {
|
|
|
34
47
|
schema: appRunnerTool.input,
|
|
35
48
|
});
|
|
36
49
|
const combinedPlaybooks = (0, playbooks_1.combinePlaybooks)(agent.playbooks) || '';
|
|
50
|
+
// Compile the prompt if it exists to allow variable injection
|
|
51
|
+
const compiledNodePrompt = node.prompt ? (0, compilePrompt_1.compilePrompt)(node.prompt, compileContext) : null;
|
|
37
52
|
const message = `${combinedPlaybooks ? combinedPlaybooks + '\n\n' : ''}
|
|
38
53
|
Additional context:
|
|
39
54
|
previous messages are available for context.
|
|
@@ -44,9 +59,9 @@ const addAppToolNode = async ({ graph, node, llm, agent, tools, }) => {
|
|
|
44
59
|
- User instructions for choosing tool parameters that are not set by the user (if any)
|
|
45
60
|
- Workflow memory
|
|
46
61
|
Parameters manually configured by the user are:
|
|
47
|
-
${JSON.stringify(
|
|
62
|
+
${JSON.stringify(compiledParameters)}
|
|
48
63
|
User instructions for choosing tool parameters are:
|
|
49
|
-
${
|
|
64
|
+
${compiledNodePrompt ? compiledNodePrompt : 'no instructions set by the user'}`;
|
|
50
65
|
const compiledPrompt = (0, compilePrompt_1.compilePrompt)(message, { state: state, memory: state.memory, env: process.env });
|
|
51
66
|
const systemMessage = new messages_1.SystemMessage(compiledPrompt);
|
|
52
67
|
if (state.messages.length === 0 || state.messages[0].getType() === 'system') {
|
|
@@ -58,7 +73,7 @@ const addAppToolNode = async ({ graph, node, llm, agent, tools, }) => {
|
|
|
58
73
|
const AIToolCallMessage = await llm.bindTools([tool], { tool_choice: tool.name }).invoke(state.messages);
|
|
59
74
|
AIToolCallMessage.tool_calls[0].args = {
|
|
60
75
|
...AIToolCallMessage.tool_calls[0].args,
|
|
61
|
-
...
|
|
76
|
+
...compiledParameters, //user set parameters have priority over ai generated parameters
|
|
62
77
|
};
|
|
63
78
|
const toolCallMessage = await tool.invoke(AIToolCallMessage.tool_calls[0]);
|
|
64
79
|
AIToolCallMessage.additional_kwargs = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addAppToolNode.js","sourceRoot":"","sources":["../../src/nodes/addAppToolNode.ts"],"names":[],"mappings":";;;AAAA,sDAA6D;AAC7D,iDAA8D;AAE9D,uDAAyD;AAMzD,4CAAyC;AACzC,8CAAqD;AAErD,sDAA0D;AAC1D,mDAAgD;AAChD,uDAAuD;AAEhD,MAAM,cAAc,GAAG,KAAK,EAAE,EACnC,KAAK,EACL,IAAI,EACJ,GAAG,EACH,KAAK,EACL,KAAK,GAON,EAAE,EAAE;IACH,MAAM,
|
|
1
|
+
{"version":3,"file":"addAppToolNode.js","sourceRoot":"","sources":["../../src/nodes/addAppToolNode.ts"],"names":[],"mappings":";;;AAAA,sDAA6D;AAC7D,iDAA8D;AAE9D,uDAAyD;AAMzD,4CAAyC;AACzC,8CAAqD;AAErD,sDAA0D;AAC1D,mDAAgD;AAChD,uDAAuD;AAEhD,MAAM,cAAc,GAAG,KAAK,EAAE,EACnC,KAAK,EACL,IAAI,EACJ,GAAG,EACH,KAAK,EACL,KAAK,GAON,EAAE,EAAE;IACH,6CAA6C;IAC7C,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,WAAW,CAAC,CAAC;IAE3E,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,4BAA4B,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,QAAQ,GAAiB,KAAK,EAAE,KAAmC,EAAE,EAAE;QAC3E,eAAM,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,4BAA4B,EAAE,IAAI,EAAE,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;QAE9E,qDAAqD;QACrD,MAAM,kBAAkB,GAAwB,EAAE,CAAC;QACnD,MAAM,cAAc,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAA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M,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3E,iBAAiB,CAAC,iBAAiB,GAAG;YACpC,cAAc,EAAE;gBACd,QAAQ,EAAE,sBAAQ,CAAC,QAAQ;aAC5B;SACF,CAAC;QAEF,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QAClB,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACvC,IAAI,eAAe,YAAY,sBAAW,EAAE,CAAC;YAC3C,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACvC,CAAC;QACD,KAAK,CAAC,OAAO,CAAC,IAAI,CAChB,IAAA,2BAAiB,EAAiC,KAAK,CAAC,OAAO,EAAE;YAC/D,IAAI,EAAE,sBAAQ,CAAC,QAAQ;YACvB,MAAM,EAAE,IAAI,CAAC,IAAI;YACjB,eAAe,EAAE,IAAI,CAAC,WAAY;YAClC,GAAG,EAAE,iBAAiB,CAAC,UAAU,CAAC,CAAC,CAAC;YACpC,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,UAAU,EAAE,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;SACjD,CAAC,CACH,CAAC;QACF,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IACF,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACrC,CAAC,CAAC;AA9GW,QAAA,cAAc,kBA8GzB"}
|
package/package.json
CHANGED
|
@@ -27,8 +27,6 @@ export const addAppToolNode = async ({
|
|
|
27
27
|
agent: Agent;
|
|
28
28
|
tools: Tool<any, any>[];
|
|
29
29
|
}) => {
|
|
30
|
-
const cleanedParameters = Object.fromEntries(Object.entries(node.parameters || {}).filter(([, value]) => value !== ''));
|
|
31
|
-
|
|
32
30
|
// Find the tool from the tools array by name
|
|
33
31
|
const appRunnerTool = tools.find((tool) => tool.name === node.displayName);
|
|
34
32
|
|
|
@@ -39,6 +37,21 @@ export const addAppToolNode = async ({
|
|
|
39
37
|
const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
|
|
40
38
|
logger.debug({ msg: `[Node] Executing tool node`, node: appRunnerTool.name });
|
|
41
39
|
|
|
40
|
+
// Compile parameters with variable injection support
|
|
41
|
+
const compiledParameters: Record<string, any> = {};
|
|
42
|
+
const compileContext = { state, memory: state.memory, env: process.env };
|
|
43
|
+
|
|
44
|
+
for (const [key, value] of Object.entries(node.parameters || {})) {
|
|
45
|
+
if (value !== '') {
|
|
46
|
+
// If the value is a string, compile it to allow variable injection
|
|
47
|
+
if (typeof value === 'string') {
|
|
48
|
+
compiledParameters[key] = compilePrompt(value, compileContext);
|
|
49
|
+
} else {
|
|
50
|
+
compiledParameters[key] = value;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
42
55
|
const executeWrapper = async (input: z.infer<typeof appRunnerTool.input>) => {
|
|
43
56
|
try {
|
|
44
57
|
const response = await appRunnerTool.execute({ input, state, agent });
|
|
@@ -56,6 +69,9 @@ export const addAppToolNode = async ({
|
|
|
56
69
|
|
|
57
70
|
const combinedPlaybooks = combinePlaybooks(agent.playbooks) || '';
|
|
58
71
|
|
|
72
|
+
// Compile the prompt if it exists to allow variable injection
|
|
73
|
+
const compiledNodePrompt = node.prompt ? compilePrompt(node.prompt, compileContext) : null;
|
|
74
|
+
|
|
59
75
|
const message = `${combinedPlaybooks ? combinedPlaybooks + '\n\n' : ''}
|
|
60
76
|
Additional context:
|
|
61
77
|
previous messages are available for context.
|
|
@@ -66,9 +82,9 @@ export const addAppToolNode = async ({
|
|
|
66
82
|
- User instructions for choosing tool parameters that are not set by the user (if any)
|
|
67
83
|
- Workflow memory
|
|
68
84
|
Parameters manually configured by the user are:
|
|
69
|
-
${JSON.stringify(
|
|
85
|
+
${JSON.stringify(compiledParameters)}
|
|
70
86
|
User instructions for choosing tool parameters are:
|
|
71
|
-
${
|
|
87
|
+
${compiledNodePrompt ? compiledNodePrompt : 'no instructions set by the user'}`;
|
|
72
88
|
|
|
73
89
|
const compiledPrompt = compilePrompt(message, { state: state, memory: state.memory, env: process.env });
|
|
74
90
|
const systemMessage = new SystemMessage(compiledPrompt);
|
|
@@ -81,7 +97,7 @@ export const addAppToolNode = async ({
|
|
|
81
97
|
const AIToolCallMessage = await llm.bindTools([tool], { tool_choice: tool.name }).invoke(state.messages);
|
|
82
98
|
AIToolCallMessage.tool_calls[0].args = {
|
|
83
99
|
...AIToolCallMessage.tool_calls[0].args,
|
|
84
|
-
...
|
|
100
|
+
...compiledParameters, //user set parameters have priority over ai generated parameters
|
|
85
101
|
};
|
|
86
102
|
const toolCallMessage = await tool.invoke(AIToolCallMessage.tool_calls[0]);
|
|
87
103
|
AIToolCallMessage.additional_kwargs = {
|