@minded-ai/mindedjs 1.0.29 → 1.0.31

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.
Files changed (188) hide show
  1. package/dist/agent.d.ts +3 -0
  2. package/dist/agent.d.ts.map +1 -0
  3. package/dist/agent.js +27 -2
  4. package/dist/agent.js.map +1 -1
  5. package/dist/checkpointer/checkpointSaverFactory.d.ts +1 -0
  6. package/dist/checkpointer/checkpointSaverFactory.d.ts.map +1 -0
  7. package/dist/cli/index.d.ts +1 -0
  8. package/dist/cli/index.d.ts.map +1 -0
  9. package/dist/cli/index.js +0 -0
  10. package/dist/edges/createDirectEdge.d.ts +1 -0
  11. package/dist/edges/createDirectEdge.d.ts.map +1 -0
  12. package/dist/edges/createLogicalRouter.d.ts +1 -0
  13. package/dist/edges/createLogicalRouter.d.ts.map +1 -0
  14. package/dist/edges/createPromptRouter.d.ts +1 -0
  15. package/dist/edges/createPromptRouter.d.ts.map +1 -0
  16. package/dist/edges/edgeFactory.d.ts +1 -0
  17. package/dist/edges/edgeFactory.d.ts.map +1 -0
  18. package/dist/events/AgentEvents.d.ts +1 -0
  19. package/dist/events/AgentEvents.d.ts.map +1 -0
  20. package/dist/events/index.d.ts +1 -0
  21. package/dist/events/index.d.ts.map +1 -0
  22. package/dist/index.d.ts +1 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/llm/createLlmInstance.d.ts +1 -0
  25. package/dist/llm/createLlmInstance.d.ts.map +1 -0
  26. package/dist/nodes/addHumanInTheLoopNode.d.ts +1 -0
  27. package/dist/nodes/addHumanInTheLoopNode.d.ts.map +1 -0
  28. package/dist/nodes/addPromptNode.d.ts +1 -0
  29. package/dist/nodes/addPromptNode.d.ts.map +1 -0
  30. package/dist/nodes/addToolNode.d.ts +1 -0
  31. package/dist/nodes/addToolNode.d.ts.map +1 -0
  32. package/dist/nodes/addToolNode.js +33 -17
  33. package/dist/nodes/addToolNode.js.map +1 -1
  34. package/dist/nodes/addTriggerNode.d.ts +1 -0
  35. package/dist/nodes/addTriggerNode.d.ts.map +1 -0
  36. package/dist/nodes/nodeFactory.d.ts +1 -0
  37. package/dist/nodes/nodeFactory.d.ts.map +1 -0
  38. package/dist/platform/config.d.ts +1 -0
  39. package/dist/platform/config.d.ts.map +1 -0
  40. package/dist/platform/config.js +1 -1
  41. package/dist/platform/config.js.map +1 -1
  42. package/dist/platform/mindedChatOpenAI.d.ts +1 -0
  43. package/dist/platform/mindedChatOpenAI.d.ts.map +1 -0
  44. package/dist/platform/mindedCheckpointSaver.d.ts +1 -0
  45. package/dist/platform/mindedCheckpointSaver.d.ts.map +1 -0
  46. package/dist/platform/mindedConnection.d.ts +2 -0
  47. package/dist/platform/mindedConnection.d.ts.map +1 -0
  48. package/dist/platform/mindedConnection.js +25 -5
  49. package/dist/platform/mindedConnection.js.map +1 -1
  50. package/dist/platform/mindedConnectionTypes.d.ts +3 -1
  51. package/dist/platform/mindedConnectionTypes.d.ts.map +1 -0
  52. package/dist/platform/mindedConnectionTypes.js +1 -0
  53. package/dist/platform/mindedConnectionTypes.js.map +1 -1
  54. package/dist/platform/mindedRequest.js +2 -2
  55. package/dist/platform/mindedRequest.js.map +1 -1
  56. package/dist/triggers/triggerTypeToDefaultMessage.d.ts +1 -0
  57. package/dist/triggers/triggerTypeToDefaultMessage.d.ts.map +1 -0
  58. package/dist/types/Agent.types.d.ts +1 -0
  59. package/dist/types/Agent.types.d.ts.map +1 -0
  60. package/dist/types/Flows.types.d.ts +1 -0
  61. package/dist/types/Flows.types.d.ts.map +1 -0
  62. package/dist/types/LLM.types.d.ts +1 -0
  63. package/dist/types/LLM.types.d.ts.map +1 -0
  64. package/dist/types/LangGraph.types.d.ts +1 -0
  65. package/dist/types/LangGraph.types.d.ts.map +1 -0
  66. package/dist/types/Tools.types.d.ts +1 -0
  67. package/dist/types/Tools.types.d.ts.map +1 -0
  68. package/dist/types/Triggers.types.d.ts +1 -0
  69. package/dist/types/Triggers.types.js +3 -0
  70. package/dist/types/Triggers.types.js.map +1 -0
  71. package/package.json +6 -2
  72. package/src/agent.ts +35 -2
  73. package/src/nodes/addToolNode.ts +44 -17
  74. package/src/platform/config.ts +1 -1
  75. package/src/platform/mindedConnection.ts +29 -8
  76. package/src/platform/mindedConnectionTypes.ts +1 -0
  77. package/.github/workflows/CI.yml +0 -34
  78. package/.prettierrc +0 -8
  79. package/dist/internalTools/appActionRunnerTool.d.ts +0 -6
  80. package/dist/internalTools/appActionRunnerTool.js +0 -55
  81. package/dist/internalTools/appActionRunnerTool.js.map +0 -1
  82. package/dist/nodes/actionRunnerTool.d.ts +0 -11
  83. package/dist/nodes/actionRunnerTool.js +0 -84
  84. package/dist/nodes/actionRunnerTool.js.map +0 -1
  85. package/dist/nodes/addAppTool.d.ts +0 -8
  86. package/dist/nodes/addAppTool.js +0 -12
  87. package/dist/nodes/addAppTool.js.map +0 -1
  88. package/dist/nodes/addAppToolNode.d.ts +0 -8
  89. package/dist/nodes/addAppToolNode.js +0 -29
  90. package/dist/nodes/addAppToolNode.js.map +0 -1
  91. package/dist/nodes/callTool.d.ts +0 -10
  92. package/dist/nodes/callTool.js +0 -57
  93. package/dist/nodes/callTool.js.map +0 -1
  94. package/dist/nodes/toolNodeRunner.d.ts +0 -15
  95. package/dist/nodes/toolNodeRunner.js +0 -79
  96. package/dist/nodes/toolNodeRunner.js.map +0 -1
  97. package/dist/tools/appToolRunner.d.ts +0 -30
  98. package/dist/tools/appToolRunner.js +0 -35
  99. package/dist/tools/appToolRunner.js.map +0 -1
  100. package/dist/tools/parser.d.ts +0 -14
  101. package/dist/tools/parser.js +0 -17
  102. package/dist/tools/parser.js.map +0 -1
  103. package/dist/tools/triggerTypeToDefaultMessage.d.ts +0 -3
  104. package/dist/tools/triggerTypeToDefaultMessage.js +0 -10
  105. package/dist/tools/triggerTypeToDefaultMessage.js.map +0 -1
  106. package/docs/.gitbook/assets/image.png +0 -0
  107. package/docs/README.md +0 -51
  108. package/docs/SUMMARY.md +0 -23
  109. package/docs/api-reference/.nojekyll +0 -1
  110. package/docs/api-reference/assets/hierarchy.js +0 -1
  111. package/docs/api-reference/assets/highlight.css +0 -120
  112. package/docs/api-reference/assets/icons.js +0 -18
  113. package/docs/api-reference/assets/icons.svg +0 -1
  114. package/docs/api-reference/assets/main.js +0 -60
  115. package/docs/api-reference/assets/navigation.js +0 -1
  116. package/docs/api-reference/assets/search.js +0 -1
  117. package/docs/api-reference/assets/style.css +0 -1640
  118. package/docs/api-reference/classes/index.Agent.html +0 -4
  119. package/docs/api-reference/enums/index.EdgeType.html +0 -4
  120. package/docs/api-reference/enums/index.NodeType.html +0 -6
  121. package/docs/api-reference/enums/index.TriggerType.html +0 -4
  122. package/docs/api-reference/enums/index.events.html +0 -3
  123. package/docs/api-reference/hierarchy.html +0 -1
  124. package/docs/api-reference/index.html +0 -310
  125. package/docs/api-reference/interfaces/index.AppToolNode.html +0 -5
  126. package/docs/api-reference/interfaces/index.AppTriggerNode.html +0 -6
  127. package/docs/api-reference/interfaces/index.Flow.html +0 -4
  128. package/docs/api-reference/interfaces/index.JunctionNode.html +0 -4
  129. package/docs/api-reference/interfaces/index.LogicalConditionEdge.html +0 -5
  130. package/docs/api-reference/interfaces/index.ManualTriggerNode.html +0 -5
  131. package/docs/api-reference/interfaces/index.PromptConditionEdge.html +0 -5
  132. package/docs/api-reference/interfaces/index.PromptNode.html +0 -6
  133. package/docs/api-reference/interfaces/index.StepForwardEdge.html +0 -4
  134. package/docs/api-reference/interfaces/index.Tool.html +0 -6
  135. package/docs/api-reference/interfaces/index.ToolNode.html +0 -5
  136. package/docs/api-reference/modules/index-1.html +0 -1
  137. package/docs/api-reference/modules/index.html +0 -1
  138. package/docs/api-reference/modules.html +0 -1
  139. package/docs/api-reference/types/index.Edge.html +0 -1
  140. package/docs/api-reference/types/index.Node.html +0 -1
  141. package/docs/api-reference/types/index.TriggerNode.html +0 -1
  142. package/docs/core-concepts/edges.md +0 -299
  143. package/docs/core-concepts/events.md +0 -165
  144. package/docs/core-concepts/flows.md +0 -74
  145. package/docs/core-concepts/memory-types.md +0 -208
  146. package/docs/core-concepts/nodes.md +0 -257
  147. package/docs/core-concepts/tools.md +0 -225
  148. package/docs/core-concepts/triggers.md +0 -87
  149. package/docs/examples/order-refund-flow.md +0 -560
  150. package/docs/getting-started/environment-configuration.md +0 -117
  151. package/docs/getting-started/installation.md +0 -40
  152. package/docs/getting-started/quick-start.md +0 -264
  153. package/docs-structure.md +0 -144
  154. package/eslint.config.js +0 -68
  155. package/examples/orderRefundAgent/flows/orderRefundFlow.yaml +0 -26
  156. package/examples/orderRefundAgent/minded.json +0 -10
  157. package/examples/orderRefundAgent/orderRefundAgent.ts +0 -64
  158. package/examples/orderRefundAgent/schema.ts +0 -7
  159. package/examples/orderRefundAgent/tools/escalateConversation.ts +0 -28
  160. package/examples/orderRefundAgent/tools/index.ts +0 -4
  161. package/examples/orderRefundAgent/tools/refundOrder.ts +0 -27
  162. package/test/can-stay-on-node/can-stay-on-node.test.ts +0 -154
  163. package/test/can-stay-on-node/flows/test-flow.yaml +0 -25
  164. package/test/cannot-stay-on-node/cannot-stay-on-node.test.ts +0 -209
  165. package/test/cannot-stay-on-node/flows/test-flow.yaml +0 -34
  166. package/test/checkpoint-saver/minded-checkpoint-saver-list.test.ts +0 -140
  167. package/test/checkpoint-saver/minded-checkpoint-saver.test.ts +0 -100
  168. package/test/edge-priority/edge-priority.test.ts +0 -182
  169. package/test/edge-priority/flows/all-three-edges/test-flow.yaml +0 -35
  170. package/test/edge-priority/flows/logical-prompt-edges/test-flow.yaml +0 -26
  171. package/test/edge-priority/flows/stepforward-logical-edges/test-flow.yaml +0 -25
  172. package/test/edge-priority/flows/stepforward-prompt-edges/test-flow.yaml +0 -25
  173. package/test/human-in-the-loop-node/flows/test-flow.yaml +0 -23
  174. package/test/human-in-the-loop-node/human-in-the-loop-node.test.ts +0 -94
  175. package/test/logical-edges/flows/logical-edge-test-flow.yaml +0 -24
  176. package/test/logical-edges/logical-edges.test.ts +0 -68
  177. package/test/no-human-in-the-loop-node/flows/test-flow.yaml +0 -23
  178. package/test/no-human-in-the-loop-node/no-human-in-the-loop-node.test.ts +0 -81
  179. package/test/prompt-edges/flows/test-flow.yaml +0 -24
  180. package/test/prompt-edges/prompt-edges.test.ts +0 -92
  181. package/test/prompt-node/flows/test-flow.yaml +0 -24
  182. package/test/prompt-node/prompt-node.test.ts +0 -88
  183. package/test/setup.ts +0 -5
  184. package/test/tool-node/flows/test-flow.yaml +0 -14
  185. package/test/tool-node/tool-node.test.ts +0 -68
  186. package/test/trigger/flows/test-flow.yaml +0 -7
  187. package/test/trigger/trigger.test.ts +0 -185
  188. package/tsconfig.json +0 -17
@@ -1,560 +0,0 @@
1
- # Order Refund Flow Example
2
-
3
- A complete example demonstrating how to build an intelligent customer support agent that can handle order refunds with sophisticated routing and business logic.
4
-
5
- ## Overview
6
-
7
- This example showcases:
8
- - **Trigger handling** with qualification logic
9
- - **Prompt-based routing** for intelligent conversation flow
10
- - **Tool integration** for business logic execution
11
- - **Memory management** for maintaining conversation state
12
- - **Error handling** and edge cases
13
-
14
- ## Complete Implementation
15
-
16
- ### Project Structure
17
-
18
- ```
19
- order-refund-agent/
20
- ├── minded.json # Agent configuration
21
- ├── schema.ts # Memory type definition
22
- ├── agent.ts # Main agent implementation
23
- ├── flows/
24
- │ └── refundFlow.yaml # Flow definition
25
- └── tools/
26
- ├── lookupOrder.ts # Order lookup tool
27
- ├── processRefund.ts # Refund processing tool
28
- └── index.ts # Tool exports
29
- ```
30
-
31
- ### 1. Agent Configuration
32
-
33
- **`minded.json`:**
34
- ```json
35
- {
36
- "flows": ["./flows"],
37
- "llm": {
38
- "name": "ChatOpenAI",
39
- "properties": {
40
- "model": "gpt-4o",
41
- "temperature": 0.7
42
- }
43
- }
44
- }
45
- ```
46
-
47
- ### 2. Memory Schema
48
-
49
- **`schema.ts`:**
50
- ```ts
51
- import { z } from 'zod';
52
-
53
- const memorySchema = z.object({
54
- // Customer information
55
- customerName: z.string().optional(),
56
- customerEmail: z.string().optional(),
57
- customerId: z.string().optional(),
58
-
59
- // Order information
60
- orderId: z.string().optional(),
61
- orderInfo: z.object({
62
- id: z.string(),
63
- status: z.string(),
64
- total: z.number(),
65
- items: z.array(z.string()),
66
- purchaseDate: z.string(),
67
- canRefund: z.boolean(),
68
- }).optional(),
69
-
70
- // Conversation state
71
- conversationStage: z.enum([
72
- 'greeting',
73
- 'gathering_info',
74
- 'processing_refund',
75
- 'complete'
76
- ]).optional(),
77
-
78
- // Refund information
79
- refundReason: z.string().optional(),
80
- refundAmount: z.number().optional(),
81
- refundProcessed: z.boolean().optional(),
82
-
83
- // Metadata
84
- timestamp: z.string().optional(),
85
- customerQuery: z.string().optional(),
86
- });
87
-
88
- export type Memory = z.infer<typeof memorySchema>;
89
- export default memorySchema;
90
- ```
91
-
92
- ### 3. Flow Definition
93
-
94
- **`flows/refundFlow.yaml`:**
95
- ```yaml
96
- name: 'Advanced Order Refund Flow'
97
- nodes:
98
- # Entry point
99
- - type: trigger
100
- triggerType: manual
101
- name: Customer Support Trigger
102
-
103
- # Initial customer interaction
104
- - type: promptNode
105
- name: Support Agent
106
- prompt: |
107
- You are a helpful customer support agent specializing in order issues and refunds.
108
-
109
- Current customer context:
110
- - Query: {{memory.customerQuery}}
111
- - Stage: {{memory.conversationStage}}
112
-
113
- If this is the first interaction:
114
- 1. Greet the customer warmly
115
- 2. Ask for their order ID if they mention order issues
116
- 3. Ask for their name and email for verification
117
-
118
- If you have order information:
119
- - Customer: {{memory.customerName}}
120
- - Order ID: {{memory.orderId}}
121
- - Order Status: {{memory.orderInfo.status}}
122
- - Order Total: ${{memory.orderInfo.total}}
123
-
124
- Be empathetic, professional, and focused on resolving their issue.
125
- llmConfig:
126
- name: ChatOpenAI
127
- properties:
128
- model: gpt-4o
129
- temperature: 0.7
130
-
131
- # Order lookup functionality
132
- - type: tool
133
- name: Lookup Order
134
- toolName: lookupOrder
135
-
136
- # Junction for decision making
137
- - type: junction
138
- name: Refund Decision Point
139
-
140
- # Refund processing
141
- - type: tool
142
- name: Process Refund
143
- toolName: processRefund
144
-
145
- # Final confirmation
146
- - type: promptNode
147
- name: Refund Confirmation
148
- prompt: |
149
- Great news! Your refund has been processed successfully.
150
-
151
- Refund Details:
152
- - Order ID: {{memory.orderId}}
153
- - Refund Amount: ${{memory.refundAmount}}
154
- - Reason: {{memory.refundReason}}
155
-
156
- You can expect to see the refund in your original payment method within 3-5 business days.
157
-
158
- Is there anything else I can help you with today?
159
-
160
- edges:
161
- # Initial flow
162
- - source: Customer Support Trigger
163
- target: Support Agent
164
- type: stepForward
165
-
166
- # Route to order lookup when customer provides order ID
167
- - source: Support Agent
168
- target: Lookup Order
169
- type: promptCondition
170
- prompt: "Customer has provided an order ID and wants to look up order information"
171
-
172
- # After order lookup, go to decision point
173
- - source: Lookup Order
174
- target: Refund Decision Point
175
- type: stepForward
176
-
177
- # Decision point routing
178
- - source: Refund Decision Point
179
- target: Process Refund
180
- type: logicalCondition
181
- condition: "({ memory }) => memory.orderInfo?.canRefund && memory.customerQuery?.toLowerCase().includes('refund')"
182
-
183
- - source: Refund Decision Point
184
- target: Support Agent
185
- type: logicalCondition
186
- condition: "({ memory }) => !memory.orderInfo?.canRefund"
187
-
188
- # After refund processing
189
- - source: Process Refund
190
- target: Refund Confirmation
191
- type: stepForward
192
-
193
- # Allow continued conversation
194
- - source: Refund Confirmation
195
- target: Support Agent
196
- type: promptCondition
197
- prompt: "Customer has additional questions or needs more help"
198
- ```
199
-
200
- ### 4. Tools Implementation
201
-
202
- **`tools/lookupOrder.ts`:**
203
- ```ts
204
- import { z } from 'zod';
205
- import { Tool } from 'mindedjs/src/types/Tools.types';
206
- import { Memory } from '../schema';
207
-
208
- const schema = z.object({
209
- orderId: z.string(),
210
- customerEmail: z.string().optional(),
211
- });
212
-
213
- const lookupOrderTool: Tool<typeof schema, Memory> = {
214
- name: 'lookupOrder',
215
- description: 'Look up order details by order ID and optionally verify with customer email',
216
- input: schema,
217
- execute: async ({ input, memory }) => {
218
- try {
219
- // Simulate API call to order system
220
- const orderInfo = await fetchOrderFromAPI(input.orderId, input.customerEmail);
221
-
222
- if (!orderInfo) {
223
- throw new Error(`Order ${input.orderId} not found or email doesn't match`);
224
- }
225
-
226
- // Determine if refund is allowed based on business rules
227
- const canRefund = determineRefundEligibility(orderInfo);
228
-
229
- return {
230
- memory: {
231
- orderId: input.orderId,
232
- orderInfo: {
233
- ...orderInfo,
234
- canRefund,
235
- },
236
- conversationStage: 'gathering_info',
237
- customerId: orderInfo.customerId,
238
- },
239
- };
240
- } catch (error) {
241
- console.error('Order lookup failed:', error);
242
- return {
243
- memory: {
244
- orderId: input.orderId,
245
- conversationStage: 'gathering_info',
246
- },
247
- };
248
- }
249
- },
250
- };
251
-
252
- // Simulate order API
253
- async function fetchOrderFromAPI(orderId: string, email?: string) {
254
- // Simulate database lookup
255
- const orders = {
256
- '12345': {
257
- id: '12345',
258
- customerId: 'cust_123',
259
- customerEmail: 'john@example.com',
260
- status: 'delivered',
261
- total: 89.99,
262
- items: ['Wireless Headphones', 'Phone Case'],
263
- purchaseDate: '2024-01-15T10:30:00Z',
264
- },
265
- '67890': {
266
- id: '67890',
267
- customerId: 'cust_456',
268
- customerEmail: 'jane@example.com',
269
- status: 'shipped',
270
- total: 199.99,
271
- items: ['Laptop Stand', 'Wireless Mouse'],
272
- purchaseDate: '2024-01-20T14:20:00Z',
273
- },
274
- };
275
-
276
- const order = orders[orderId];
277
- if (!order) return null;
278
-
279
- // Verify email if provided
280
- if (email && order.customerEmail !== email) {
281
- return null;
282
- }
283
-
284
- return order;
285
- }
286
-
287
- // Business rules for refund eligibility
288
- function determineRefundEligibility(orderInfo: any): boolean {
289
- const purchaseDate = new Date(orderInfo.purchaseDate);
290
- const now = new Date();
291
- const daysSincePurchase = Math.floor((now.getTime() - purchaseDate.getTime()) / (1000 * 60 * 60 * 24));
292
-
293
- // Refund rules:
294
- // - Must be within 30 days
295
- // - Order must be delivered
296
- // - Order total must be less than $500 (higher amounts need manager approval)
297
- return (
298
- daysSincePurchase <= 30 &&
299
- orderInfo.status === 'delivered' &&
300
- orderInfo.total < 500
301
- );
302
- }
303
-
304
- export default lookupOrderTool;
305
- ```
306
-
307
- **`tools/processRefund.ts`:**
308
- ```ts
309
- import { z } from 'zod';
310
- import { Tool } from 'mindedjs/src/types/Tools.types';
311
- import { Memory } from '../schema';
312
-
313
- const schema = z.object({
314
- orderId: z.string(),
315
- customerName: z.string(),
316
- reason: z.string(),
317
- amount: z.number().optional(), // Optional partial refund amount
318
- });
319
-
320
- const processRefundTool: Tool<typeof schema, Memory> = {
321
- name: 'processRefund',
322
- description: 'Process a refund for the customer order',
323
- input: schema,
324
- execute: async ({ input, memory }) => {
325
- try {
326
- // Determine refund amount
327
- const refundAmount = input.amount || memory.orderInfo?.total || 0;
328
-
329
- // Validate refund amount
330
- if (refundAmount > (memory.orderInfo?.total || 0)) {
331
- throw new Error('Refund amount cannot exceed order total');
332
- }
333
-
334
- // Process the refund (simulate payment processor API)
335
- const refundResult = await processRefundWithPaymentProcessor({
336
- orderId: input.orderId,
337
- amount: refundAmount,
338
- reason: input.reason,
339
- });
340
-
341
- // Log the refund for auditing
342
- await logRefundTransaction({
343
- orderId: input.orderId,
344
- customerId: memory.customerId,
345
- amount: refundAmount,
346
- reason: input.reason,
347
- processedBy: 'ai-agent',
348
- timestamp: new Date().toISOString(),
349
- });
350
-
351
- console.log(`✅ Refund processed: Order ${input.orderId}, Amount: $${refundAmount}`);
352
-
353
- return {
354
- memory: {
355
- refundAmount,
356
- refundReason: input.reason,
357
- refundProcessed: true,
358
- conversationStage: 'complete',
359
- },
360
- };
361
- } catch (error) {
362
- console.error('Refund processing failed:', error);
363
-
364
- return {
365
- memory: {
366
- refundAmount: 0,
367
- refundReason: input.reason,
368
- refundProcessed: false,
369
- conversationStage: 'gathering_info', // Go back to gathering info
370
- },
371
- };
372
- }
373
- },
374
- };
375
-
376
- // Simulate payment processor API
377
- async function processRefundWithPaymentProcessor(params: any) {
378
- // Simulate API call delay
379
- await new Promise(resolve => setTimeout(resolve, 1000));
380
-
381
- // Simulate occasional failures for testing
382
- if (Math.random() < 0.1) {
383
- throw new Error('Payment processor temporarily unavailable');
384
- }
385
-
386
- return {
387
- refundId: `ref_${Date.now()}`,
388
- status: 'processed',
389
- amount: params.amount,
390
- };
391
- }
392
-
393
- // Simulate audit logging
394
- async function logRefundTransaction(transaction: any) {
395
- console.log('📝 Logging refund transaction:', transaction);
396
- // In real implementation, this would write to a database or audit system
397
- }
398
-
399
- export default processRefundTool;
400
- ```
401
-
402
- **`tools/index.ts`:**
403
- ```ts
404
- import lookupOrderTool from './lookupOrder';
405
- import processRefundTool from './processRefund';
406
-
407
- export default [lookupOrderTool, processRefundTool];
408
- ```
409
-
410
- ### 5. Main Agent Implementation
411
-
412
- **`agent.ts`:**
413
- ```ts
414
- import { Agent } from 'mindedjs/src/agent';
415
- import { HumanMessage } from '@langchain/core/messages';
416
- import { events } from 'mindedjs/src/index';
417
- import memorySchema, { Memory } from './schema';
418
- import tools from './tools';
419
- import config from './minded.json';
420
-
421
- // Create the agent
422
- const agent = new Agent<Memory>({
423
- memorySchema,
424
- config,
425
- tools,
426
- });
427
-
428
- // Handle AI messages (responses to user)
429
- agent.on(events.AI_MESSAGE, async ({ message, memory }) => {
430
- console.log('🤖 Agent:', message);
431
- if (memory.conversationStage) {
432
- console.log(` Stage: ${memory.conversationStage}`);
433
- }
434
- });
435
-
436
- // Handle trigger events with qualification logic
437
- agent.on(events.TRIGGER_EVENT, async ({ triggerName, triggerBody }) => {
438
- if (triggerName === 'Customer Support Trigger') {
439
- // Qualify the trigger - only handle customer service related queries
440
- const lowerQuery = triggerBody.toLowerCase();
441
- const serviceKeywords = ['order', 'refund', 'help', 'support', 'issue', 'problem'];
442
-
443
- const isServiceQuery = serviceKeywords.some(keyword =>
444
- lowerQuery.includes(keyword)
445
- );
446
-
447
- if (!isServiceQuery) {
448
- console.log('❌ Query not qualified for customer service');
449
- return false; // Disqualify this trigger
450
- }
451
-
452
- console.log('✅ Customer service query qualified');
453
-
454
- // Transform the request and initialize memory
455
- return {
456
- memory: {
457
- customerQuery: triggerBody,
458
- conversationStage: 'greeting',
459
- timestamp: new Date().toISOString(),
460
- },
461
- messages: [new HumanMessage(triggerBody)],
462
- };
463
- }
464
-
465
- return false; // Unknown trigger
466
- });
467
-
468
- // Example usage function
469
- async function runRefundExample() {
470
- console.log('🚀 Starting Order Refund Flow Example\n');
471
-
472
- const examples = [
473
- {
474
- description: 'Happy path - valid refund request',
475
- query: 'Hi, I need to return my order #12345. The headphones don\'t work properly.',
476
- },
477
- {
478
- description: 'Order lookup required',
479
- query: 'I want to check the status of my recent order and possibly get a refund.',
480
- },
481
- {
482
- description: 'Non-service query (should be disqualified)',
483
- query: 'What\'s the weather like today?',
484
- },
485
- ];
486
-
487
- for (const example of examples) {
488
- console.log(`\n📋 Example: ${example.description}`);
489
- console.log(`User: ${example.query}\n`);
490
-
491
- try {
492
- const result = await agent.invoke({
493
- triggerBody: example.query,
494
- triggerName: 'Customer Support Trigger',
495
- sessionId: `session_${Date.now()}`,
496
- });
497
-
498
- console.log('✅ Flow completed successfully');
499
- console.log('Final memory state:', JSON.stringify(result.memory, null, 2));
500
- } catch (error) {
501
- console.error('❌ Flow execution failed:', error);
502
- }
503
-
504
- console.log('\n' + '─'.repeat(50));
505
- }
506
- }
507
-
508
- // Run the example if this file is executed directly
509
- if (require.main === module) {
510
- runRefundExample().catch(console.error);
511
- }
512
-
513
- export { agent, runRefundExample };
514
- ```
515
-
516
- ## Running the Example
517
-
518
- 1. **Install dependencies:**
519
- ```bash
520
- npm install @minded-ai/mindedjs langchain
521
- ```
522
-
523
- 2. **Set up environment:**
524
- ```bash
525
- export OPENAI_API_KEY="your-openai-api-key"
526
- ```
527
-
528
- 3. **Run the agent:**
529
- ```bash
530
- npx ts-node agent.ts
531
- ```
532
-
533
- ## Expected Output
534
-
535
- ```
536
- 🚀 Starting Order Refund Flow Example
537
-
538
- 📋 Example: Happy path - valid refund request
539
- User: Hi, I need to return my order #12345. The headphones don't work properly.
540
-
541
- ✅ Customer service query qualified
542
- 🤖 Agent: Hello! I'm sorry to hear you're having trouble with your headphones. I'd be happy to help you with a return. I see you mentioned order #12345. Could you please provide your email address so I can look up your order details?
543
-
544
- ✅ Refund processed: Order 12345, Amount: $89.99
545
- 📝 Logging refund transaction: {...}
546
- 🤖 Agent: Great news! Your refund has been processed successfully...
547
-
548
- ✅ Flow completed successfully
549
- ```
550
-
551
- ## Key Features Demonstrated
552
-
553
- 1. **Intelligent Qualification**: The trigger only accepts customer service related queries
554
- 2. **Conversation State Management**: Memory tracks the conversation stage and relevant information
555
- 3. **Business Logic Integration**: Tools implement real business rules for refund eligibility
556
- 4. **Error Handling**: Graceful handling of failed API calls and invalid requests
557
- 5. **Audit Trail**: All refund transactions are logged for compliance
558
- 6. **Type Safety**: Full TypeScript type safety throughout the flow
559
-
560
- This example provides a solid foundation for building production-ready customer service agents with MindedJS!
@@ -1,117 +0,0 @@
1
- # Environment Configuration
2
-
3
- Configure your environment variables to customize MindedJS behavior and connect to external services.
4
-
5
- ## Environment Variables
6
-
7
- Create a `.env` file in your project root to configure MindedJS:
8
-
9
- ```bash
10
- # .env file
11
- ```
12
-
13
- ### Core Configuration
14
-
15
- #### `RUN_LOCALLY`
16
-
17
- Controls whether the agent runs fully local in memory or connects to the Minded platform.
18
-
19
- ```bash
20
- RUN_LOCALLY=true
21
- ```
22
-
23
- - **`true`**: Agent runs fully local in memory without external connections
24
- - **`false`** (default): Agent connects to the Minded platform
25
-
26
- ### Chat Model Credentials
27
-
28
- Depending on which LangChain chat models you use in your agent, you'll need to specify the appropriate credentials. MindedJS supports all [LangChain chat models](https://js.langchain.com/docs/integrations/chat/).
29
-
30
- #### Popular Chat Model Configurations
31
-
32
- **OpenAI**
33
-
34
- ```bash
35
- OPENAI_API_KEY=your-openai-api-key
36
- ```
37
-
38
- **Anthropic**
39
-
40
- ```bash
41
- ANTHROPIC_API_KEY=your-anthropic-api-key
42
- ```
43
-
44
- **Google Gemini**
45
-
46
- ```bash
47
- GOOGLE_API_KEY=your-google-api-key
48
- ```
49
-
50
- **Groq**
51
-
52
- ```bash
53
- GROQ_API_KEY=your-groq-api-key
54
- ```
55
-
56
- **Azure OpenAI**
57
-
58
- ```bash
59
- AZURE_OPENAI_API_KEY=your-azure-openai-api-key
60
- AZURE_OPENAI_ENDPOINT=your-azure-openai-endpoint
61
- ```
62
-
63
- **Mistral AI**
64
-
65
- ```bash
66
- MISTRAL_API_KEY=your-mistral-api-key
67
- ```
68
-
69
- {% hint style="info" %}
70
- For a complete list of supported chat models and their required environment variables, visit the [LangChain Chat Models documentation](https://js.langchain.com/docs/integrations/chat/).
71
- {% endhint %}
72
-
73
- ### Platform Connection
74
-
75
- #### `MINDED_CONNECTION_TOKEN`
76
-
77
- Required to connect to the Minded platform for advanced features and monitoring. Each token is specific to the agent you are working on.
78
-
79
- ```bash
80
- MINDED_CONNECTION_TOKEN=your-minded-connection-token
81
- ```
82
-
83
- {% hint style="info" %}
84
- Your connection token is available on the [Minded platform](https://app.minded.com) in the agent page within the GitHub integration popup. You can also use the npx command provided there to automatically set the minded token.
85
- {% endhint %}
86
-
87
- ## Example .env File
88
-
89
- Here's a complete example of a `.env` file:
90
-
91
- ```bash
92
- # Core Configuration
93
- RUN_LOCALLY=false
94
-
95
- # Chat Model (OpenAI example)
96
- OPENAI_API_KEY=sk-your-openai-api-key-here
97
-
98
- # Platform Connection
99
- MINDED_CONNECTION_TOKEN=your-minded-connection-token-here
100
- ```
101
-
102
- ## Loading Environment Variables
103
-
104
- MindedJS automatically loads environment variables from your `.env` file. Make sure to:
105
-
106
- 1. Create the `.env` file in your project root
107
- 2. Add `.env` to your `.gitignore` file to keep credentials secure
108
- 3. Never commit your `.env` file to version control
109
-
110
- ```bash
111
- # Add to .gitignore
112
- .env
113
- ```
114
-
115
- ## Next Steps
116
-
117
- With your environment configured, you're ready to build your first agent! Head over to the [Quick Start](quick-start.md) guide.
@@ -1,40 +0,0 @@
1
- # Installation
2
-
3
- Get MindedJS up and running in your project.
4
-
5
- ## Requirements
6
-
7
- - Node.js 18 or later
8
- - npm, yarn, or pnpm
9
-
10
- ## Install MindedJS
11
-
12
- {% tabs %}
13
- {% tab title="npm" %}
14
-
15
- ```bash
16
- npm i @minded-ai/mindedjs langchain
17
- ```
18
-
19
- {% endtab %}
20
-
21
- {% tab title="yarn" %}
22
-
23
- ```bash
24
- yarn add @minded-ai/mindedjs langchain
25
- ```
26
-
27
- {% endtab %}
28
-
29
- {% tab title="pnpm" %}
30
-
31
- ```bash
32
- pnpm add @minded-ai/mindedjs langchain
33
- ```
34
-
35
- {% endtab %}
36
- {% endtabs %}
37
-
38
- ## Next Steps
39
-
40
- Now that MindedJS is installed, configure your environment variables in the [Environment Configuration](environment-configuration.md) guide, then head over to the [Quick Start](quick-start.md) guide to build your first agent!