@minded-ai/mindedjs 1.0.108 → 1.0.109-beta-1
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 +12 -12
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +37 -13
- package/dist/agent.js.map +1 -1
- package/dist/browserTask/README.md +419 -0
- package/dist/browserTask/browserAgent.py +632 -0
- package/dist/browserTask/captcha_isolated.png +0 -0
- package/dist/browserTask/executeBrowserTask.d.ts +1 -11
- package/dist/browserTask/executeBrowserTask.d.ts.map +1 -1
- package/dist/browserTask/executeBrowserTask.js +67 -170
- package/dist/browserTask/executeBrowserTask.js.map +1 -1
- package/dist/browserTask/executeBrowserTask.ts +79 -0
- package/dist/browserTask/requirements.txt +8 -0
- package/dist/browserTask/setup.sh +144 -0
- package/dist/cli/index.js +103 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/edges/createLogicalRouter.d.ts +3 -1
- package/dist/edges/createLogicalRouter.d.ts.map +1 -1
- package/dist/edges/createLogicalRouter.js +41 -2
- package/dist/edges/createLogicalRouter.js.map +1 -1
- package/dist/edges/edgeFactory.d.ts.map +1 -1
- package/dist/edges/edgeFactory.js +7 -7
- package/dist/edges/edgeFactory.js.map +1 -1
- package/dist/events/AgentEvents.d.ts +19 -1
- package/dist/events/AgentEvents.d.ts.map +1 -1
- package/dist/events/AgentEvents.js +2 -0
- package/dist/events/AgentEvents.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/internalTools/timer.d.ts +3 -3
- package/dist/internalTools/timer.d.ts.map +1 -1
- package/dist/internalTools/timer.js +3 -3
- package/dist/internalTools/timer.js.map +1 -1
- package/dist/nodes/addBrowserTaskNode.d.ts +1 -3
- package/dist/nodes/addBrowserTaskNode.d.ts.map +1 -1
- package/dist/nodes/addBrowserTaskNode.js +54 -186
- package/dist/nodes/addBrowserTaskNode.js.map +1 -1
- package/dist/nodes/nodeFactory.js +1 -1
- package/dist/nodes/nodeFactory.js.map +1 -1
- package/docs/SUMMARY.md +8 -4
- package/docs/low-code-editor/edges.md +4 -0
- package/docs/sdk/debugging.md +342 -0
- package/docs/{platform → sdk}/events.md +168 -1
- package/package.json +12 -5
- package/dist/nodes/addBrowserTaskRunNode.d.ts +0 -13
- package/dist/nodes/addBrowserTaskRunNode.d.ts.map +0 -1
- package/dist/nodes/addBrowserTaskRunNode.js +0 -130
- package/dist/nodes/addBrowserTaskRunNode.js.map +0 -1
- package/src/agent.ts +0 -928
- package/src/browserTask/executeBrowserTask.ts +0 -213
- package/src/checkpointer/checkpointSaverFactory.ts +0 -18
- package/src/cli/index.ts +0 -170
- package/src/cli/lambdaHandlerTemplate.ts +0 -45
- package/src/edges/createDirectEdge.ts +0 -16
- package/src/edges/createLogicalRouter.ts +0 -114
- package/src/edges/createPromptRouter.ts +0 -218
- package/src/edges/edgeFactory.ts +0 -141
- package/src/events/AgentEvents.ts +0 -47
- package/src/events/index.ts +0 -3
- package/src/index.ts +0 -70
- package/src/interfaces/zendesk.ts +0 -157
- package/src/internalTools/appActionRunnerTool.ts +0 -68
- package/src/internalTools/documentExtraction/documentExtraction.ts +0 -809
- package/src/internalTools/documentExtraction/types.ts +0 -59
- package/src/internalTools/libraryActionRunnerTool.ts +0 -63
- package/src/internalTools/retell.ts +0 -28
- package/src/internalTools/sendPlaceholderMessage.ts +0 -27
- package/src/internalTools/timer.ts +0 -137
- package/src/llm/createLlmInstance.ts +0 -33
- package/src/nodes/addAppToolNode.ts +0 -106
- package/src/nodes/addBrowserTaskNode.ts +0 -231
- package/src/nodes/addBrowserTaskRunNode.ts +0 -144
- package/src/nodes/addHumanInTheLoopNode.ts +0 -25
- package/src/nodes/addJumpToNode.ts +0 -25
- package/src/nodes/addJunctionNode.ts +0 -20
- package/src/nodes/addPromptNode.ts +0 -119
- package/src/nodes/addToolNode.ts +0 -72
- package/src/nodes/addToolRunNode.ts +0 -76
- package/src/nodes/addTriggerNode.ts +0 -27
- package/src/nodes/nodeFactory.ts +0 -57
- package/src/platform/config.ts +0 -77
- package/src/platform/mindedCheckpointSaver.ts +0 -146
- package/src/platform/mindedConnection.ts +0 -199
- package/src/platform/mindedConnectionTypes.ts +0 -220
- package/src/platform/models/mindedChatOpenAI.ts +0 -49
- package/src/platform/models/parallelWrapper.ts +0 -141
- package/src/platform/piiGateway/gateway.ts +0 -103
- package/src/platform/piiGateway/index.ts +0 -5
- package/src/platform/piiGateway/types.ts +0 -29
- package/src/platform/utils/parseAttachments.ts +0 -56
- package/src/playbooks/playbooks.ts +0 -209
- package/src/toolsLibrary/index.ts +0 -6
- package/src/toolsLibrary/parseDocument.ts +0 -136
- package/src/triggers/triggerTypeToDefaultMessage.ts +0 -9
- package/src/types/Agent.types.ts +0 -67
- package/src/types/Flows.types.ts +0 -200
- package/src/types/LLM.types.ts +0 -15
- package/src/types/LangGraph.types.ts +0 -53
- package/src/types/Platform.types.ts +0 -1
- package/src/types/Tools.types.ts +0 -31
- package/src/types/Voice.types.ts +0 -4
- package/src/utils/extractStateMemoryResponse.ts +0 -16
- package/src/utils/history.ts +0 -9
- package/src/utils/logger.ts +0 -22
- package/src/utils/wait.ts +0 -1
- package/src/voice/elevenLabsUtils.ts +0 -81
- package/src/voice/voiceSession.ts +0 -294
- /package/docs/{platform → sdk}/logging.md +0 -0
- /package/docs/{platform → sdk}/memory.md +0 -0
- /package/docs/{platform → sdk}/parallel-llm.md +0 -0
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { PreCompiledGraph, stateAnnotation } from '../types/LangGraph.types';
|
|
2
|
-
import { RunnableLike } from '@langchain/core/runnables';
|
|
3
|
-
import { internalNodesSuffix, NodeType, BrowserTaskNode } from '../types/Flows.types';
|
|
4
|
-
import { ToolMessage, AIMessage } from '@langchain/core/messages';
|
|
5
|
-
import { Agent } from '../agent';
|
|
6
|
-
import { logger } from '../utils/logger';
|
|
7
|
-
import { createHistoryStep } from '../utils/history';
|
|
8
|
-
import { HistoryStep } from '../types/Agent.types';
|
|
9
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
10
|
-
import { waitForCompletion } from '../browserTask/executeBrowserTask';
|
|
11
|
-
|
|
12
|
-
type AddBrowserTaskRunNodeParams = {
|
|
13
|
-
graph: PreCompiledGraph;
|
|
14
|
-
browserTaskNode: BrowserTaskNode;
|
|
15
|
-
attachedToNodeName: string;
|
|
16
|
-
agent: Agent;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const buildBrowserTaskRunNodeName = (nodeName: string) => `${nodeName}${internalNodesSuffix.BROWSER_TASK_RUN}`;
|
|
20
|
-
|
|
21
|
-
export const addBrowserTaskRunNode = async ({ graph, browserTaskNode, attachedToNodeName }: AddBrowserTaskRunNodeParams) => {
|
|
22
|
-
const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
|
|
23
|
-
logger.info(`Executing browser task run node for ${browserTaskNode.displayName}`);
|
|
24
|
-
|
|
25
|
-
const toolCallObj = state.messages[state.messages.length - 1] as any;
|
|
26
|
-
if (!toolCallObj.tool_calls) {
|
|
27
|
-
throw new Error('Tool call not found');
|
|
28
|
-
}
|
|
29
|
-
const toolCall = toolCallObj.tool_calls[0];
|
|
30
|
-
const { taskId, ...inputParams } = toolCall.args;
|
|
31
|
-
try {
|
|
32
|
-
if (!taskId) {
|
|
33
|
-
throw new Error('Task ID not found in tool call arguments');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Wait for task completion
|
|
37
|
-
const completedTask = await waitForCompletion(taskId);
|
|
38
|
-
logger.debug({ msg: 'Browser task completed', taskId, output: completedTask.output });
|
|
39
|
-
|
|
40
|
-
// Create tool message with the result
|
|
41
|
-
const toolMessage = new ToolMessage({
|
|
42
|
-
id: uuidv4(),
|
|
43
|
-
content: JSON.stringify({
|
|
44
|
-
result: completedTask.output || 'Task completed successfully',
|
|
45
|
-
steps: completedTask.steps || [],
|
|
46
|
-
inputParams: inputParams,
|
|
47
|
-
}),
|
|
48
|
-
name: 'browser-task',
|
|
49
|
-
tool_call_id: toolCall.id,
|
|
50
|
-
status: 'success',
|
|
51
|
-
additional_kwargs: {
|
|
52
|
-
mindedMetadata: {
|
|
53
|
-
nodeType: NodeType.BROWSER_TASK,
|
|
54
|
-
nodeDisplayName: browserTaskNode.displayName,
|
|
55
|
-
taskId,
|
|
56
|
-
steps: completedTask.steps,
|
|
57
|
-
inputParams: inputParams,
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
// Update the AI message with steps using the message reducer pattern
|
|
63
|
-
const updatedAIMessage = new AIMessage({
|
|
64
|
-
id: toolCallObj.id,
|
|
65
|
-
content: toolCallObj.content,
|
|
66
|
-
tool_calls: toolCallObj.tool_calls,
|
|
67
|
-
additional_kwargs: {
|
|
68
|
-
...toolCallObj.additional_kwargs,
|
|
69
|
-
mindedMetadata: {
|
|
70
|
-
...toolCallObj.additional_kwargs?.mindedMetadata,
|
|
71
|
-
nodeDisplayName: browserTaskNode.displayName,
|
|
72
|
-
steps: completedTask.steps,
|
|
73
|
-
status: 'completed',
|
|
74
|
-
},
|
|
75
|
-
update: true, // This triggers the message reducer to update the existing message
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
return {
|
|
80
|
-
messages: [toolMessage, updatedAIMessage],
|
|
81
|
-
history: createHistoryStep<HistoryStep>(state.history, {
|
|
82
|
-
type: NodeType.BROWSER_TASK,
|
|
83
|
-
nodeId: browserTaskNode.name,
|
|
84
|
-
nodeDisplayName: browserTaskNode.displayName,
|
|
85
|
-
raw: completedTask,
|
|
86
|
-
messageIds: [],
|
|
87
|
-
}),
|
|
88
|
-
};
|
|
89
|
-
} catch (error: any) {
|
|
90
|
-
logger.error({ msg: 'Error executing browser task run node', error });
|
|
91
|
-
|
|
92
|
-
const errorToolMessage = new ToolMessage({
|
|
93
|
-
id: uuidv4(),
|
|
94
|
-
content: JSON.stringify({
|
|
95
|
-
error: error instanceof Error ? error.message : error.toString(),
|
|
96
|
-
inputParams: inputParams,
|
|
97
|
-
}),
|
|
98
|
-
status: 'error',
|
|
99
|
-
name: 'browser-task',
|
|
100
|
-
tool_call_id: toolCall.id,
|
|
101
|
-
additional_kwargs: {
|
|
102
|
-
mindedMetadata: {
|
|
103
|
-
nodeType: NodeType.BROWSER_TASK,
|
|
104
|
-
nodeDisplayName: browserTaskNode.displayName,
|
|
105
|
-
taskId,
|
|
106
|
-
error: error.message,
|
|
107
|
-
inputParams: inputParams,
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
// Update the AI message with error status
|
|
113
|
-
const updatedAIMessage = new AIMessage({
|
|
114
|
-
id: toolCallObj.id,
|
|
115
|
-
content: toolCallObj.content,
|
|
116
|
-
tool_calls: toolCallObj.tool_calls,
|
|
117
|
-
additional_kwargs: {
|
|
118
|
-
...toolCallObj.additional_kwargs,
|
|
119
|
-
mindedMetadata: {
|
|
120
|
-
...toolCallObj.additional_kwargs?.mindedMetadata,
|
|
121
|
-
nodeDisplayName: browserTaskNode.displayName,
|
|
122
|
-
status: 'failed',
|
|
123
|
-
error: error.message,
|
|
124
|
-
},
|
|
125
|
-
update: true,
|
|
126
|
-
},
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
return {
|
|
130
|
-
messages: [errorToolMessage, updatedAIMessage],
|
|
131
|
-
history: createHistoryStep<HistoryStep>(state.history, {
|
|
132
|
-
type: NodeType.BROWSER_TASK,
|
|
133
|
-
nodeId: browserTaskNode.name,
|
|
134
|
-
nodeDisplayName: browserTaskNode.displayName,
|
|
135
|
-
raw: error,
|
|
136
|
-
messageIds: [],
|
|
137
|
-
}),
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
graph.addNode(buildBrowserTaskRunNodeName(attachedToNodeName), callback);
|
|
143
|
-
graph.addEdge(attachedToNodeName as any, buildBrowserTaskRunNodeName(attachedToNodeName) as any);
|
|
144
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { interrupt } from '@langchain/langgraph';
|
|
2
|
-
import { PreCompiledGraph, stateAnnotation } from '../types/LangGraph.types';
|
|
3
|
-
import { RunnableLike } from '@langchain/core/runnables';
|
|
4
|
-
import { logger } from '../utils/logger';
|
|
5
|
-
import { internalNodesSuffix } from '../types/Flows.types';
|
|
6
|
-
|
|
7
|
-
type AddHumanInTheLoopNodeParams = {
|
|
8
|
-
graph: PreCompiledGraph;
|
|
9
|
-
attachedToNodeName: string;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export const buildHumanInTheLoopNodeName = (nodeName: string) => `${nodeName}${internalNodesSuffix.HUMAN_IN_THE_LOOP}`;
|
|
13
|
-
|
|
14
|
-
export const addHumanInTheLoopNode = async ({ graph, attachedToNodeName }: AddHumanInTheLoopNodeParams) => {
|
|
15
|
-
const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
|
|
16
|
-
logger.debug({ msg: `[Node] Waiting for human input`, node: attachedToNodeName });
|
|
17
|
-
|
|
18
|
-
if (state.messages[state.messages.length - 1].getType() === 'ai') {
|
|
19
|
-
const value = interrupt('input from human in the loop');
|
|
20
|
-
return value;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
graph.addNode(buildHumanInTheLoopNodeName(attachedToNodeName), callback);
|
|
24
|
-
graph.addEdge(attachedToNodeName as any, buildHumanInTheLoopNodeName(attachedToNodeName) as any);
|
|
25
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { RunnableLike } from '@langchain/core/runnables';
|
|
2
|
-
import { PreCompiledGraph, stateAnnotation } from '../types/LangGraph.types';
|
|
3
|
-
import { JumpToNode, NodeType } from '../types/Flows.types';
|
|
4
|
-
import { logger } from '../utils/logger';
|
|
5
|
-
import { HistoryStep } from '../types/Agent.types';
|
|
6
|
-
import { createHistoryStep } from '../utils/history';
|
|
7
|
-
|
|
8
|
-
export const addJumpToNode = async ({ graph, node }: { graph: PreCompiledGraph; node: JumpToNode }) => {
|
|
9
|
-
const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
|
|
10
|
-
logger.info(`Executing jump node ${node.displayName} – jumping to ${node.targetNodeId}`);
|
|
11
|
-
// No state modifications are necessary; control flow is handled via edges.
|
|
12
|
-
return {
|
|
13
|
-
goto: null,
|
|
14
|
-
history: createHistoryStep<HistoryStep>(state.history, {
|
|
15
|
-
type: NodeType.JUMP_TO_NODE,
|
|
16
|
-
nodeId: node.name,
|
|
17
|
-
nodeDisplayName: node.displayName,
|
|
18
|
-
raw: '',
|
|
19
|
-
}),
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
graph.addNode(node.name, callback);
|
|
24
|
-
graph.addEdge(node.name as any, node.targetNodeId as any);
|
|
25
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { JunctionNode, NodeType } from '../types/Flows.types';
|
|
2
|
-
import { PreCompiledGraph, stateAnnotation } from '../types/LangGraph.types';
|
|
3
|
-
import { RunnableLike } from '@langchain/core/runnables';
|
|
4
|
-
import { createHistoryStep } from '../utils/history';
|
|
5
|
-
import { HistoryStep } from '../types/Agent.types';
|
|
6
|
-
|
|
7
|
-
export const addJunctionNode = ({ graph, node }: { graph: PreCompiledGraph; node: JunctionNode }) => {
|
|
8
|
-
const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
|
|
9
|
-
return {
|
|
10
|
-
goto: null,
|
|
11
|
-
history: createHistoryStep<HistoryStep>(state.history, {
|
|
12
|
-
type: NodeType.JUNCTION,
|
|
13
|
-
nodeId: node.name,
|
|
14
|
-
nodeDisplayName: node.displayName,
|
|
15
|
-
raw: '',
|
|
16
|
-
}),
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
graph.addNode(node.name, callback);
|
|
20
|
-
};
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { RunnableLike } from '@langchain/core/runnables';
|
|
2
|
-
import { NodeType, PromptNode } from '../types/Flows.types';
|
|
3
|
-
import { PreCompiledGraph, stateAnnotation } from '../types/LangGraph.types';
|
|
4
|
-
import { z } from 'zod';
|
|
5
|
-
import { BaseLanguageModel } from '@langchain/core/language_models/base';
|
|
6
|
-
import { SystemMessage, AIMessage, ToolMessage } from '@langchain/core/messages';
|
|
7
|
-
import { Tool } from '../types/Tools.types';
|
|
8
|
-
import { tool as langchainTool } from '@langchain/core/tools';
|
|
9
|
-
import { AgentEventRequestPayloads, AgentEvents } from '../events/AgentEvents';
|
|
10
|
-
import { EmitSignature, HistoryStep } from '../types/Agent.types';
|
|
11
|
-
import { createLlmInstance } from '../llm/createLlmInstance';
|
|
12
|
-
import extractToolStateResponse from '../utils/extractStateMemoryResponse';
|
|
13
|
-
import { Agent } from '../agent';
|
|
14
|
-
import { logger } from '../utils/logger';
|
|
15
|
-
import { compilePlaybooks } from '../playbooks/playbooks';
|
|
16
|
-
import { createHistoryStep } from '../utils/history';
|
|
17
|
-
|
|
18
|
-
type AddPromptNodeParams = {
|
|
19
|
-
graph: PreCompiledGraph;
|
|
20
|
-
node: PromptNode;
|
|
21
|
-
llm: BaseLanguageModel;
|
|
22
|
-
tools: Tool<any, any>[];
|
|
23
|
-
emit: EmitSignature<any, keyof AgentEventRequestPayloads<any>>;
|
|
24
|
-
agent: Agent;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: AddPromptNodeParams) => {
|
|
28
|
-
const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
|
|
29
|
-
logger.debug({ msg: `[Node] Executing prompt node`, node: node.displayName });
|
|
30
|
-
const llmToUse = node.llmConfig ? createLlmInstance(node.llmConfig) : llm;
|
|
31
|
-
|
|
32
|
-
const globalTools = tools
|
|
33
|
-
.filter((tool) => tool.isGlobal)
|
|
34
|
-
.map((tool) =>
|
|
35
|
-
langchainTool((input: z.infer<typeof tool.input>) => tool.execute({ input, state, agent }), {
|
|
36
|
-
name: tool.name,
|
|
37
|
-
description: tool.description,
|
|
38
|
-
schema: tool.input,
|
|
39
|
-
}),
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
// Get compiled playbooks with proper parameters
|
|
43
|
-
const playbookParams = {
|
|
44
|
-
...state.memory, // Spread memory fields at the top level
|
|
45
|
-
};
|
|
46
|
-
const compiledPlaybooks = compilePlaybooks(agent.playbooks, playbookParams) || '';
|
|
47
|
-
|
|
48
|
-
const message = `
|
|
49
|
-
${node.prompt ? `# Task instructions:\n${node.prompt}\n\n` : ''}
|
|
50
|
-
${state.memory ? `# Task context:\n${JSON.stringify(state.memory)}\n\n` : ''}
|
|
51
|
-
${compiledPlaybooks ? `# General guidelines:\n${compiledPlaybooks}\n\n` : ''}
|
|
52
|
-
`;
|
|
53
|
-
|
|
54
|
-
const result: AIMessage = await llmToUse.bindTools(globalTools).invoke([...state.messages, new SystemMessage(message)]);
|
|
55
|
-
|
|
56
|
-
// Check if the result contains tool calls
|
|
57
|
-
if (result.tool_calls && result.tool_calls.length > 0) {
|
|
58
|
-
// Execute the tools
|
|
59
|
-
const toolResults = [];
|
|
60
|
-
let stateUpdates = {};
|
|
61
|
-
|
|
62
|
-
for (const toolCall of result.tool_calls) {
|
|
63
|
-
const matchedTool = globalTools.find((t) => t.name === toolCall.name);
|
|
64
|
-
logger.info({ msg: `[Model] Calling tool`, tool: matchedTool?.name });
|
|
65
|
-
if (matchedTool) {
|
|
66
|
-
try {
|
|
67
|
-
// Invoke the LangChain tool directly
|
|
68
|
-
const toolResult = await matchedTool.invoke(toolCall);
|
|
69
|
-
logger.debug({ msg: `[Tool] Tool result`, tool: matchedTool?.name, result: toolResult });
|
|
70
|
-
const toolStateUpdate = extractToolStateResponse(toolResult);
|
|
71
|
-
// Properly merge memory and other state updates
|
|
72
|
-
stateUpdates = {
|
|
73
|
-
...stateUpdates,
|
|
74
|
-
...toolStateUpdate,
|
|
75
|
-
memory: { ...(stateUpdates as any).memory, ...(toolStateUpdate as any).memory },
|
|
76
|
-
};
|
|
77
|
-
toolResults.push(toolResult);
|
|
78
|
-
} catch (error) {
|
|
79
|
-
logger.error({ msg: `[Tool] Error executing tool`, tool: toolCall.name, error });
|
|
80
|
-
const errorMessage = new ToolMessage({
|
|
81
|
-
content: JSON.stringify({ error: error instanceof Error ? error.message : String(error) }),
|
|
82
|
-
tool_call_id: toolCall.id!,
|
|
83
|
-
});
|
|
84
|
-
toolResults.push(errorMessage);
|
|
85
|
-
}
|
|
86
|
-
} else {
|
|
87
|
-
logger.error({ msg: `[Tool] Model called tool but it was not found`, tool: toolCall.name });
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Return the tool call message and tool results with state updates spread at top level
|
|
92
|
-
return {
|
|
93
|
-
...stateUpdates,
|
|
94
|
-
messages: [result, ...toolResults],
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (result.getType() === 'ai') {
|
|
99
|
-
await emit(AgentEvents.AI_MESSAGE, {
|
|
100
|
-
message: result.content as string,
|
|
101
|
-
state,
|
|
102
|
-
});
|
|
103
|
-
logger.info({ msg: `[Model] Response`, content: result.content });
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return {
|
|
107
|
-
goto: null,
|
|
108
|
-
history: createHistoryStep<HistoryStep>(state.history, {
|
|
109
|
-
type: NodeType.PROMPT_NODE,
|
|
110
|
-
nodeId: node.name,
|
|
111
|
-
nodeDisplayName: node.displayName,
|
|
112
|
-
raw: result.content,
|
|
113
|
-
messageIds: [result.id!],
|
|
114
|
-
}),
|
|
115
|
-
messages: [result],
|
|
116
|
-
};
|
|
117
|
-
};
|
|
118
|
-
graph.addNode(node.name, callback);
|
|
119
|
-
};
|
package/src/nodes/addToolNode.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { NodeType, ToolNode } from '../types/Flows.types';
|
|
2
|
-
import { Tool } from '../types/Tools.types';
|
|
3
|
-
import { tool as langchainTool } from '@langchain/core/tools';
|
|
4
|
-
import { PreCompiledGraph, stateAnnotation } from '../types/LangGraph.types';
|
|
5
|
-
import { AIMessage, SystemMessage } from '@langchain/core/messages';
|
|
6
|
-
import { RunnableLike } from '@langchain/core/runnables';
|
|
7
|
-
import { LLMProviders } from '../types/LLM.types';
|
|
8
|
-
import { logger } from '../utils/logger';
|
|
9
|
-
import { Agent } from '../agent';
|
|
10
|
-
import { compilePlaybooks } from '../playbooks/playbooks';
|
|
11
|
-
import { createHistoryStep } from '../utils/history';
|
|
12
|
-
import { HistoryStep } from '../types/Agent.types';
|
|
13
|
-
|
|
14
|
-
export const addToolNode = async ({
|
|
15
|
-
graph,
|
|
16
|
-
node,
|
|
17
|
-
tools,
|
|
18
|
-
llm,
|
|
19
|
-
agent,
|
|
20
|
-
}: {
|
|
21
|
-
graph: PreCompiledGraph;
|
|
22
|
-
node: ToolNode;
|
|
23
|
-
tools: Tool<any, any>[];
|
|
24
|
-
llm: (typeof LLMProviders)[keyof typeof LLMProviders];
|
|
25
|
-
agent: Agent;
|
|
26
|
-
}) => {
|
|
27
|
-
const toolNode = node as ToolNode;
|
|
28
|
-
const matchedTool = tools.find((tool) => tool.name === toolNode.toolName);
|
|
29
|
-
if (!matchedTool) {
|
|
30
|
-
throw new Error(`Tool not found: ${toolNode.toolName} in node ${node.name}`);
|
|
31
|
-
}
|
|
32
|
-
const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
|
|
33
|
-
logger.debug({ msg: `[Node] Executing tool node`, node: toolNode.displayName });
|
|
34
|
-
|
|
35
|
-
const tool = langchainTool(() => {}, {
|
|
36
|
-
name: matchedTool.name,
|
|
37
|
-
description: matchedTool.description,
|
|
38
|
-
schema: matchedTool.input,
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
// Get compiled playbooks with proper parameters
|
|
42
|
-
const playbookParams = {
|
|
43
|
-
...state.memory, // Spread memory fields at the top level
|
|
44
|
-
currentTime: new Date().toISOString(),
|
|
45
|
-
// Add any other common parameters that playbooks might need
|
|
46
|
-
};
|
|
47
|
-
const compiledPlaybooks = compilePlaybooks(agent.playbooks, playbookParams) || '';
|
|
48
|
-
|
|
49
|
-
const prompt = `${compiledPlaybooks ? compiledPlaybooks + '\n\n' : ''}
|
|
50
|
-
Additional context:
|
|
51
|
-
workflow memory: ${JSON.stringify(state.memory)}
|
|
52
|
-
`;
|
|
53
|
-
const AIToolCallMessage: AIMessage = await llm
|
|
54
|
-
.bindTools([tool], {
|
|
55
|
-
tool_choice: tool.name,
|
|
56
|
-
})
|
|
57
|
-
.invoke([...state.messages, new SystemMessage(prompt)]);
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
goto: null,
|
|
61
|
-
messages: [AIToolCallMessage],
|
|
62
|
-
history: createHistoryStep<HistoryStep>(state.history, {
|
|
63
|
-
type: NodeType.TOOL,
|
|
64
|
-
nodeId: node.name,
|
|
65
|
-
nodeDisplayName: node.displayName,
|
|
66
|
-
raw: AIToolCallMessage.tool_calls?.[0] || '',
|
|
67
|
-
messageIds: [AIToolCallMessage.id!],
|
|
68
|
-
}),
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
graph.addNode(node.name, callback);
|
|
72
|
-
};
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { PreCompiledGraph, stateAnnotation } from '../types/LangGraph.types';
|
|
2
|
-
import { RunnableLike } from '@langchain/core/runnables';
|
|
3
|
-
import { Tool } from '../types/Tools.types';
|
|
4
|
-
import { LLMProviders } from '../types/LLM.types';
|
|
5
|
-
import { internalNodesSuffix, NodeType, ToolNode } from '../types/Flows.types';
|
|
6
|
-
import { tool as langchainTool } from '@langchain/core/tools';
|
|
7
|
-
import { ToolMessage } from '@langchain/core/messages';
|
|
8
|
-
import { z } from 'zod';
|
|
9
|
-
import extractToolStateResponse from '../utils/extractStateMemoryResponse';
|
|
10
|
-
import { Agent } from '../agent';
|
|
11
|
-
import { logger } from '../utils/logger';
|
|
12
|
-
import { createHistoryStep } from '../utils/history';
|
|
13
|
-
import { HistoryStep } from '../types/Agent.types';
|
|
14
|
-
|
|
15
|
-
type AddToolRunNodeParams = {
|
|
16
|
-
graph: PreCompiledGraph;
|
|
17
|
-
tools: Tool<any, any>[];
|
|
18
|
-
llm: (typeof LLMProviders)[keyof typeof LLMProviders];
|
|
19
|
-
toolNode: ToolNode;
|
|
20
|
-
attachedToNodeName: string;
|
|
21
|
-
agent: Agent;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const buildToolRunNodeName = (nodeName: string) => `${nodeName}${internalNodesSuffix.TOOL_RUN}`;
|
|
25
|
-
|
|
26
|
-
export const addToolRunNode = async ({ graph, tools, toolNode, attachedToNodeName, agent }: AddToolRunNodeParams) => {
|
|
27
|
-
const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
|
|
28
|
-
const matchedTool = tools.find((tool) => tool.name === toolNode.toolName);
|
|
29
|
-
if (!matchedTool) {
|
|
30
|
-
throw new Error(`Tool not found: ${toolNode.toolName}`);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const executeWrapper = async (input: z.infer<typeof matchedTool.input>) => {
|
|
34
|
-
try {
|
|
35
|
-
const response = await matchedTool.execute({ input, state, agent });
|
|
36
|
-
return response || {};
|
|
37
|
-
} catch (error) {
|
|
38
|
-
logger.error({ msg: '[Tool] Error executing tool', error, node: toolNode.displayName });
|
|
39
|
-
throw error;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
const tool = langchainTool(executeWrapper, {
|
|
43
|
-
name: matchedTool.name,
|
|
44
|
-
description: matchedTool.description,
|
|
45
|
-
schema: matchedTool.input,
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const toolCallObj = state.messages[state.messages.length - 1] as any;
|
|
49
|
-
if (!toolCallObj.tool_calls) {
|
|
50
|
-
throw new Error('Tool call not found');
|
|
51
|
-
}
|
|
52
|
-
const toolCallMessage = await tool.invoke(toolCallObj.tool_calls[0]);
|
|
53
|
-
const toolStateUpdate = extractToolStateResponse(toolCallMessage as ToolMessage);
|
|
54
|
-
|
|
55
|
-
// Push the toolCallMessage into the messages array from toolStateUpdate
|
|
56
|
-
const updatedMessages = [toolCallMessage, ...((toolStateUpdate as any).messages || [])];
|
|
57
|
-
|
|
58
|
-
// Return the full state update from the tool with the updated messages
|
|
59
|
-
|
|
60
|
-
return {
|
|
61
|
-
goto: null,
|
|
62
|
-
...toolStateUpdate,
|
|
63
|
-
messages: updatedMessages,
|
|
64
|
-
history: createHistoryStep<HistoryStep>(state.history, {
|
|
65
|
-
type: NodeType.TOOL,
|
|
66
|
-
nodeId: toolNode.name,
|
|
67
|
-
nodeDisplayName: toolNode.displayName,
|
|
68
|
-
raw: toolCallMessage,
|
|
69
|
-
messageIds: [],
|
|
70
|
-
}),
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
graph.addNode(buildToolRunNodeName(attachedToNodeName), callback);
|
|
75
|
-
graph.addEdge(attachedToNodeName as any, buildToolRunNodeName(attachedToNodeName) as any);
|
|
76
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { RunnableLike } from '@langchain/core/runnables';
|
|
2
|
-
import { NodeType, TriggerNode, TriggerType } from '../types/Flows.types';
|
|
3
|
-
import { PreCompiledGraph, stateAnnotation } from '../types/LangGraph.types';
|
|
4
|
-
import { logger } from '../utils/logger';
|
|
5
|
-
import { HistoryStep } from '../types/Agent.types';
|
|
6
|
-
import { createHistoryStep } from '../utils/history';
|
|
7
|
-
|
|
8
|
-
export const addTriggerNode = async ({ graph, node }: { graph: PreCompiledGraph; node: TriggerNode }) => {
|
|
9
|
-
const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
|
|
10
|
-
logger.debug({ msg: `[Trigger] Executing trigger node`, node: node.displayName });
|
|
11
|
-
if (node.triggerType === TriggerType.MANUAL) {
|
|
12
|
-
return {
|
|
13
|
-
goto: null,
|
|
14
|
-
history: createHistoryStep<HistoryStep>(state.history, {
|
|
15
|
-
type: NodeType.TRIGGER,
|
|
16
|
-
nodeId: node.name,
|
|
17
|
-
nodeDisplayName: node.displayName,
|
|
18
|
-
raw: '',
|
|
19
|
-
messageIds: [],
|
|
20
|
-
}),
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
return {};
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
graph.addNode(node.name, callback);
|
|
27
|
-
};
|
package/src/nodes/nodeFactory.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { Node, NodeType } from '../types/Flows.types';
|
|
2
|
-
import { PreCompiledGraph } from '../types/LangGraph.types';
|
|
3
|
-
import { Tool } from '../types/Tools.types';
|
|
4
|
-
import { addToolNode } from './addToolNode';
|
|
5
|
-
import { addPromptNode } from './addPromptNode';
|
|
6
|
-
import { AgentEventRequestPayloads } from '../events/AgentEvents';
|
|
7
|
-
import { EmitSignature } from '../types/Agent.types';
|
|
8
|
-
import { addAppToolNode } from './addAppToolNode';
|
|
9
|
-
import { addTriggerNode } from './addTriggerNode';
|
|
10
|
-
import { LLMProviders } from '../types/LLM.types';
|
|
11
|
-
import { Agent } from '../agent';
|
|
12
|
-
import { addJumpToNode } from './addJumpToNode';
|
|
13
|
-
import { addJunctionNode } from './addJunctionNode';
|
|
14
|
-
import { addBrowserTaskNode } from './addBrowserTaskNode';
|
|
15
|
-
|
|
16
|
-
export const nodeFactory = ({
|
|
17
|
-
graph,
|
|
18
|
-
node,
|
|
19
|
-
tools,
|
|
20
|
-
llm,
|
|
21
|
-
emit,
|
|
22
|
-
agent,
|
|
23
|
-
}: {
|
|
24
|
-
graph: PreCompiledGraph;
|
|
25
|
-
node: Node;
|
|
26
|
-
tools: Tool<any, any>[];
|
|
27
|
-
llm: (typeof LLMProviders)[keyof typeof LLMProviders];
|
|
28
|
-
emit: EmitSignature<any, keyof AgentEventRequestPayloads<any>>;
|
|
29
|
-
agent: Agent;
|
|
30
|
-
}) => {
|
|
31
|
-
const nodeType = node.type;
|
|
32
|
-
switch (nodeType) {
|
|
33
|
-
case NodeType.TRIGGER:
|
|
34
|
-
addTriggerNode({ graph, node });
|
|
35
|
-
break;
|
|
36
|
-
case NodeType.TOOL:
|
|
37
|
-
addToolNode({ graph, node, tools, llm, agent });
|
|
38
|
-
break;
|
|
39
|
-
case NodeType.JUNCTION:
|
|
40
|
-
addJunctionNode({ graph, node });
|
|
41
|
-
break;
|
|
42
|
-
case NodeType.APP_TOOL:
|
|
43
|
-
addAppToolNode({ graph, node, llm, agent, tools });
|
|
44
|
-
break;
|
|
45
|
-
case NodeType.PROMPT_NODE:
|
|
46
|
-
addPromptNode({ graph, node, tools, llm, emit, agent });
|
|
47
|
-
break;
|
|
48
|
-
case NodeType.JUMP_TO_NODE:
|
|
49
|
-
addJumpToNode({ graph, node });
|
|
50
|
-
break;
|
|
51
|
-
case NodeType.BROWSER_TASK:
|
|
52
|
-
addBrowserTaskNode({ graph, node, agent, llm });
|
|
53
|
-
break;
|
|
54
|
-
default:
|
|
55
|
-
throw new Error(`Unsupported node type: ${nodeType}`);
|
|
56
|
-
}
|
|
57
|
-
};
|
package/src/platform/config.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { resolve } from 'path';
|
|
2
|
-
import { config } from 'dotenv';
|
|
3
|
-
import { Environment } from '../types/Platform.types';
|
|
4
|
-
const path = resolve(__dirname, '../../.env');
|
|
5
|
-
config({ path });
|
|
6
|
-
|
|
7
|
-
type MindedConfig = {
|
|
8
|
-
baseUrl: string;
|
|
9
|
-
env: Environment;
|
|
10
|
-
token: string | null;
|
|
11
|
-
runLocally: boolean;
|
|
12
|
-
isDeployed: boolean;
|
|
13
|
-
dashboardConnected: boolean;
|
|
14
|
-
elevenLabsKey: string | null;
|
|
15
|
-
elevenLabsAgentId: string | null;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const getConfig = (): MindedConfig => {
|
|
19
|
-
const environment = (process.env.NODE_ENV as Environment) || 'sandbox';
|
|
20
|
-
switch (environment) {
|
|
21
|
-
case 'test':
|
|
22
|
-
return {
|
|
23
|
-
baseUrl: 'http://localhost:8888',
|
|
24
|
-
env: 'test',
|
|
25
|
-
token: process.env.MINDED_CONNECTION_TOKEN || '',
|
|
26
|
-
runLocally: process.env.RUN_LOCALLY !== 'false',
|
|
27
|
-
isDeployed: process.env.IS_DEPLOYED_AGENT === 'true',
|
|
28
|
-
dashboardConnected: false,
|
|
29
|
-
elevenLabsKey: process.env.ELEVEN_LABS_API_KEY || null,
|
|
30
|
-
elevenLabsAgentId: process.env.ELEVEN_LABS_AGENT_ID || null,
|
|
31
|
-
};
|
|
32
|
-
case 'development':
|
|
33
|
-
return {
|
|
34
|
-
baseUrl: 'http://localhost:8888',
|
|
35
|
-
env: 'development',
|
|
36
|
-
token: process.env.MINDED_CONNECTION_TOKEN || '',
|
|
37
|
-
runLocally: process.env.RUN_LOCALLY === 'true',
|
|
38
|
-
isDeployed: process.env.IS_DEPLOYED_AGENT === 'true',
|
|
39
|
-
dashboardConnected: true,
|
|
40
|
-
elevenLabsKey: process.env.ELEVEN_LABS_API_KEY || null,
|
|
41
|
-
elevenLabsAgentId: process.env.ELEVEN_LABS_AGENT_ID || 'Iyr6DCOj80AdvVEVHSGt',
|
|
42
|
-
};
|
|
43
|
-
case 'sandbox-staging':
|
|
44
|
-
return {
|
|
45
|
-
baseUrl: 'https://dashboard-api.dev.minded.com',
|
|
46
|
-
env: 'sandbox-staging',
|
|
47
|
-
token: process.env.MINDED_CONNECTION_TOKEN || '',
|
|
48
|
-
runLocally: false,
|
|
49
|
-
isDeployed: process.env.IS_DEPLOYED_AGENT === 'true',
|
|
50
|
-
elevenLabsKey: process.env.ELEVEN_LABS_API_KEY || null,
|
|
51
|
-
dashboardConnected: true,
|
|
52
|
-
elevenLabsAgentId: process.env.ELEVEN_LABS_AGENT_ID || 'agent_01jye194psezr909nwec27m2t9',
|
|
53
|
-
};
|
|
54
|
-
case 'sandbox':
|
|
55
|
-
return {
|
|
56
|
-
baseUrl: 'https://dashboard-api.minded.com',
|
|
57
|
-
env: 'sandbox',
|
|
58
|
-
token: process.env.MINDED_CONNECTION_TOKEN || '',
|
|
59
|
-
runLocally: false,
|
|
60
|
-
isDeployed: process.env.IS_DEPLOYED_AGENT === 'true',
|
|
61
|
-
elevenLabsKey: process.env.ELEVEN_LABS_API_KEY || null,
|
|
62
|
-
dashboardConnected: true,
|
|
63
|
-
elevenLabsAgentId: process.env.ELEVEN_LABS_AGENT_ID || 'agent_01jye194psezr909nwec27m2t9',
|
|
64
|
-
};
|
|
65
|
-
case 'production':
|
|
66
|
-
return {
|
|
67
|
-
baseUrl: 'https://api.minded.com',
|
|
68
|
-
env: 'production',
|
|
69
|
-
token: process.env.MINDED_CONNECTION_TOKEN || '',
|
|
70
|
-
runLocally: false,
|
|
71
|
-
isDeployed: process.env.IS_DEPLOYED_AGENT === 'true',
|
|
72
|
-
elevenLabsKey: process.env.ELEVEN_LABS_API_KEY || null,
|
|
73
|
-
dashboardConnected: false,
|
|
74
|
-
elevenLabsAgentId: process.env.ELEVEN_LABS_AGENT_ID || 'agent_01jye1ajkaf17axpcxg220qwcm',
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
};
|