@minded-ai/mindedjs 1.0.31 → 1.0.33
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/internalTools/appActionRunnerTool.d.ts +7 -0
- package/dist/internalTools/appActionRunnerTool.d.ts.map +1 -0
- package/dist/internalTools/appActionRunnerTool.js +49 -0
- package/dist/internalTools/appActionRunnerTool.js.map +1 -0
- package/dist/internalTools/utils.d.ts +2 -0
- package/dist/internalTools/utils.d.ts.map +1 -0
- package/dist/internalTools/utils.js +8 -0
- package/dist/internalTools/utils.js.map +1 -0
- package/dist/nodes/actionRunnerNode.d.ts +14 -0
- package/dist/nodes/actionRunnerNode.d.ts.map +1 -0
- package/dist/nodes/actionRunnerNode.js +100 -0
- package/dist/nodes/actionRunnerNode.js.map +1 -0
- package/dist/nodes/actionRunnerTool.d.ts +14 -0
- package/dist/nodes/actionRunnerTool.d.ts.map +1 -0
- package/dist/nodes/actionRunnerTool.js +101 -0
- package/dist/nodes/actionRunnerTool.js.map +1 -0
- package/dist/nodes/addAppTool.d.ts +8 -0
- package/dist/nodes/addAppTool.js +12 -0
- package/dist/nodes/addAppTool.js.map +1 -0
- package/dist/nodes/addAppToolNode.d.ts +9 -0
- package/dist/nodes/addAppToolNode.d.ts.map +1 -0
- package/dist/nodes/addAppToolNode.js +62 -0
- package/dist/nodes/addAppToolNode.js.map +1 -0
- package/dist/nodes/addPromptNode.d.ts.map +1 -1
- package/dist/nodes/addPromptNode.js +10 -24
- package/dist/nodes/addPromptNode.js.map +1 -1
- package/dist/nodes/addToolNode.d.ts +2 -2
- package/dist/nodes/addToolNode.d.ts.map +1 -1
- package/dist/nodes/addToolNode.js +24 -70
- package/dist/nodes/addToolNode.js.map +1 -1
- package/dist/nodes/callTool.d.ts +10 -0
- package/dist/nodes/callTool.js +57 -0
- package/dist/nodes/callTool.js.map +1 -0
- package/dist/nodes/nodeFactory.d.ts +2 -2
- package/dist/nodes/nodeFactory.d.ts.map +1 -1
- package/dist/nodes/nodeFactory.js.map +1 -1
- package/dist/nodes/toolNodeRunner.d.ts +15 -0
- package/dist/nodes/toolNodeRunner.js +79 -0
- package/dist/nodes/toolNodeRunner.js.map +1 -0
- package/dist/platform/mindedRequest.js +2 -2
- package/dist/platform/mindedRequest.js.map +1 -1
- package/dist/tools/appToolRunner.d.ts +30 -0
- package/dist/tools/appToolRunner.js +35 -0
- package/dist/tools/appToolRunner.js.map +1 -0
- package/dist/tools/parser.d.ts +14 -0
- package/dist/tools/parser.js +17 -0
- package/dist/tools/parser.js.map +1 -0
- package/dist/tools/triggerTypeToDefaultMessage.d.ts +3 -0
- package/dist/tools/triggerTypeToDefaultMessage.js +10 -0
- package/dist/tools/triggerTypeToDefaultMessage.js.map +1 -0
- package/package.json +2 -2
- package/src/nodes/addPromptNode.ts +13 -26
- package/src/nodes/addToolNode.ts +27 -84
- package/src/nodes/nodeFactory.ts +2 -1
- package/dist/types/Triggers.types.d.ts +0 -1
- package/dist/types/Triggers.types.js +0 -3
- package/dist/types/Triggers.types.js.map +0 -1
package/src/nodes/addToolNode.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { BaseLanguageModel } from '@langchain/core/language_models/base';
|
|
2
1
|
import { ToolNode } from '../types/Flows.types';
|
|
3
2
|
import { Tool } from '../types/Tools.types';
|
|
4
3
|
import { tool as langchainTool } from '@langchain/core/tools';
|
|
5
4
|
import { PreCompiledGraph, stateAnnotation } from '../types/LangGraph.types';
|
|
6
|
-
import {
|
|
7
|
-
import { createReactAgent } from '@langchain/langgraph/prebuilt';
|
|
5
|
+
import { SystemMessage, ToolMessage } from '@langchain/core/messages';
|
|
8
6
|
import { RunnableLike } from '@langchain/core/runnables';
|
|
9
7
|
import { z } from 'zod';
|
|
10
|
-
import {
|
|
11
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
8
|
+
import { LLMProviders } from '../types/LLM.types';
|
|
12
9
|
|
|
13
10
|
export const addToolNode = async <Memory>({
|
|
14
11
|
graph,
|
|
@@ -19,7 +16,7 @@ export const addToolNode = async <Memory>({
|
|
|
19
16
|
graph: PreCompiledGraph;
|
|
20
17
|
node: ToolNode;
|
|
21
18
|
tools: Tool<any, any>[];
|
|
22
|
-
llm:
|
|
19
|
+
llm: typeof LLMProviders[keyof typeof LLMProviders];
|
|
23
20
|
}) => {
|
|
24
21
|
const toolNode = node as ToolNode;
|
|
25
22
|
const matchedTool = tools.find((tool) => tool.name === toolNode.toolName);
|
|
@@ -27,90 +24,36 @@ export const addToolNode = async <Memory>({
|
|
|
27
24
|
throw new Error(`Tool not found: ${toolNode.toolName}`);
|
|
28
25
|
}
|
|
29
26
|
const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
|
|
30
|
-
|
|
31
|
-
console.log(`Executing tool node ${toolNode.name}`);
|
|
27
|
+
console.log(`Executing tool node ${toolNode.name}`);
|
|
32
28
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
let toolResponseMessage;
|
|
50
|
-
let attempts = 0;
|
|
51
|
-
const maxAttempts = 3;
|
|
52
|
-
|
|
53
|
-
while ((!toolCallMessage || !toolResponseMessage) && attempts < maxAttempts) {
|
|
54
|
-
const prompt = `
|
|
55
|
-
Context:
|
|
56
|
-
messages: ${JSON.stringify(state.messages)}
|
|
29
|
+
const executeWrapper = async (input: z.infer<typeof matchedTool.input>) => {
|
|
30
|
+
try {
|
|
31
|
+
const response = await matchedTool.execute({ input, memory: state.memory, triggerInvocations: state.triggerInvocations });
|
|
32
|
+
return response || {};
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error('Error executing tool', error);
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const tool = langchainTool(executeWrapper, {
|
|
39
|
+
name: matchedTool.name,
|
|
40
|
+
description: matchedTool.description,
|
|
41
|
+
schema: matchedTool.input,
|
|
42
|
+
});
|
|
43
|
+
const prompt = `
|
|
44
|
+
Additional context:
|
|
57
45
|
workflow memory: ${JSON.stringify(state.memory)}
|
|
58
|
-
Instructions:
|
|
59
|
-
Your ONLY task is to call the tool ${tool.name}(...) using the context above.
|
|
60
|
-
Do not engage in conversation or provide any other responses.
|
|
61
|
-
Just make the tool call immediately.
|
|
62
|
-
You MUST call the tool even if you are uncertain about some parameters - use your best judgment to fill in any missing values.
|
|
63
|
-
${toolNode.prompt ? `Tool parameters guidance: ${toolNode.prompt}` : ''}
|
|
64
|
-
${
|
|
65
|
-
attempts > 0
|
|
66
|
-
? `Previous attempts failed. You MUST make a tool call now with your best guess at the parameters - this is your only job.`
|
|
67
|
-
: ''
|
|
68
|
-
}
|
|
69
46
|
`;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
{ messages: [new SystemMessage(prompt)] },
|
|
78
|
-
{ configurable: { thread_id: uuidv4() } },
|
|
79
|
-
);
|
|
80
|
-
toolCallMessage = getLastToolCallMessage(response.messages);
|
|
81
|
-
toolResponseMessage = getLastToolMessage(response.messages);
|
|
82
|
-
|
|
83
|
-
if (!toolCallMessage || !toolResponseMessage) {
|
|
84
|
-
response.messages.push(new SystemMessage('No tool call was made. Please try again and make sure to call the tool.'));
|
|
85
|
-
attempts++;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (!toolCallMessage || !toolResponseMessage) {
|
|
90
|
-
throw new Error('Failed to get tool call or response after multiple attempts');
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const toolMemory = extractToolMemoryResponse<Memory>(toolResponseMessage);
|
|
94
|
-
return { memory: toolMemory, messages: [toolCallMessage, toolResponseMessage], triggerInvocations: state.triggerInvocations };
|
|
95
|
-
} catch (error) {
|
|
96
|
-
console.error('Error executing tool node', error);
|
|
97
|
-
throw error;
|
|
98
|
-
}
|
|
99
|
-
};
|
|
47
|
+
const AIToolCallMessage = await llm.bindTools([tool], {
|
|
48
|
+
tool_choice: tool.name,
|
|
49
|
+
}).invoke([...state.messages, new SystemMessage(prompt)]);
|
|
50
|
+
const toolCallMessage = await tool.invoke(AIToolCallMessage.tool_calls[0])
|
|
51
|
+
const toolMemory = extractToolMemoryResponse<Memory>(toolCallMessage as ToolMessage);
|
|
52
|
+
return { memory: toolMemory, messages: [AIToolCallMessage, toolCallMessage] };
|
|
53
|
+
}
|
|
100
54
|
graph.addNode(node.name, callback);
|
|
101
55
|
};
|
|
102
56
|
|
|
103
|
-
const getLastToolCallMessage = (messages: BaseMessage[]): BaseMessage => {
|
|
104
|
-
const toolCallMessages = messages.filter((message) => (message as AIMessage).tool_calls?.length || 0 > 0);
|
|
105
|
-
const lastToolCallMessage = toolCallMessages[toolCallMessages.length - 1];
|
|
106
|
-
return lastToolCallMessage;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const getLastToolMessage = (messages: BaseMessage[]): ToolMessage => {
|
|
110
|
-
const toolMessages = messages.filter((message) => message.getType() === 'tool');
|
|
111
|
-
const lastToolMessage = toolMessages[toolMessages.length - 1];
|
|
112
|
-
return lastToolMessage as ToolMessage;
|
|
113
|
-
};
|
|
114
57
|
|
|
115
58
|
const extractToolMemoryResponse = <Memory>(toolMessage: ToolMessage): Partial<Memory> => {
|
|
116
59
|
try {
|
package/src/nodes/nodeFactory.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { addPromptNode } from './addPromptNode';
|
|
|
8
8
|
import { AgentEventRequestPayloads } from '../events/AgentEvents';
|
|
9
9
|
import { EmitSignature } from '../types/Agent.types';
|
|
10
10
|
import { addTriggerNode } from './addTriggerNode';
|
|
11
|
+
import { LLMProviders } from '../types/LLM.types';
|
|
11
12
|
|
|
12
13
|
const addJunctionNode = ({ graph, node }: { graph: PreCompiledGraph; node: JunctionNode }) => {
|
|
13
14
|
const callback: RunnableLike = async () => { };
|
|
@@ -39,7 +40,7 @@ export const nodeFactory = ({
|
|
|
39
40
|
graph: PreCompiledGraph;
|
|
40
41
|
node: Node;
|
|
41
42
|
tools: Tool<any, any>[];
|
|
42
|
-
llm:
|
|
43
|
+
llm: typeof LLMProviders[keyof typeof LLMProviders];
|
|
43
44
|
emit: EmitSignature<any, keyof AgentEventRequestPayloads<any>>;
|
|
44
45
|
}) => {
|
|
45
46
|
const nodeType = node.type;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type TriggerBody = any;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Triggers.types.js","sourceRoot":"","sources":["../../src/types/Triggers.types.ts"],"names":[],"mappings":""}
|