@minded-ai/mindedjs 1.0.19 → 1.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.
- package/dist/agent.d.ts +11 -9
- package/dist/agent.js +47 -65
- package/dist/agent.js.map +1 -1
- package/dist/edges/createDirectEdge.d.ts +5 -4
- package/dist/edges/createDirectEdge.js +6 -5
- package/dist/edges/createDirectEdge.js.map +1 -1
- package/dist/edges/createLogicalRouter.d.ts +6 -4
- package/dist/edges/createLogicalRouter.js +6 -4
- package/dist/edges/createLogicalRouter.js.map +1 -1
- package/dist/edges/createPromptRouter.d.ts +5 -5
- package/dist/edges/createPromptRouter.js +10 -8
- package/dist/edges/createPromptRouter.js.map +1 -1
- package/dist/edges/edgeFactory.d.ts +5 -6
- package/dist/edges/edgeFactory.js +19 -55
- package/dist/edges/edgeFactory.js.map +1 -1
- package/dist/events/AgentEvents.d.ts +3 -2
- package/dist/events/AgentEvents.js.map +1 -1
- package/dist/events/index.d.ts +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js.map +1 -1
- package/dist/llm/createLlmInstance.js +0 -3
- package/dist/llm/createLlmInstance.js.map +1 -1
- package/dist/nodes/addPromptNode.d.ts +11 -11
- package/dist/nodes/addPromptNode.js +26 -6
- package/dist/nodes/addPromptNode.js.map +1 -1
- package/dist/nodes/addToolNode.d.ts +3 -3
- package/dist/nodes/addToolNode.js +8 -16
- package/dist/nodes/addToolNode.js.map +1 -1
- package/dist/nodes/addTriggerNode.d.ts +7 -4
- package/dist/nodes/addTriggerNode.js +37 -3
- package/dist/nodes/addTriggerNode.js.map +1 -1
- package/dist/nodes/nodeFactory.d.ts +10 -10
- package/dist/nodes/nodeFactory.js +3 -3
- package/dist/nodes/nodeFactory.js.map +1 -1
- package/dist/platform/analytics.js +2 -2
- package/dist/platform/analytics.js.map +1 -1
- package/dist/platform/mindedCheckpointSaver.d.ts +2 -2
- package/dist/platform/mindedCheckpointSaver.js +8 -8
- package/dist/platform/mindedCheckpointSaver.js.map +1 -1
- package/dist/platform/mindedConnection.d.ts +1 -0
- package/dist/platform/mindedConnection.js +17 -3
- package/dist/platform/mindedConnection.js.map +1 -1
- package/dist/platform/mindedConnectionTypes.d.ts +1 -4
- package/dist/platform/mindedConnectionTypes.js +1 -0
- package/dist/platform/mindedConnectionTypes.js.map +1 -1
- package/dist/platform/mindedRequest.d.ts +1 -1
- package/dist/platform/mindedRequest.js +3 -3
- package/dist/platform/mindedRequest.js.map +1 -1
- package/dist/types/Agent.types.d.ts +0 -6
- package/dist/types/Flows.types.d.ts +20 -21
- package/dist/types/Flows.types.js.map +1 -1
- package/dist/types/LLM.types.d.ts +11 -3
- package/dist/types/LLM.types.js +8 -3
- package/dist/types/LLM.types.js.map +1 -1
- package/dist/types/LangGraph.types.d.ts +8 -7
- package/dist/types/LangGraph.types.js +1 -1
- package/dist/types/LangGraph.types.js.map +1 -1
- package/dist/types/Tools.types.d.ts +1 -2
- package/docs/api-reference/classes/index.Agent.html +2 -2
- package/docs/api-reference/enums/index.EdgeType.html +2 -2
- package/docs/api-reference/enums/index.NodeType.html +2 -2
- package/docs/api-reference/enums/index.TriggerType.html +2 -2
- package/docs/api-reference/enums/index.events.html +2 -2
- package/docs/api-reference/hierarchy.html +1 -1
- package/docs/api-reference/index.html +3 -3
- package/docs/api-reference/interfaces/index.AppToolNode.html +2 -2
- package/docs/api-reference/interfaces/index.AppTriggerNode.html +2 -2
- package/docs/api-reference/interfaces/index.Flow.html +2 -2
- package/docs/api-reference/interfaces/index.JunctionNode.html +2 -2
- package/docs/api-reference/interfaces/index.LogicalConditionEdge.html +2 -2
- package/docs/api-reference/interfaces/index.ManualTriggerNode.html +2 -2
- package/docs/api-reference/interfaces/index.PromptConditionEdge.html +2 -2
- package/docs/api-reference/interfaces/index.PromptNode.html +2 -2
- package/docs/api-reference/interfaces/index.StepForwardEdge.html +2 -2
- package/docs/api-reference/interfaces/index.Tool.html +2 -2
- package/docs/api-reference/interfaces/index.ToolNode.html +2 -2
- package/docs/api-reference/modules/index-1.html +1 -1
- package/docs/api-reference/modules/index.html +1 -1
- package/docs/api-reference/modules.html +1 -1
- package/docs/api-reference/types/index.Edge.html +1 -1
- package/docs/api-reference/types/index.Node.html +1 -1
- package/docs/api-reference/types/index.TriggerNode.html +1 -1
- package/docs/examples/order-refund-flow.md +1 -1
- package/docs/getting-started/installation.md +3 -3
- package/examples/orderRefundAgent/flows/orderRefundFlow.yaml +3 -3
- package/examples/orderRefundAgent/orderRefundAgent.ts +9 -3
- package/package.json +4 -2
- package/src/agent.ts +15 -9
- package/src/checkpointer/checkpointSaverFactory.ts +31 -0
- package/src/edges/createPromptRouter.ts +1 -1
- package/src/platform/mindedCheckpointSaver.ts +75 -18
- package/src/platform/mindedConnection.ts +99 -55
- package/src/platform/mindedConnectionTypes.ts +4 -5
- package/src/platform/mindedRequest.ts +2 -1
- package/test/checkpoint-saver/minded-checkpoint-saver-list.test.ts +138 -0
- package/test/checkpoint-saver/minded-checkpoint-saver.test.ts +99 -0
- package/dist/analytics.d.ts +0 -6
- package/dist/analytics.js +0 -19
- package/dist/analytics.js.map +0 -1
- package/dist/infrastructure.ts/mindedRequest.d.ts +0 -8
- package/dist/infrastructure.ts/mindedRequest.js +0 -22
- package/dist/infrastructure.ts/mindedRequest.js.map +0 -1
- package/dist/nodes/addHumanInTheLoopNode.d.ts +0 -8
- package/dist/nodes/addHumanInTheLoopNode.js +0 -17
- package/dist/nodes/addHumanInTheLoopNode.js.map +0 -1
package/dist/agent.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { Tool } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { Tool } from "./types/Tools.types";
|
|
2
|
+
import { BaseLanguageModel } from "@langchain/core/language_models/base";
|
|
3
|
+
import { MemorySaver } from "@langchain/langgraph";
|
|
4
|
+
import { TriggerBody } from "./types/Triggers.types";
|
|
5
|
+
import { AgentEventRequestPayloads, AgentEventResponsePayloads } from "./events/AgentEvents";
|
|
6
|
+
import { z } from "zod";
|
|
6
7
|
type CreateAgentParams<Memory> = {
|
|
7
8
|
memorySchema: z.ZodSchema;
|
|
8
|
-
|
|
9
|
+
flows: string;
|
|
9
10
|
tools: Tool<any, Memory>[];
|
|
11
|
+
llm: BaseLanguageModel;
|
|
10
12
|
platformToken?: string;
|
|
11
|
-
memorySaver?:
|
|
13
|
+
memorySaver?: MemorySaver;
|
|
12
14
|
};
|
|
13
15
|
export declare class Agent {
|
|
14
16
|
private memorySchema;
|
|
@@ -25,8 +27,8 @@ export declare class Agent {
|
|
|
25
27
|
private validate;
|
|
26
28
|
private initializeGraph;
|
|
27
29
|
private init;
|
|
28
|
-
invoke({ triggerBody, triggerName, sessionId }: {
|
|
29
|
-
triggerBody:
|
|
30
|
+
invoke({ triggerBody, triggerName, sessionId, }: {
|
|
31
|
+
triggerBody: TriggerBody;
|
|
30
32
|
triggerName: string;
|
|
31
33
|
sessionId?: string;
|
|
32
34
|
}): Promise<import("@langchain/langgraph").StateType<import("@langchain/langgraph").StateDefinition>>;
|
package/dist/agent.js
CHANGED
|
@@ -41,84 +41,73 @@ const langgraph_2 = require("@langchain/langgraph");
|
|
|
41
41
|
const nodeFactory_1 = require("./nodes/nodeFactory");
|
|
42
42
|
const LangGraph_types_1 = require("./types/LangGraph.types");
|
|
43
43
|
const edgeFactory_1 = require("./edges/edgeFactory");
|
|
44
|
-
const AgentEvents_1 = require("./events/AgentEvents");
|
|
45
44
|
const mindedConnection_1 = require("./platform/mindedConnection");
|
|
46
45
|
const mindedConnectionTypes_1 = require("./platform/mindedConnectionTypes");
|
|
47
46
|
const fs = __importStar(require("fs"));
|
|
48
47
|
const path = __importStar(require("path"));
|
|
49
48
|
const yaml = __importStar(require("js-yaml"));
|
|
50
|
-
const createLlmInstance_1 = require("./llm/createLlmInstance");
|
|
51
|
-
const dotenv_1 = require("dotenv");
|
|
52
|
-
const path_1 = require("path");
|
|
53
|
-
(0, dotenv_1.config)({ path: (0, path_1.resolve)(__dirname, '../.env') });
|
|
54
49
|
class Agent {
|
|
55
50
|
constructor(params) {
|
|
56
|
-
this.mindedConnection = null;
|
|
57
51
|
// Event handlers storage keyed by event name. Handlers can optionally return a value.
|
|
58
52
|
this.eventHandlers = {};
|
|
59
|
-
const {
|
|
53
|
+
const { flows: flowsDirectory, tools, platformToken, llm, memorySaver, memorySchema, } = params;
|
|
60
54
|
this.memorySchema = memorySchema;
|
|
61
|
-
this.flows = this.loadFlowsFromDirectory(
|
|
55
|
+
this.flows = this.loadFlowsFromDirectory(flowsDirectory);
|
|
62
56
|
this.tools = tools;
|
|
63
57
|
this.platformToken = platformToken;
|
|
64
|
-
this.llm =
|
|
58
|
+
this.llm = llm;
|
|
65
59
|
this.checkpointer = memorySaver || new langgraph_2.MemorySaver();
|
|
66
60
|
this.validate();
|
|
67
61
|
this.compiledGraph = this.initializeGraph();
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
});
|
|
74
|
-
}
|
|
62
|
+
this.mindedConnection = new mindedConnection_1.MindedConnection();
|
|
63
|
+
this.mindedConnection.start();
|
|
64
|
+
this.mindedConnection.on(mindedConnectionTypes_1.MindedConnectionSocketMessageType.OnAppTrigger, (trigger) => {
|
|
65
|
+
console.log('Received trigger:', trigger);
|
|
66
|
+
});
|
|
75
67
|
}
|
|
76
|
-
loadFlowsFromDirectory(
|
|
68
|
+
loadFlowsFromDirectory(flowsDirectory) {
|
|
69
|
+
if (!fs.existsSync(flowsDirectory)) {
|
|
70
|
+
throw new Error(`Flows directory does not exist: ${flowsDirectory}`);
|
|
71
|
+
}
|
|
77
72
|
const flows = [];
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const parsedFlow = yaml.load(fileContent);
|
|
89
|
-
// Validate that the parsed flow has the required structure
|
|
90
|
-
if (!parsedFlow.name || !parsedFlow.nodes || !parsedFlow.edges) {
|
|
91
|
-
throw new Error(`Invalid flow structure in ${file}. Flow must have name, nodes, and edges.`);
|
|
92
|
-
}
|
|
93
|
-
flows.push(parsedFlow);
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
throw new Error(`Failed to parse flow file ${file}: ${error}`);
|
|
73
|
+
const files = fs.readdirSync(flowsDirectory);
|
|
74
|
+
for (const file of files) {
|
|
75
|
+
if (file.endsWith(".yaml") || file.endsWith(".yml")) {
|
|
76
|
+
const filePath = path.join(flowsDirectory, file);
|
|
77
|
+
try {
|
|
78
|
+
const fileContent = fs.readFileSync(filePath, "utf8");
|
|
79
|
+
const parsedFlow = yaml.load(fileContent);
|
|
80
|
+
// Validate that the parsed flow has the required structure
|
|
81
|
+
if (!parsedFlow.name || !parsedFlow.nodes || !parsedFlow.edges) {
|
|
82
|
+
throw new Error(`Invalid flow structure in ${file}. Flow must have name, nodes, and edges.`);
|
|
97
83
|
}
|
|
84
|
+
flows.push(parsedFlow);
|
|
85
|
+
console.log(`Loaded flow: ${parsedFlow.name} from ${file}`);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
throw new Error(`Failed to parse flow file ${file}: ${error}`);
|
|
98
89
|
}
|
|
99
90
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
91
|
+
}
|
|
92
|
+
if (flows.length === 0) {
|
|
93
|
+
throw new Error(`No YAML flow files found in directory: ${flowsDirectory}`);
|
|
103
94
|
}
|
|
104
95
|
return flows;
|
|
105
96
|
}
|
|
106
97
|
validate() {
|
|
107
98
|
if (this.flows.length === 0) {
|
|
108
|
-
throw new Error(
|
|
99
|
+
throw new Error("No flows provided");
|
|
109
100
|
}
|
|
110
101
|
}
|
|
111
102
|
initializeGraph() {
|
|
112
103
|
const nodes = this.flows.flatMap((flow) => flow.nodes);
|
|
113
104
|
const edges = this.flows.flatMap((flow) => flow.edges);
|
|
114
105
|
// Initialize the graph
|
|
115
|
-
const graph = new langgraph_1.StateGraph(LangGraph_types_1.stateAnnotation)
|
|
116
|
-
|
|
117
|
-
|
|
106
|
+
const graph = new langgraph_1.StateGraph(LangGraph_types_1.stateAnnotation)
|
|
107
|
+
.addNode("init", this.init.bind(this))
|
|
108
|
+
.addEdge("__start__", "init");
|
|
109
|
+
// Add nodes
|
|
118
110
|
nodes.forEach((node) => {
|
|
119
|
-
// Add to nodes object
|
|
120
|
-
nodesObject[node.name] = node;
|
|
121
|
-
// Add to graph
|
|
122
111
|
(0, nodeFactory_1.nodeFactory)({
|
|
123
112
|
graph,
|
|
124
113
|
node,
|
|
@@ -128,16 +117,17 @@ class Agent {
|
|
|
128
117
|
});
|
|
129
118
|
});
|
|
130
119
|
// Add edges
|
|
131
|
-
(0, edgeFactory_1.edgeFactory)({ graph, edges,
|
|
120
|
+
(0, edgeFactory_1.edgeFactory)({ graph, edges, llm: this.llm });
|
|
121
|
+
// Add edges to trigger nodes
|
|
132
122
|
nodes.forEach((node) => {
|
|
133
123
|
if (node.type === Flows_types_1.NodeType.TRIGGER) {
|
|
134
|
-
graph.addEdge(
|
|
124
|
+
graph.addEdge("__start__", node.name);
|
|
135
125
|
}
|
|
136
126
|
});
|
|
137
127
|
// Compile the graph
|
|
138
128
|
return graph.compile({ checkpointer: this.checkpointer });
|
|
139
129
|
}
|
|
140
|
-
init() {
|
|
130
|
+
init(state) {
|
|
141
131
|
return {
|
|
142
132
|
messages: [],
|
|
143
133
|
memory: {},
|
|
@@ -145,20 +135,9 @@ class Agent {
|
|
|
145
135
|
interruptedNode: null,
|
|
146
136
|
};
|
|
147
137
|
}
|
|
148
|
-
async invoke({ triggerBody, triggerName, sessionId }) {
|
|
149
|
-
var _a
|
|
138
|
+
async invoke({ triggerBody, triggerName, sessionId, }) {
|
|
139
|
+
var _a;
|
|
150
140
|
const session = sessionId || (0, uuid_1.v4)();
|
|
151
|
-
const results = await this.emit(AgentEvents_1.AgentEvents.TRIGGER_EVENT, {
|
|
152
|
-
triggerName,
|
|
153
|
-
triggerBody,
|
|
154
|
-
});
|
|
155
|
-
const handlerResult = results.find((r) => r !== undefined);
|
|
156
|
-
if (handlerResult === false) {
|
|
157
|
-
console.log(`Disqualified trigger ${triggerName}`);
|
|
158
|
-
throw new Error('Disqualified trigger');
|
|
159
|
-
}
|
|
160
|
-
const memoryUpdate = (handlerResult === null || handlerResult === void 0 ? void 0 : handlerResult.memory) || {};
|
|
161
|
-
const messages = (_a = handlerResult === null || handlerResult === void 0 ? void 0 : handlerResult.messages) !== null && _a !== void 0 ? _a : [];
|
|
162
141
|
console.log(`Invoking trigger ${triggerName} with session ${session}`);
|
|
163
142
|
const config = { configurable: { thread_id: session, recursionLimit: 3 } };
|
|
164
143
|
const triggerNode = this.compiledGraph.builder.nodes[triggerName];
|
|
@@ -166,15 +145,18 @@ class Agent {
|
|
|
166
145
|
throw new Error(`Trigger node not found: ${triggerName}`);
|
|
167
146
|
}
|
|
168
147
|
const state = await this.compiledGraph.getState(config);
|
|
148
|
+
const triggerMetadata = { name: triggerName, triggerBody };
|
|
169
149
|
// Resume interruption
|
|
170
|
-
if ((
|
|
150
|
+
if ((_a = state === null || state === void 0 ? void 0 : state.values) === null || _a === void 0 ? void 0 : _a.next) {
|
|
171
151
|
const res = await this.compiledGraph.invoke(new langgraph_1.Command({
|
|
172
|
-
resume:
|
|
152
|
+
resume: true,
|
|
153
|
+
goto: triggerName,
|
|
154
|
+
update: { triggerMetadata },
|
|
173
155
|
}), config);
|
|
174
156
|
return res;
|
|
175
157
|
}
|
|
176
158
|
else {
|
|
177
|
-
const res = await this.compiledGraph.invoke({
|
|
159
|
+
const res = await this.compiledGraph.invoke({ triggerMetadata, next: triggerName }, config);
|
|
178
160
|
return res;
|
|
179
161
|
}
|
|
180
162
|
}
|
package/dist/agent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAqD;AAErD,+BAAoC;AAEpC,oDAA2D;AAC3D,oDAAmD;AACnD,qDAAkD;AAClD,6DAIiC;AAEjC,qDAAkD;AAOlD,kEAA+D;AAC/D,4EAAqF;AACrF,uCAAyB;AACzB,2CAA6B;AAC7B,8CAAgC;AAYhC,MAAa,KAAK;IAuBhB,YAAY,MAA4D;QAXxE,sFAAsF;QAC9E,kBAAa,GAQjB,EAAE,CAAC;QAGL,MAAM,EACJ,KAAK,EAAE,cAAc,EACrB,KAAK,EACL,aAAa,EACb,GAAG,EACH,WAAW,EACX,YAAY,GACb,GAAG,MAAM,CAAC;QACX,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,sBAAsB,CAAC,cAAc,CAAC,CAAC;QACzD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,YAAY,GAAG,WAAW,IAAI,IAAI,uBAAW,EAAE,CAAC;QACrD,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QAE5C,IAAI,CAAC,gBAAgB,GAAG,IAAI,mCAAgB,EAAE,CAAC;QAC/C,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;QAE9B,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,yDAAiC,CAAC,YAAY,EAAE,CAAC,OAAO,EAAE,EAAE;YACnF,OAAO,CAAC,GAAG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-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Edge } from "../types/Flows.types";
|
|
2
|
+
import { stateAnnotation } from "../types/LangGraph.types";
|
|
3
|
+
export declare const createDirectEdge: <Memory>({ edge }: {
|
|
4
|
+
edge: Edge<Memory>;
|
|
5
|
+
}) => (state: typeof stateAnnotation.State) => Promise<string>;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createDirectEdge = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const langgraph_1 = require("@langchain/langgraph");
|
|
5
|
+
const createDirectEdge = ({ edge }) => {
|
|
6
|
+
return async (state) => {
|
|
7
|
+
if (state.interruptedNode) {
|
|
8
|
+
return langgraph_1.END;
|
|
9
|
+
}
|
|
9
10
|
console.log(`Executing edge ${JSON.stringify(edge)}`);
|
|
10
11
|
return edge.target;
|
|
11
12
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDirectEdge.js","sourceRoot":"","sources":["../../src/edges/createDirectEdge.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"createDirectEdge.js","sourceRoot":"","sources":["../../src/edges/createDirectEdge.ts"],"names":[],"mappings":";;;AAEA,oDAA2C;AACpC,MAAM,gBAAgB,GAAG,CAAS,EAAE,IAAI,EAA0B,EAAE,EAAE;IAC3E,OAAO,KAAK,EAAE,KAAmC,EAAE,EAAE;QACnD,IAAI,KAAK,CAAC,eAAe,EAAE,CAAC;YAC1B,OAAO,eAAG,CAAC;QACb,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACtD,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC,CAAA;AACH,CAAC,CAAA;AARY,QAAA,gBAAgB,oBAQ5B"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { BaseLanguageModel } from "@langchain/core/language_models/base";
|
|
2
|
+
import { LogicalConditionEdge } from "../types/Flows.types";
|
|
3
|
+
import { stateAnnotation } from "../types/LangGraph.types";
|
|
4
|
+
export declare const createLogicalRouter: <Memory>({ edges, llm }: {
|
|
5
|
+
edges: LogicalConditionEdge<Memory>[];
|
|
6
|
+
llm: BaseLanguageModel;
|
|
5
7
|
}) => (state: typeof stateAnnotation.State) => Promise<string>;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createLogicalRouter = void 0;
|
|
4
|
-
const
|
|
4
|
+
const langgraph_1 = require("@langchain/langgraph");
|
|
5
|
+
const createLogicalRouter = ({ edges, llm }) => {
|
|
5
6
|
return async (state) => {
|
|
7
|
+
if (state.interruptedNode) {
|
|
8
|
+
return langgraph_1.END;
|
|
9
|
+
}
|
|
6
10
|
console.log(`Executing logical router. Edges: ${JSON.stringify(edges)}`);
|
|
7
11
|
for (const edge of edges) {
|
|
8
|
-
|
|
9
|
-
const result = await conditionFn({ memory: state.memory });
|
|
10
|
-
if (result) {
|
|
12
|
+
if (await edge.condition({ memory: state.memory })) {
|
|
11
13
|
return edge.target;
|
|
12
14
|
}
|
|
13
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLogicalRouter.js","sourceRoot":"","sources":["../../src/edges/createLogicalRouter.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"createLogicalRouter.js","sourceRoot":"","sources":["../../src/edges/createLogicalRouter.ts"],"names":[],"mappings":";;;AAEA,oDAA2C;AAGpC,MAAM,mBAAmB,GAAG,CAAS,EAAE,KAAK,EAAE,GAAG,EAAqE,EAAE,EAAE;IAC/H,OAAO,KAAK,EAAE,KAAmC,EAAE,EAAE;QACnD,IAAI,KAAK,CAAC,eAAe,EAAE,CAAC;YAC1B,OAAO,eAAG,CAAC;QACb,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,oCAAoC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACzE,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,MAAM,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC;gBACnD,OAAO,IAAI,CAAC,MAAM,CAAC;YACrB,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACzB,CAAC,CAAA;AACH,CAAC,CAAA;AAbY,QAAA,mBAAmB,uBAa/B"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { PromptConditionEdge } from
|
|
2
|
-
import { BaseLanguageModel } from
|
|
3
|
-
import { stateAnnotation } from
|
|
4
|
-
export declare const createPromptRouter: ({ edges, llm }: {
|
|
5
|
-
edges: PromptConditionEdge[];
|
|
1
|
+
import { PromptConditionEdge } from "../types/Flows.types";
|
|
2
|
+
import { BaseLanguageModel } from "@langchain/core/language_models/base";
|
|
3
|
+
import { stateAnnotation } from "../types/LangGraph.types";
|
|
4
|
+
export declare const createPromptRouter: <Memory>({ edges, llm, }: {
|
|
5
|
+
edges: PromptConditionEdge<Memory>[];
|
|
6
6
|
llm: BaseLanguageModel;
|
|
7
7
|
}) => (state: typeof stateAnnotation.State) => Promise<string>;
|
|
@@ -4,7 +4,8 @@ exports.createPromptRouter = void 0;
|
|
|
4
4
|
const prebuilt_1 = require("@langchain/langgraph/prebuilt");
|
|
5
5
|
const zod_1 = require("zod");
|
|
6
6
|
const messages_1 = require("@langchain/core/messages");
|
|
7
|
-
const
|
|
7
|
+
const langgraph_1 = require("@langchain/langgraph");
|
|
8
|
+
const createPromptRouter = ({ edges, llm, }) => {
|
|
8
9
|
const agent = (0, prebuilt_1.createReactAgent)({
|
|
9
10
|
llm,
|
|
10
11
|
tools: [],
|
|
@@ -14,17 +15,19 @@ const createPromptRouter = ({ edges, llm }) => {
|
|
|
14
15
|
}),
|
|
15
16
|
});
|
|
16
17
|
return async (state) => {
|
|
18
|
+
if (state.interruptedNode) {
|
|
19
|
+
return langgraph_1.END;
|
|
20
|
+
}
|
|
17
21
|
console.log(`Executing prompt router. Edges: ${JSON.stringify(edges)}`);
|
|
18
22
|
const result = await agent.invoke({
|
|
19
23
|
messages: [
|
|
20
24
|
new messages_1.AIMessage({
|
|
21
25
|
content: `You are a router that decides which node to take in a flow based on the current memory state, history and available node ids.
|
|
22
26
|
|
|
23
|
-
Your task is to analyze the current memory state, history and available nodes and determine the most appropriate next node in the flow
|
|
24
|
-
|
|
27
|
+
Your task is to analyze the current memory state, history and available nodes and determine the most appropriate next node in the flow. If none of the available nodes is appropriate, stay on the current node with id ${edges[0].source}
|
|
25
28
|
|
|
26
|
-
Available nodes
|
|
27
|
-
${edges.map((edge) => `- ${edge.target}: ${edge.prompt}`).join(
|
|
29
|
+
Available nodes:
|
|
30
|
+
${edges.map((edge) => `- ${edge.target}: ${edge.prompt}`).join("\n")}
|
|
28
31
|
|
|
29
32
|
Current memory state:
|
|
30
33
|
${JSON.stringify(state.memory)}
|
|
@@ -39,14 +42,13 @@ Based on the memory state and available nodes, determine the most appropriate ne
|
|
|
39
42
|
});
|
|
40
43
|
try {
|
|
41
44
|
const nextNode = result.structuredResponse.nextNodeId;
|
|
42
|
-
console.log(`Next node: ${nextNode}`);
|
|
43
45
|
if (!nextNode) {
|
|
44
|
-
throw new Error(
|
|
46
|
+
throw new Error("No next node id returned from router");
|
|
45
47
|
}
|
|
46
48
|
return nextNode;
|
|
47
49
|
}
|
|
48
50
|
catch (e) {
|
|
49
|
-
throw new Error(`Failed to parse router response: ${result.structuredResponse}
|
|
51
|
+
throw new Error(`Failed to parse router response: ${result.structuredResponse}`);
|
|
50
52
|
}
|
|
51
53
|
};
|
|
52
54
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPromptRouter.js","sourceRoot":"","sources":["../../src/edges/createPromptRouter.ts"],"names":[],"mappings":";;;AAAA,4DAAiE;AACjE,6BAAwB;AAGxB,
|
|
1
|
+
{"version":3,"file":"createPromptRouter.js","sourceRoot":"","sources":["../../src/edges/createPromptRouter.ts"],"names":[],"mappings":";;;AAAA,4DAAiE;AACjE,6BAAwB;AAGxB,uDAAkE;AAClE,oDAA2C;AAGpC,MAAM,kBAAkB,GAAG,CAAS,EACzC,KAAK,EACL,GAAG,GAIJ,EAAE,EAAE;IACH,MAAM,KAAK,GAAG,IAAA,2BAAgB,EAAC;QAC7B,GAAG;QACH,KAAK,EAAE,EAAE;QACT,cAAc,EAAE,OAAC,CAAC,MAAM,CAAC;YACvB,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE;YACtB,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE;SACtB,CAAC;KACH,CAAC,CAAC;IACH,OAAO,KAAK,EAAE,KAAmC,EAAE,EAAE;QACnD,IAAI,KAAK,CAAC,eAAe,EAAE,CAAC;YAC1B,OAAO,eAAG,CAAC;QACb,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,mCAAmC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACxE,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC;YAChC,QAAQ,EAAE;gBACR,IAAI,oBAAS,CAAC;oBACZ,OAAO,EAAE;;0NAGP,KAAK,CAAC,CAAC,CAAC,CAAC,MACX;;;EAGR,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;;EAGlE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC;;;EAG5B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC;;;OAGzB;iBACE,CAAC;aACH;SACF,CAAC,CAAC;QACH,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,CAAC,kBAAkB,CAAC,UAAU,CAAC;YACtD,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;YAC1D,CAAC;YACD,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CACb,oCAAoC,MAAM,CAAC,kBAAkB,EAAE,CAChE,CAAC;QACJ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AAvDW,QAAA,kBAAkB,sBAuD7B"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { Edge
|
|
2
|
-
import { PreCompiledGraph } from
|
|
3
|
-
import { BaseLanguageModel } from
|
|
4
|
-
export declare const edgeFactory: ({ graph, edges,
|
|
1
|
+
import { Edge } from "../types/Flows.types";
|
|
2
|
+
import { PreCompiledGraph } from "../types/LangGraph.types";
|
|
3
|
+
import { BaseLanguageModel } from "@langchain/core/language_models/base";
|
|
4
|
+
export declare const edgeFactory: <Memory>({ graph, edges, llm }: {
|
|
5
5
|
graph: PreCompiledGraph;
|
|
6
|
-
edges: Edge[];
|
|
7
|
-
nodes: Record<string, Node>;
|
|
6
|
+
edges: Edge<Memory>[];
|
|
8
7
|
llm: BaseLanguageModel;
|
|
9
8
|
}) => void;
|
|
@@ -5,61 +5,25 @@ const Flows_types_1 = require("../types/Flows.types");
|
|
|
5
5
|
const createPromptRouter_1 = require("./createPromptRouter");
|
|
6
6
|
const createLogicalRouter_1 = require("./createLogicalRouter");
|
|
7
7
|
const createDirectEdge_1 = require("./createDirectEdge");
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if ((_b = nodes[source]) === null || _b === void 0 ? void 0 : _b.canStayOnNode) {
|
|
28
|
-
const stayEdge = {
|
|
29
|
-
source,
|
|
30
|
-
target: source,
|
|
31
|
-
type: Flows_types_1.EdgeType.PROMPT_CONDITION,
|
|
32
|
-
prompt: 'stay at current node if still relevant',
|
|
33
|
-
};
|
|
34
|
-
edgesForSource.push(stayEdge);
|
|
35
|
-
}
|
|
36
|
-
graph.addConditionalEdges(effectiveSource, router({ edges: edgesForSource, llm }));
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
// Direct edges - simple and straightforward
|
|
40
|
-
const directEdges = edges.filter((edge) => edge.type === Flows_types_1.EdgeType.STEP_FORWARD);
|
|
41
|
-
if (directEdges.length > 0) {
|
|
42
|
-
processEdges({
|
|
43
|
-
edges: directEdges,
|
|
44
|
-
router: createDirectEdge_1.createDirectEdge,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
// Prompt condition edges - enhanced with AI-driven routing
|
|
48
|
-
const promptEdges = edges.filter((edge) => edge.type === Flows_types_1.EdgeType.PROMPT_CONDITION);
|
|
49
|
-
if (promptEdges.length > 0) {
|
|
50
|
-
processEdges({
|
|
51
|
-
edges: promptEdges,
|
|
52
|
-
router: createPromptRouter_1.createPromptRouter,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
// Logical condition edges - enhanced with programmatic routing
|
|
56
|
-
const logicalEdges = edges.filter((edge) => edge.type === Flows_types_1.EdgeType.LOGICAL_CONDITION);
|
|
57
|
-
if (logicalEdges.length > 0) {
|
|
58
|
-
processEdges({
|
|
59
|
-
edges: logicalEdges,
|
|
60
|
-
router: createLogicalRouter_1.createLogicalRouter,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
8
|
+
const edgeFactory = ({ graph, edges, llm }) => {
|
|
9
|
+
// Direct edges
|
|
10
|
+
edges.filter(edge => edge.type === Flows_types_1.EdgeType.STEP_FORWARD).forEach(edge => {
|
|
11
|
+
graph.addConditionalEdges(edge.source, (0, createDirectEdge_1.createDirectEdge)({ edge }));
|
|
12
|
+
});
|
|
13
|
+
// Prompt condition edges
|
|
14
|
+
const promptEdges = edges.filter(edge => edge.type === Flows_types_1.EdgeType.PROMPT_CONDITION);
|
|
15
|
+
const uniquePromptSources = [...new Set(promptEdges.map(edge => edge.source))];
|
|
16
|
+
uniquePromptSources.forEach(source => {
|
|
17
|
+
const edgesForSource = promptEdges.filter(edge => edge.source === source);
|
|
18
|
+
graph.addConditionalEdges(source, (0, createPromptRouter_1.createPromptRouter)({ edges: edgesForSource, llm }));
|
|
19
|
+
});
|
|
20
|
+
// Logical condition edges
|
|
21
|
+
const logicalEdges = edges.filter(edge => edge.type === Flows_types_1.EdgeType.LOGICAL_CONDITION);
|
|
22
|
+
const uniqueLogicalSources = [...new Set(logicalEdges.map(edge => edge.source))];
|
|
23
|
+
uniqueLogicalSources.forEach(source => {
|
|
24
|
+
const edgesForSource = logicalEdges.filter(edge => edge.source === source);
|
|
25
|
+
graph.addConditionalEdges(source, (0, createLogicalRouter_1.createLogicalRouter)({ edges: edgesForSource, llm }));
|
|
26
|
+
});
|
|
63
27
|
};
|
|
64
28
|
exports.edgeFactory = edgeFactory;
|
|
65
29
|
//# sourceMappingURL=edgeFactory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edgeFactory.js","sourceRoot":"","sources":["../../src/edges/edgeFactory.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"edgeFactory.js","sourceRoot":"","sources":["../../src/edges/edgeFactory.ts"],"names":[],"mappings":";;;AAAA,sDAAsD;AAGtD,6DAA0D;AAC1D,+DAA4D;AAC5D,yDAAsD;AAE/C,MAAM,WAAW,GAAG,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C,CAAC,CAAC,CAAC;IACjF,oBAAoB,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACpC,MAAM,cAAc,GAAG,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC;QAC3E,KAAK,CAAC,mBAAmB,CAAC,MAAa,EAAE,IAAA,yCAAmB,EAAS,EAAE,KAAK,EAAE,cAAc,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;IACxG,CAAC,CAAC,CAAC;AACL,CAAC,CAAA;AArBY,QAAA,WAAW,eAqBvB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { TriggerBody } from "../types/Triggers.types";
|
|
2
|
+
import { BaseMessage } from "@langchain/core/messages";
|
|
2
3
|
export declare enum AgentEvents {
|
|
3
4
|
AI_MESSAGE = "AI_MESSAGE",
|
|
4
5
|
TRIGGER_EVENT = "TRIGGER_EVENT"
|
|
@@ -10,7 +11,7 @@ export type AgentEventRequestPayloads<Memory> = {
|
|
|
10
11
|
};
|
|
11
12
|
[AgentEvents.TRIGGER_EVENT]: {
|
|
12
13
|
triggerName: string;
|
|
13
|
-
triggerBody:
|
|
14
|
+
triggerBody: TriggerBody;
|
|
14
15
|
};
|
|
15
16
|
};
|
|
16
17
|
export type AgentEventResponsePayloads<Memory> = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentEvents.js","sourceRoot":"","sources":["../../src/events/AgentEvents.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"AgentEvents.js","sourceRoot":"","sources":["../../src/events/AgentEvents.ts"],"names":[],"mappings":";;;AAGA,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,wCAAyB,CAAA;IACzB,8CAA+B,CAAA;AACjC,CAAC,EAHW,WAAW,2BAAX,WAAW,QAGtB"}
|
package/dist/events/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AgentEvents } from
|
|
1
|
+
import { AgentEvents } from "./AgentEvents";
|
|
2
2
|
export default AgentEvents;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Agent } from
|
|
2
|
-
import events from
|
|
1
|
+
import { Agent } from "./agent";
|
|
2
|
+
import events from "./events";
|
|
3
3
|
export { Agent, events };
|
|
4
|
-
export type { Flow, Node, Edge, TriggerNode, AppTriggerNode, PromptNode, PromptConditionEdge, LogicalConditionEdge, StepForwardEdge, ManualTriggerNode, JunctionNode, ToolNode, AppToolNode
|
|
4
|
+
export type { Flow, Node, Edge, TriggerNode, AppTriggerNode, PromptNode, PromptConditionEdge, LogicalConditionEdge, StepForwardEdge, ManualTriggerNode, JunctionNode, ToolNode, AppToolNode } from './types/Flows.types';
|
|
5
5
|
export { NodeType, TriggerType, EdgeType } from './types/Flows.types';
|
|
6
6
|
export type { Tool } from './types/Tools.types';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAgC;AAGvB,sFAHA,aAAK,OAGA;AAFd,sDAA8B;AAEd,iBAFT,gBAAM,CAES;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAgC;AAGvB,sFAHA,aAAK,OAGA;AAFd,sDAA8B;AAEd,iBAFT,gBAAM,CAES;AAGtB,mDAAsE;AAA7D,uGAAA,QAAQ,OAAA;AAAE,0GAAA,WAAW,OAAA;AAAE,uGAAA,QAAQ,OAAA"}
|
|
@@ -5,9 +5,6 @@ const LLM_types_1 = require("../types/LLM.types");
|
|
|
5
5
|
const createLlmInstance = (llmConfig) => {
|
|
6
6
|
const { name, properties } = llmConfig;
|
|
7
7
|
const LLMClass = LLM_types_1.LLMProviders[name];
|
|
8
|
-
if (!LLMClass) {
|
|
9
|
-
throw new Error(`Unsupported LLM provider: ${name}`);
|
|
10
|
-
}
|
|
11
8
|
return new LLMClass(properties);
|
|
12
9
|
};
|
|
13
10
|
exports.createLlmInstance = createLlmInstance;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLlmInstance.js","sourceRoot":"","sources":["../../src/llm/createLlmInstance.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"createLlmInstance.js","sourceRoot":"","sources":["../../src/llm/createLlmInstance.ts"],"names":[],"mappings":";;;AAAA,kDAA6D;AAEtD,MAAM,iBAAiB,GAAG,CAAC,SAAoB,EAAE,EAAE;IACxD,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,SAAS,CAAC;IACvC,MAAM,QAAQ,GAAG,wBAAY,CAAC,IAAI,CAAC,CAAC;IACpC,OAAO,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC;AAClC,CAAC,CAAA;AAJY,QAAA,iBAAiB,qBAI7B"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { PromptNode } from
|
|
2
|
-
import { PreCompiledGraph } from
|
|
3
|
-
import { BaseLanguageModel } from
|
|
4
|
-
import { Tool } from
|
|
5
|
-
import { AgentEventRequestPayloads } from
|
|
6
|
-
import { EmitSignature } from
|
|
7
|
-
type AddPromptNodeParams = {
|
|
1
|
+
import { PromptNode } from "../types/Flows.types";
|
|
2
|
+
import { PreCompiledGraph } from "../types/LangGraph.types";
|
|
3
|
+
import { BaseLanguageModel } from "@langchain/core/language_models/base";
|
|
4
|
+
import { Tool } from "../types/Tools.types";
|
|
5
|
+
import { AgentEventRequestPayloads } from "../events/AgentEvents";
|
|
6
|
+
import { EmitSignature } from "../types/Agent.types";
|
|
7
|
+
type AddPromptNodeParams<Memory> = {
|
|
8
8
|
graph: PreCompiledGraph;
|
|
9
|
-
node: PromptNode
|
|
9
|
+
node: PromptNode<Memory>;
|
|
10
10
|
llm: BaseLanguageModel;
|
|
11
|
-
tools: Tool<any,
|
|
12
|
-
emit: EmitSignature<
|
|
11
|
+
tools: Tool<any, Memory>[];
|
|
12
|
+
emit: EmitSignature<Memory, keyof AgentEventRequestPayloads<Memory>>;
|
|
13
13
|
};
|
|
14
|
-
export declare const addPromptNode: ({ graph, node, llm, tools, emit }: AddPromptNodeParams) => Promise<void>;
|
|
14
|
+
export declare const addPromptNode: <Memory>({ graph, node, llm, tools, emit, }: AddPromptNodeParams<Memory>) => Promise<void>;
|
|
15
15
|
export {};
|