@minded-ai/mindedjs 1.0.19
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/.github/workflows/CI.yml +34 -0
- package/.prettierrc +8 -0
- package/README.md +6 -0
- package/dist/agent.d.ts +36 -0
- package/dist/agent.js +199 -0
- package/dist/agent.js.map +1 -0
- package/dist/analytics.d.ts +6 -0
- package/dist/analytics.js +19 -0
- package/dist/analytics.js.map +1 -0
- package/dist/edges/createDirectEdge.d.ts +4 -0
- package/dist/edges/createDirectEdge.js +14 -0
- package/dist/edges/createDirectEdge.js.map +1 -0
- package/dist/edges/createLogicalRouter.d.ts +5 -0
- package/dist/edges/createLogicalRouter.js +18 -0
- package/dist/edges/createLogicalRouter.js.map +1 -0
- package/dist/edges/createPromptRouter.d.ts +7 -0
- package/dist/edges/createPromptRouter.js +54 -0
- package/dist/edges/createPromptRouter.js.map +1 -0
- package/dist/edges/edgeFactory.d.ts +9 -0
- package/dist/edges/edgeFactory.js +65 -0
- package/dist/edges/edgeFactory.js.map +1 -0
- package/dist/events/AgentEvents.d.ts +22 -0
- package/dist/events/AgentEvents.js +9 -0
- package/dist/events/AgentEvents.js.map +1 -0
- package/dist/events/index.d.ts +2 -0
- package/dist/events/index.js +5 -0
- package/dist/events/index.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/infrastructure.ts/mindedRequest.d.ts +8 -0
- package/dist/infrastructure.ts/mindedRequest.js +22 -0
- package/dist/infrastructure.ts/mindedRequest.js.map +1 -0
- package/dist/llm/createLlmInstance.d.ts +2 -0
- package/dist/llm/createLlmInstance.js +14 -0
- package/dist/llm/createLlmInstance.js.map +1 -0
- package/dist/nodes/addHumanInTheLoopNode.d.ts +8 -0
- package/dist/nodes/addHumanInTheLoopNode.js +17 -0
- package/dist/nodes/addHumanInTheLoopNode.js.map +1 -0
- package/dist/nodes/addPromptNode.d.ts +15 -0
- package/dist/nodes/addPromptNode.js +52 -0
- package/dist/nodes/addPromptNode.js.map +1 -0
- package/dist/nodes/addToolNode.d.ts +10 -0
- package/dist/nodes/addToolNode.js +82 -0
- package/dist/nodes/addToolNode.js.map +1 -0
- package/dist/nodes/addTriggerNode.d.ts +6 -0
- package/dist/nodes/addTriggerNode.js +12 -0
- package/dist/nodes/addTriggerNode.js.map +1 -0
- package/dist/nodes/nodeFactory.d.ts +13 -0
- package/dist/nodes/nodeFactory.js +41 -0
- package/dist/nodes/nodeFactory.js.map +1 -0
- package/dist/platform/analytics.d.ts +6 -0
- package/dist/platform/analytics.js +19 -0
- package/dist/platform/analytics.js.map +1 -0
- package/dist/platform/mindedCheckpointSaver.d.ts +10 -0
- package/dist/platform/mindedCheckpointSaver.js +49 -0
- package/dist/platform/mindedCheckpointSaver.js.map +1 -0
- package/dist/platform/mindedConnection.d.ts +13 -0
- package/dist/platform/mindedConnection.js +117 -0
- package/dist/platform/mindedConnection.js.map +1 -0
- package/dist/platform/mindedConnectionTypes.d.ts +10 -0
- package/dist/platform/mindedConnectionTypes.js +8 -0
- package/dist/platform/mindedConnectionTypes.js.map +1 -0
- package/dist/platform/mindedRequest.d.ts +8 -0
- package/dist/platform/mindedRequest.js +22 -0
- package/dist/platform/mindedRequest.js.map +1 -0
- package/dist/types/Agent.types.d.ts +8 -0
- package/dist/types/Agent.types.js +3 -0
- package/dist/types/Agent.types.js.map +1 -0
- package/dist/types/Flows.types.d.ts +83 -0
- package/dist/types/Flows.types.js +24 -0
- package/dist/types/Flows.types.js.map +1 -0
- package/dist/types/LLM.types.d.ts +10 -0
- package/dist/types/LLM.types.js +9 -0
- package/dist/types/LLM.types.js.map +1 -0
- package/dist/types/LangGraph.types.d.ts +29 -0
- package/dist/types/LangGraph.types.js +20 -0
- package/dist/types/LangGraph.types.js.map +1 -0
- package/dist/types/Tools.types.d.ts +14 -0
- package/dist/types/Tools.types.js +3 -0
- package/dist/types/Tools.types.js.map +1 -0
- package/dist/types/Triggers.types.d.ts +1 -0
- package/dist/types/Triggers.types.js +3 -0
- package/dist/types/Triggers.types.js.map +1 -0
- package/docs/.gitbook/assets/image.png +0 -0
- package/docs/README.md +51 -0
- package/docs/SUMMARY.md +21 -0
- package/docs/api-reference/.nojekyll +1 -0
- package/docs/api-reference/assets/hierarchy.js +1 -0
- package/docs/api-reference/assets/highlight.css +120 -0
- package/docs/api-reference/assets/icons.js +18 -0
- package/docs/api-reference/assets/icons.svg +1 -0
- package/docs/api-reference/assets/main.js +60 -0
- package/docs/api-reference/assets/navigation.js +1 -0
- package/docs/api-reference/assets/search.js +1 -0
- package/docs/api-reference/assets/style.css +1640 -0
- package/docs/api-reference/classes/index.Agent.html +4 -0
- package/docs/api-reference/enums/index.EdgeType.html +4 -0
- package/docs/api-reference/enums/index.NodeType.html +6 -0
- package/docs/api-reference/enums/index.TriggerType.html +4 -0
- package/docs/api-reference/enums/index.events.html +3 -0
- package/docs/api-reference/hierarchy.html +1 -0
- package/docs/api-reference/index.html +310 -0
- package/docs/api-reference/interfaces/index.AppToolNode.html +5 -0
- package/docs/api-reference/interfaces/index.AppTriggerNode.html +6 -0
- package/docs/api-reference/interfaces/index.Flow.html +4 -0
- package/docs/api-reference/interfaces/index.JunctionNode.html +4 -0
- package/docs/api-reference/interfaces/index.LogicalConditionEdge.html +5 -0
- package/docs/api-reference/interfaces/index.ManualTriggerNode.html +5 -0
- package/docs/api-reference/interfaces/index.PromptConditionEdge.html +5 -0
- package/docs/api-reference/interfaces/index.PromptNode.html +6 -0
- package/docs/api-reference/interfaces/index.StepForwardEdge.html +4 -0
- package/docs/api-reference/interfaces/index.Tool.html +6 -0
- package/docs/api-reference/interfaces/index.ToolNode.html +5 -0
- package/docs/api-reference/modules/index-1.html +1 -0
- package/docs/api-reference/modules/index.html +1 -0
- package/docs/api-reference/modules.html +1 -0
- package/docs/api-reference/types/index.Edge.html +1 -0
- package/docs/api-reference/types/index.Node.html +1 -0
- package/docs/api-reference/types/index.TriggerNode.html +1 -0
- package/docs/core-concepts/edges.md +242 -0
- package/docs/core-concepts/events.md +161 -0
- package/docs/core-concepts/flows.md +74 -0
- package/docs/core-concepts/memory-types.md +208 -0
- package/docs/core-concepts/nodes.md +239 -0
- package/docs/core-concepts/tools.md +205 -0
- package/docs/examples/order-refund-flow.md +560 -0
- package/docs/getting-started/installation.md +34 -0
- package/docs/getting-started/quick-start.md +264 -0
- package/docs-structure.md +144 -0
- package/eslint.config.js +68 -0
- package/examples/orderRefundAgent/flows/orderRefundFlow.yaml +32 -0
- package/examples/orderRefundAgent/minded.json +14 -0
- package/examples/orderRefundAgent/orderRefundAgent.ts +58 -0
- package/examples/orderRefundAgent/schema.ts +7 -0
- package/examples/orderRefundAgent/tools/escalateConversation.ts +28 -0
- package/examples/orderRefundAgent/tools/index.ts +4 -0
- package/examples/orderRefundAgent/tools/refundOrder.ts +27 -0
- package/package.json +46 -0
- package/src/agent.ts +216 -0
- package/src/edges/createDirectEdge.ts +11 -0
- package/src/edges/createLogicalRouter.ts +16 -0
- package/src/edges/createPromptRouter.ts +52 -0
- package/src/edges/edgeFactory.ts +85 -0
- package/src/events/AgentEvents.ts +22 -0
- package/src/events/index.ts +3 -0
- package/src/index.ts +22 -0
- package/src/llm/createLlmInstance.ts +10 -0
- package/src/nodes/addHumanInTheLoopNode.ts +20 -0
- package/src/nodes/addPromptNode.ts +66 -0
- package/src/nodes/addToolNode.ts +95 -0
- package/src/nodes/addTriggerNode.ts +12 -0
- package/src/nodes/nodeFactory.ts +65 -0
- package/src/platform/analytics.ts +16 -0
- package/src/platform/mindedCheckpointSaver.ts +74 -0
- package/src/platform/mindedConnection.ts +106 -0
- package/src/platform/mindedConnectionTypes.ts +15 -0
- package/src/platform/mindedRequest.ts +28 -0
- package/src/types/Agent.types.ts +10 -0
- package/src/types/Flows.types.ts +103 -0
- package/src/types/LLM.types.ts +13 -0
- package/src/types/LangGraph.types.ts +25 -0
- package/src/types/Tools.types.ts +9 -0
- package/test/can-stay-on-node/can-stay-on-node.test.ts +148 -0
- package/test/can-stay-on-node/flows/test-flow.yaml +25 -0
- package/test/cannot-stay-on-node/cannot-stay-on-node.test.ts +201 -0
- package/test/cannot-stay-on-node/flows/test-flow.yaml +34 -0
- package/test/human-in-the-loop-node/flows/test-flow.yaml +23 -0
- package/test/human-in-the-loop-node/human-in-the-loop-node.test.ts +92 -0
- package/test/logical-edges/flows/logical-edge-test-flow.yaml +24 -0
- package/test/logical-edges/logical-edges.test.ts +66 -0
- package/test/no-human-in-the-loop-node/flows/test-flow.yaml +23 -0
- package/test/no-human-in-the-loop-node/no-human-in-the-loop-node.test.ts +80 -0
- package/test/prompt-edges/flows/test-flow.yaml +24 -0
- package/test/prompt-edges/prompt-edges.test.ts +90 -0
- package/test/prompt-node/flows/test-flow.yaml +24 -0
- package/test/prompt-node/prompt-node.test.ts +86 -0
- package/test/setup.ts +5 -0
- package/test/tool-node/flows/test-flow.yaml +14 -0
- package/test/tool-node/tool-node.test.ts +67 -0
- package/test/trigger/flows/test-flow.yaml +7 -0
- package/test/trigger/trigger.test.ts +57 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# Tools
|
|
2
|
+
|
|
3
|
+
Tools are reusable functions that agents can call to perform specific actions like processing payments, sending emails, or updating databases.
|
|
4
|
+
|
|
5
|
+
## Tool Structure
|
|
6
|
+
|
|
7
|
+
Every tool must implement the `Tool` interface:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
interface Tool<Input extends z.ZodSchema, Memory> {
|
|
11
|
+
name: string; // Unique tool identifier
|
|
12
|
+
description: string; // What the tool does (used by LLM)
|
|
13
|
+
input: Input; // Zod schema for input validation
|
|
14
|
+
isGlobal?: boolean; // Optional: available across all nodes
|
|
15
|
+
execute: ({ input, memory }) => Promise<{ memory?, result? }>;
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Basic Tool Example
|
|
20
|
+
|
|
21
|
+
Here's a simple refund processing tool:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { z } from 'zod';
|
|
25
|
+
import { Tool } from 'mindedjs/src/types/Tools.types';
|
|
26
|
+
import memorySchema from '../schema';
|
|
27
|
+
|
|
28
|
+
type Memory = z.infer<typeof memorySchema>;
|
|
29
|
+
|
|
30
|
+
const schema = z.object({
|
|
31
|
+
orderId: z.string(),
|
|
32
|
+
customerName: z.string(),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const refundOrderTool: Tool<typeof schema, Memory> = {
|
|
36
|
+
name: 'refundOrder',
|
|
37
|
+
description: 'Process a customer refund for their order',
|
|
38
|
+
input: schema,
|
|
39
|
+
execute: async ({ input, memory }) => {
|
|
40
|
+
// Your business logic here
|
|
41
|
+
console.log(`Processing refund for order ${input.orderId}`);
|
|
42
|
+
|
|
43
|
+
// Call external API, update database, etc.
|
|
44
|
+
const refundAmount = await processRefundInSystem(input.orderId);
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
memory: {
|
|
48
|
+
orderId: input.orderId,
|
|
49
|
+
customerName: input.customerName,
|
|
50
|
+
issue: `Refund processed: $${refundAmount}`,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export default refundOrderTool;
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Tool Registration
|
|
60
|
+
|
|
61
|
+
### Global Tools
|
|
62
|
+
|
|
63
|
+
Mark tools as global if you want them to be available in all LLM calls.
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
const auditLogTool: Tool<typeof auditSchema, Memory> = {
|
|
67
|
+
name: 'auditLog',
|
|
68
|
+
description: 'Log user action for compliance',
|
|
69
|
+
isGlobal: true, // Available in all flows
|
|
70
|
+
input: z.object({
|
|
71
|
+
action: z.string(),
|
|
72
|
+
details: z.string(),
|
|
73
|
+
}),
|
|
74
|
+
execute: async ({ input, memory }) => {
|
|
75
|
+
await auditService.log({
|
|
76
|
+
userId: memory.userId,
|
|
77
|
+
action: input.action,
|
|
78
|
+
details: input.details,
|
|
79
|
+
timestamp: new Date(),
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Memory Management
|
|
86
|
+
|
|
87
|
+
Tools can read and update memory state:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
const updateProfileTool: Tool<typeof profileSchema, Memory> = {
|
|
91
|
+
name: 'updateProfile',
|
|
92
|
+
description: 'Update customer profile information',
|
|
93
|
+
input: z.object({
|
|
94
|
+
field: z.string(),
|
|
95
|
+
value: z.string(),
|
|
96
|
+
}),
|
|
97
|
+
execute: async ({ input, memory }) => {
|
|
98
|
+
// Read current memory
|
|
99
|
+
console.log(`Current customer: ${memory.customerName}`);
|
|
100
|
+
|
|
101
|
+
// Update external system
|
|
102
|
+
await profileService.update(memory.customerId, {
|
|
103
|
+
[input.field]: input.value
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// Return updated memory
|
|
107
|
+
return {
|
|
108
|
+
memory: {
|
|
109
|
+
...memory,
|
|
110
|
+
[`${input.field}Updated`]: true,
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Error Handling
|
|
118
|
+
|
|
119
|
+
Handle errors gracefully in tools:
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
const paymentTool: Tool<typeof paymentSchema, Memory> = {
|
|
123
|
+
name: 'processPayment',
|
|
124
|
+
description: 'Process customer payment',
|
|
125
|
+
input: z.object({
|
|
126
|
+
amount: z.number(),
|
|
127
|
+
cardToken: z.string(),
|
|
128
|
+
}),
|
|
129
|
+
execute: async ({ input, memory }) => {
|
|
130
|
+
try {
|
|
131
|
+
const result = await paymentService.charge({
|
|
132
|
+
amount: input.amount,
|
|
133
|
+
cardToken: input.cardToken,
|
|
134
|
+
customerId: memory.customerId,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
result: `Payment successful: ${result.transactionId}`,
|
|
139
|
+
memory: { lastPaymentId: result.transactionId },
|
|
140
|
+
};
|
|
141
|
+
} catch (error) {
|
|
142
|
+
console.error('Payment failed:', error);
|
|
143
|
+
return {
|
|
144
|
+
result: 'Payment failed. Please try again or contact support.',
|
|
145
|
+
memory: { paymentError: error.message },
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Best Practices
|
|
153
|
+
|
|
154
|
+
1. **Clear Descriptions**: Write descriptions that help the LLM understand when to use the tool
|
|
155
|
+
2. **Input Validation**: Use Zod schemas to validate all inputs
|
|
156
|
+
3. **Memory Updates**: Update memory with relevant information for future tool calls
|
|
157
|
+
4. **Error Handling**: Always handle errors gracefully and provide meaningful messages
|
|
158
|
+
5. **Async Operations**: Use async/await for external API calls and database operations
|
|
159
|
+
6. **Logging**: Log important actions for debugging and auditing
|
|
160
|
+
|
|
161
|
+
## Tool Nodes
|
|
162
|
+
|
|
163
|
+
Tool nodes force execution of specific tools at defined points in your flow, bypassing LLM decision-making.
|
|
164
|
+
|
|
165
|
+
### Configuration
|
|
166
|
+
|
|
167
|
+
```yaml
|
|
168
|
+
nodes:
|
|
169
|
+
- name: 'Force Refund Processing'
|
|
170
|
+
type: 'tool'
|
|
171
|
+
toolName: 'refundOrder'
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Tool Node vs Automatic Tool Calls
|
|
175
|
+
|
|
176
|
+
| Feature | Tool Nodes | Automatic Tool Calls |
|
|
177
|
+
| ------------- | ------------------------------- | ----------------------------------- |
|
|
178
|
+
| **Execution** | Guaranteed when node is reached | Only when LLM decides to call |
|
|
179
|
+
| **Control** | Explicit flow control | LLM-driven decision |
|
|
180
|
+
| **Use Case** | Required business logic steps | Flexible, context-dependent actions |
|
|
181
|
+
|
|
182
|
+
### Example
|
|
183
|
+
|
|
184
|
+
```yaml
|
|
185
|
+
nodes:
|
|
186
|
+
- name: 'Customer Support Start'
|
|
187
|
+
type: 'prompt'
|
|
188
|
+
prompt: 'How can I help you today?'
|
|
189
|
+
- name: 'Log Interaction'
|
|
190
|
+
type: 'tool'
|
|
191
|
+
toolName: 'auditLog'
|
|
192
|
+
|
|
193
|
+
edges:
|
|
194
|
+
- source: 'Customer Support Start'
|
|
195
|
+
target: 'Log Interaction'
|
|
196
|
+
type: 'always'
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Best Practices
|
|
200
|
+
|
|
201
|
+
1. **Strategic Placement**: Use for critical business logic that must always execute
|
|
202
|
+
2. **Clear Context**: Ensure conversation provides context for parameter extraction
|
|
203
|
+
3. **Error Handling**: Handle errors gracefully since they bypass LLM error recovery
|
|
204
|
+
|
|
205
|
+
Tool parameters are automatically extracted from conversation context and memory state using an internal LLM agent.
|