@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.
- package/dist/agent.d.ts +3 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +27 -2
- package/dist/agent.js.map +1 -1
- package/dist/checkpointer/checkpointSaverFactory.d.ts +1 -0
- package/dist/checkpointer/checkpointSaverFactory.d.ts.map +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +0 -0
- package/dist/edges/createDirectEdge.d.ts +1 -0
- package/dist/edges/createDirectEdge.d.ts.map +1 -0
- package/dist/edges/createLogicalRouter.d.ts +1 -0
- package/dist/edges/createLogicalRouter.d.ts.map +1 -0
- package/dist/edges/createPromptRouter.d.ts +1 -0
- package/dist/edges/createPromptRouter.d.ts.map +1 -0
- package/dist/edges/edgeFactory.d.ts +1 -0
- package/dist/edges/edgeFactory.d.ts.map +1 -0
- package/dist/events/AgentEvents.d.ts +1 -0
- package/dist/events/AgentEvents.d.ts.map +1 -0
- package/dist/events/index.d.ts +1 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/llm/createLlmInstance.d.ts +1 -0
- package/dist/llm/createLlmInstance.d.ts.map +1 -0
- package/dist/nodes/addHumanInTheLoopNode.d.ts +1 -0
- package/dist/nodes/addHumanInTheLoopNode.d.ts.map +1 -0
- package/dist/nodes/addPromptNode.d.ts +1 -0
- package/dist/nodes/addPromptNode.d.ts.map +1 -0
- package/dist/nodes/addToolNode.d.ts +1 -0
- package/dist/nodes/addToolNode.d.ts.map +1 -0
- package/dist/nodes/addToolNode.js +33 -17
- package/dist/nodes/addToolNode.js.map +1 -1
- package/dist/nodes/addTriggerNode.d.ts +1 -0
- package/dist/nodes/addTriggerNode.d.ts.map +1 -0
- package/dist/nodes/nodeFactory.d.ts +1 -0
- package/dist/nodes/nodeFactory.d.ts.map +1 -0
- package/dist/platform/config.d.ts +1 -0
- package/dist/platform/config.d.ts.map +1 -0
- package/dist/platform/config.js +1 -1
- package/dist/platform/config.js.map +1 -1
- package/dist/platform/mindedChatOpenAI.d.ts +1 -0
- package/dist/platform/mindedChatOpenAI.d.ts.map +1 -0
- package/dist/platform/mindedCheckpointSaver.d.ts +1 -0
- package/dist/platform/mindedCheckpointSaver.d.ts.map +1 -0
- package/dist/platform/mindedConnection.d.ts +2 -0
- package/dist/platform/mindedConnection.d.ts.map +1 -0
- package/dist/platform/mindedConnection.js +25 -5
- package/dist/platform/mindedConnection.js.map +1 -1
- package/dist/platform/mindedConnectionTypes.d.ts +3 -1
- package/dist/platform/mindedConnectionTypes.d.ts.map +1 -0
- package/dist/platform/mindedConnectionTypes.js +1 -0
- package/dist/platform/mindedConnectionTypes.js.map +1 -1
- package/dist/platform/mindedRequest.js +2 -2
- package/dist/platform/mindedRequest.js.map +1 -1
- package/dist/triggers/triggerTypeToDefaultMessage.d.ts +1 -0
- package/dist/triggers/triggerTypeToDefaultMessage.d.ts.map +1 -0
- package/dist/types/Agent.types.d.ts +1 -0
- package/dist/types/Agent.types.d.ts.map +1 -0
- package/dist/types/Flows.types.d.ts +1 -0
- package/dist/types/Flows.types.d.ts.map +1 -0
- package/dist/types/LLM.types.d.ts +1 -0
- package/dist/types/LLM.types.d.ts.map +1 -0
- package/dist/types/LangGraph.types.d.ts +1 -0
- package/dist/types/LangGraph.types.d.ts.map +1 -0
- package/dist/types/Tools.types.d.ts +1 -0
- package/dist/types/Tools.types.d.ts.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/package.json +6 -2
- package/src/agent.ts +35 -2
- package/src/nodes/addToolNode.ts +44 -17
- package/src/platform/config.ts +1 -1
- package/src/platform/mindedConnection.ts +29 -8
- package/src/platform/mindedConnectionTypes.ts +1 -0
- package/.github/workflows/CI.yml +0 -34
- package/.prettierrc +0 -8
- package/dist/internalTools/appActionRunnerTool.d.ts +0 -6
- package/dist/internalTools/appActionRunnerTool.js +0 -55
- package/dist/internalTools/appActionRunnerTool.js.map +0 -1
- package/dist/nodes/actionRunnerTool.d.ts +0 -11
- package/dist/nodes/actionRunnerTool.js +0 -84
- package/dist/nodes/actionRunnerTool.js.map +0 -1
- package/dist/nodes/addAppTool.d.ts +0 -8
- package/dist/nodes/addAppTool.js +0 -12
- package/dist/nodes/addAppTool.js.map +0 -1
- package/dist/nodes/addAppToolNode.d.ts +0 -8
- package/dist/nodes/addAppToolNode.js +0 -29
- package/dist/nodes/addAppToolNode.js.map +0 -1
- package/dist/nodes/callTool.d.ts +0 -10
- package/dist/nodes/callTool.js +0 -57
- package/dist/nodes/callTool.js.map +0 -1
- package/dist/nodes/toolNodeRunner.d.ts +0 -15
- package/dist/nodes/toolNodeRunner.js +0 -79
- package/dist/nodes/toolNodeRunner.js.map +0 -1
- package/dist/tools/appToolRunner.d.ts +0 -30
- package/dist/tools/appToolRunner.js +0 -35
- package/dist/tools/appToolRunner.js.map +0 -1
- package/dist/tools/parser.d.ts +0 -14
- package/dist/tools/parser.js +0 -17
- package/dist/tools/parser.js.map +0 -1
- package/dist/tools/triggerTypeToDefaultMessage.d.ts +0 -3
- package/dist/tools/triggerTypeToDefaultMessage.js +0 -10
- package/dist/tools/triggerTypeToDefaultMessage.js.map +0 -1
- package/docs/.gitbook/assets/image.png +0 -0
- package/docs/README.md +0 -51
- package/docs/SUMMARY.md +0 -23
- package/docs/api-reference/.nojekyll +0 -1
- package/docs/api-reference/assets/hierarchy.js +0 -1
- package/docs/api-reference/assets/highlight.css +0 -120
- package/docs/api-reference/assets/icons.js +0 -18
- package/docs/api-reference/assets/icons.svg +0 -1
- package/docs/api-reference/assets/main.js +0 -60
- package/docs/api-reference/assets/navigation.js +0 -1
- package/docs/api-reference/assets/search.js +0 -1
- package/docs/api-reference/assets/style.css +0 -1640
- package/docs/api-reference/classes/index.Agent.html +0 -4
- package/docs/api-reference/enums/index.EdgeType.html +0 -4
- package/docs/api-reference/enums/index.NodeType.html +0 -6
- package/docs/api-reference/enums/index.TriggerType.html +0 -4
- package/docs/api-reference/enums/index.events.html +0 -3
- package/docs/api-reference/hierarchy.html +0 -1
- package/docs/api-reference/index.html +0 -310
- package/docs/api-reference/interfaces/index.AppToolNode.html +0 -5
- package/docs/api-reference/interfaces/index.AppTriggerNode.html +0 -6
- package/docs/api-reference/interfaces/index.Flow.html +0 -4
- package/docs/api-reference/interfaces/index.JunctionNode.html +0 -4
- package/docs/api-reference/interfaces/index.LogicalConditionEdge.html +0 -5
- package/docs/api-reference/interfaces/index.ManualTriggerNode.html +0 -5
- package/docs/api-reference/interfaces/index.PromptConditionEdge.html +0 -5
- package/docs/api-reference/interfaces/index.PromptNode.html +0 -6
- package/docs/api-reference/interfaces/index.StepForwardEdge.html +0 -4
- package/docs/api-reference/interfaces/index.Tool.html +0 -6
- package/docs/api-reference/interfaces/index.ToolNode.html +0 -5
- package/docs/api-reference/modules/index-1.html +0 -1
- package/docs/api-reference/modules/index.html +0 -1
- package/docs/api-reference/modules.html +0 -1
- package/docs/api-reference/types/index.Edge.html +0 -1
- package/docs/api-reference/types/index.Node.html +0 -1
- package/docs/api-reference/types/index.TriggerNode.html +0 -1
- package/docs/core-concepts/edges.md +0 -299
- package/docs/core-concepts/events.md +0 -165
- package/docs/core-concepts/flows.md +0 -74
- package/docs/core-concepts/memory-types.md +0 -208
- package/docs/core-concepts/nodes.md +0 -257
- package/docs/core-concepts/tools.md +0 -225
- package/docs/core-concepts/triggers.md +0 -87
- package/docs/examples/order-refund-flow.md +0 -560
- package/docs/getting-started/environment-configuration.md +0 -117
- package/docs/getting-started/installation.md +0 -40
- package/docs/getting-started/quick-start.md +0 -264
- package/docs-structure.md +0 -144
- package/eslint.config.js +0 -68
- package/examples/orderRefundAgent/flows/orderRefundFlow.yaml +0 -26
- package/examples/orderRefundAgent/minded.json +0 -10
- package/examples/orderRefundAgent/orderRefundAgent.ts +0 -64
- package/examples/orderRefundAgent/schema.ts +0 -7
- package/examples/orderRefundAgent/tools/escalateConversation.ts +0 -28
- package/examples/orderRefundAgent/tools/index.ts +0 -4
- package/examples/orderRefundAgent/tools/refundOrder.ts +0 -27
- package/test/can-stay-on-node/can-stay-on-node.test.ts +0 -154
- package/test/can-stay-on-node/flows/test-flow.yaml +0 -25
- package/test/cannot-stay-on-node/cannot-stay-on-node.test.ts +0 -209
- package/test/cannot-stay-on-node/flows/test-flow.yaml +0 -34
- package/test/checkpoint-saver/minded-checkpoint-saver-list.test.ts +0 -140
- package/test/checkpoint-saver/minded-checkpoint-saver.test.ts +0 -100
- package/test/edge-priority/edge-priority.test.ts +0 -182
- package/test/edge-priority/flows/all-three-edges/test-flow.yaml +0 -35
- package/test/edge-priority/flows/logical-prompt-edges/test-flow.yaml +0 -26
- package/test/edge-priority/flows/stepforward-logical-edges/test-flow.yaml +0 -25
- package/test/edge-priority/flows/stepforward-prompt-edges/test-flow.yaml +0 -25
- package/test/human-in-the-loop-node/flows/test-flow.yaml +0 -23
- package/test/human-in-the-loop-node/human-in-the-loop-node.test.ts +0 -94
- package/test/logical-edges/flows/logical-edge-test-flow.yaml +0 -24
- package/test/logical-edges/logical-edges.test.ts +0 -68
- package/test/no-human-in-the-loop-node/flows/test-flow.yaml +0 -23
- package/test/no-human-in-the-loop-node/no-human-in-the-loop-node.test.ts +0 -81
- package/test/prompt-edges/flows/test-flow.yaml +0 -24
- package/test/prompt-edges/prompt-edges.test.ts +0 -92
- package/test/prompt-node/flows/test-flow.yaml +0 -24
- package/test/prompt-node/prompt-node.test.ts +0 -88
- package/test/setup.ts +0 -5
- package/test/tool-node/flows/test-flow.yaml +0 -14
- package/test/tool-node/tool-node.test.ts +0 -68
- package/test/trigger/flows/test-flow.yaml +0 -7
- package/test/trigger/trigger.test.ts +0 -185
- package/tsconfig.json +0 -17
|
@@ -1,225 +0,0 @@
|
|
|
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 LLM calls
|
|
15
|
-
execute: ({ input, memory }) => Promise<{ memory?, result? }>;
|
|
16
|
-
}
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Execute Function Signature
|
|
20
|
-
|
|
21
|
-
The `execute` function is the core of every tool. It receives validated input from the LLM and current memory state, then returns updated memory and/or result tool result which will be added to the message history and be available for future LLM calls.
|
|
22
|
-
|
|
23
|
-
### Parameters
|
|
24
|
-
|
|
25
|
-
```ts
|
|
26
|
-
execute: ({ input, memory }) => Promise<{ memory?, result? }>
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
- **`input`**: Validated data matching your Zod schema - contains the parameters the LLM extracted from the conversation
|
|
30
|
-
- **`memory`**: Current conversation memory state - contains all the context and data accumulated during the flow
|
|
31
|
-
|
|
32
|
-
### Return Value
|
|
33
|
-
|
|
34
|
-
The execute function returns a Promise with an object containing:
|
|
35
|
-
|
|
36
|
-
- **`memory?`** (optional): Updated memory state that will be merged with existing memory
|
|
37
|
-
- **`result?`** (optional): Result that gets sent back to the LLM as the tool's response
|
|
38
|
-
|
|
39
|
-
## Basic Tool Example
|
|
40
|
-
|
|
41
|
-
Here's a simple refund processing tool:
|
|
42
|
-
|
|
43
|
-
```ts
|
|
44
|
-
import { z } from 'zod';
|
|
45
|
-
import { Tool } from 'mindedjs/src/types/Tools.types';
|
|
46
|
-
import memorySchema from '../schema';
|
|
47
|
-
|
|
48
|
-
type Memory = z.infer<typeof memorySchema>;
|
|
49
|
-
|
|
50
|
-
const schema = z.object({
|
|
51
|
-
orderId: z.string(),
|
|
52
|
-
customerName: z.string(),
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const refundOrderTool: Tool<typeof schema, Memory> = {
|
|
56
|
-
name: 'refundOrder',
|
|
57
|
-
description: 'Process a customer refund for their order',
|
|
58
|
-
input: schema,
|
|
59
|
-
execute: async ({ input, memory }) => {
|
|
60
|
-
// Your business logic here
|
|
61
|
-
console.log(`Processing refund for order ${input.orderId}`);
|
|
62
|
-
|
|
63
|
-
// Call external API, update database, etc.
|
|
64
|
-
const refundAmount = await processRefundInSystem(input.orderId);
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
memory: {
|
|
68
|
-
orderId: input.orderId,
|
|
69
|
-
customerName: input.customerName,
|
|
70
|
-
issue: `Refund processed: $${refundAmount}`,
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export default refundOrderTool;
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
## Tool Registration
|
|
80
|
-
|
|
81
|
-
### Global Tools
|
|
82
|
-
|
|
83
|
-
Mark tools as global if you want them to be available in all LLM calls.
|
|
84
|
-
|
|
85
|
-
```ts
|
|
86
|
-
const auditLogTool: Tool<typeof auditSchema, Memory> = {
|
|
87
|
-
name: 'auditLog',
|
|
88
|
-
description: 'Log user action for compliance',
|
|
89
|
-
isGlobal: true, // Available in all flows
|
|
90
|
-
input: z.object({
|
|
91
|
-
action: z.string(),
|
|
92
|
-
details: z.string(),
|
|
93
|
-
}),
|
|
94
|
-
execute: async ({ input, memory }) => {
|
|
95
|
-
await auditService.log({
|
|
96
|
-
userId: memory.userId,
|
|
97
|
-
action: input.action,
|
|
98
|
-
details: input.details,
|
|
99
|
-
timestamp: new Date(),
|
|
100
|
-
});
|
|
101
|
-
},
|
|
102
|
-
};
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
## Memory Management
|
|
106
|
-
|
|
107
|
-
Tools can read and update memory state:
|
|
108
|
-
|
|
109
|
-
```ts
|
|
110
|
-
const updateProfileTool: Tool<typeof profileSchema, Memory> = {
|
|
111
|
-
name: 'updateProfile',
|
|
112
|
-
description: 'Update customer profile information',
|
|
113
|
-
input: z.object({
|
|
114
|
-
field: z.string(),
|
|
115
|
-
value: z.string(),
|
|
116
|
-
}),
|
|
117
|
-
execute: async ({ input, memory }) => {
|
|
118
|
-
// Read current memory
|
|
119
|
-
console.log(`Current customer: ${memory.customerName}`);
|
|
120
|
-
|
|
121
|
-
// Update external system
|
|
122
|
-
await profileService.update(memory.customerId, {
|
|
123
|
-
[input.field]: input.value
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
// Return updated memory
|
|
127
|
-
return {
|
|
128
|
-
memory: {
|
|
129
|
-
...memory,
|
|
130
|
-
[`${input.field}Updated`]: true,
|
|
131
|
-
},
|
|
132
|
-
};
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
## Error Handling
|
|
138
|
-
|
|
139
|
-
Handle errors gracefully in tools:
|
|
140
|
-
|
|
141
|
-
```ts
|
|
142
|
-
const paymentTool: Tool<typeof paymentSchema, Memory> = {
|
|
143
|
-
name: 'processPayment',
|
|
144
|
-
description: 'Process customer payment',
|
|
145
|
-
input: z.object({
|
|
146
|
-
amount: z.number(),
|
|
147
|
-
cardToken: z.string(),
|
|
148
|
-
}),
|
|
149
|
-
execute: async ({ input, memory }) => {
|
|
150
|
-
try {
|
|
151
|
-
const result = await paymentService.charge({
|
|
152
|
-
amount: input.amount,
|
|
153
|
-
cardToken: input.cardToken,
|
|
154
|
-
customerId: memory.customerId,
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
return {
|
|
158
|
-
result: `Payment successful: ${result.transactionId}`,
|
|
159
|
-
memory: { lastPaymentId: result.transactionId },
|
|
160
|
-
};
|
|
161
|
-
} catch (error) {
|
|
162
|
-
console.error('Payment failed:', error);
|
|
163
|
-
return {
|
|
164
|
-
result: 'Payment failed. Please try again or contact support.',
|
|
165
|
-
memory: { paymentError: error.message },
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
};
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
## Best Practices
|
|
173
|
-
|
|
174
|
-
1. **Clear Descriptions**: Write descriptions that help the LLM understand when to use the tool
|
|
175
|
-
2. **Input Validation**: Use Zod schemas to validate all inputs
|
|
176
|
-
3. **Memory Updates**: Update memory with relevant information for future tool calls
|
|
177
|
-
4. **Error Handling**: Always handle errors gracefully and provide meaningful messages
|
|
178
|
-
5. **Async Operations**: Use async/await for external API calls and database operations
|
|
179
|
-
6. **Logging**: Log important actions for debugging and auditing
|
|
180
|
-
|
|
181
|
-
## Tool Nodes
|
|
182
|
-
|
|
183
|
-
Tool nodes force execution of specific tools at defined points in your flow, bypassing LLM decision-making.
|
|
184
|
-
|
|
185
|
-
### Configuration
|
|
186
|
-
|
|
187
|
-
```yaml
|
|
188
|
-
nodes:
|
|
189
|
-
- name: 'Force Refund Processing'
|
|
190
|
-
type: 'tool'
|
|
191
|
-
toolName: 'refundOrder'
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
### Tool Node vs Automatic Tool Calls
|
|
195
|
-
|
|
196
|
-
| Feature | Tool Nodes | Automatic Tool Calls |
|
|
197
|
-
| ------------- | ------------------------------- | ----------------------------------- |
|
|
198
|
-
| **Execution** | Guaranteed when node is reached | Only when LLM decides to call |
|
|
199
|
-
| **Control** | Explicit flow control | LLM-driven decision |
|
|
200
|
-
| **Use Case** | Required business logic steps | Flexible, context-dependent actions |
|
|
201
|
-
|
|
202
|
-
### Example
|
|
203
|
-
|
|
204
|
-
```yaml
|
|
205
|
-
nodes:
|
|
206
|
-
- name: 'Customer Support Start'
|
|
207
|
-
type: 'prompt'
|
|
208
|
-
prompt: 'How can I help you today?'
|
|
209
|
-
- name: 'Log Interaction'
|
|
210
|
-
type: 'tool'
|
|
211
|
-
toolName: 'auditLog'
|
|
212
|
-
|
|
213
|
-
edges:
|
|
214
|
-
- source: 'Customer Support Start'
|
|
215
|
-
target: 'Log Interaction'
|
|
216
|
-
type: 'always'
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
### Best Practices
|
|
220
|
-
|
|
221
|
-
1. **Strategic Placement**: Use for critical business logic that must always execute
|
|
222
|
-
2. **Clear Context**: Ensure conversation provides context for parameter extraction
|
|
223
|
-
3. **Error Handling**: Handle errors gracefully since they bypass LLM error recovery
|
|
224
|
-
|
|
225
|
-
Tool parameters are automatically extracted from conversation context and memory state using an internal LLM agent.
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
# Triggers
|
|
2
|
-
|
|
3
|
-
Triggers are the entry points into your agent's flows. They serve as the initial contact point between external systems and your agent, handling incoming events and initializing conversations with appropriate context and memory.
|
|
4
|
-
|
|
5
|
-
## Trigger Types
|
|
6
|
-
|
|
7
|
-
Currently, MindedJS supports a single type of trigger:
|
|
8
|
-
|
|
9
|
-
- **App Triggers**: Triggered by specific applications (e.g., Slack, Zendesk)
|
|
10
|
-
- Each app trigger is identified by a unique `appTriggerId`
|
|
11
|
-
- Triggers can be customized to handle app-specific data formats
|
|
12
|
-
- Supports automatic message conversion for certain apps (e.g., Slack messages)
|
|
13
|
-
|
|
14
|
-
### Trigger Invocation History
|
|
15
|
-
|
|
16
|
-
When a trigger is invoked, it creates a comprehensive record of the event that is:
|
|
17
|
-
|
|
18
|
-
1. Added to the flow history for tracking and debugging
|
|
19
|
-
2. Passed to subsequent tool calls via the `triggerInvocations` parameter
|
|
20
|
-
3. Preserved throughout the flow's execution
|
|
21
|
-
|
|
22
|
-
This history allows tools to:
|
|
23
|
-
|
|
24
|
-
- Access the original trigger context
|
|
25
|
-
- Make decisions based on the triggering event
|
|
26
|
-
- Maintain conversation continuity
|
|
27
|
-
- Debug flow execution
|
|
28
|
-
|
|
29
|
-
Example:
|
|
30
|
-
|
|
31
|
-
```typescript
|
|
32
|
-
const tool: Tool = {
|
|
33
|
-
name: 'myTool',
|
|
34
|
-
execute: async ({ input, triggerInvocations }) => {
|
|
35
|
-
// Access trigger information
|
|
36
|
-
const trigger = triggerInvocations[0];
|
|
37
|
-
console.log(`Triggered by ${trigger.appName}: ${trigger.triggerName}`);
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
### Default Message Behavior
|
|
43
|
-
|
|
44
|
-
MindedJS provides intelligent message handling for different trigger types through the `triggerTypeToDefaultMessage` mapping. This system:
|
|
45
|
-
|
|
46
|
-
- Automatically converts trigger data into appropriate message formats
|
|
47
|
-
- Maintains conversation context without manual intervention
|
|
48
|
-
- Supports different message types for different applications
|
|
49
|
-
|
|
50
|
-
Currently supported default messages:
|
|
51
|
-
|
|
52
|
-
- **Slack**: For "New Direct Message (Instant)" triggers, the message text is automatically converted to a human message
|
|
53
|
-
|
|
54
|
-
Example:
|
|
55
|
-
|
|
56
|
-
```typescript
|
|
57
|
-
// Slack trigger will automatically add a human message
|
|
58
|
-
const slackResult = await agent.invoke({
|
|
59
|
-
triggerName: 'New Direct Message (Instant)',
|
|
60
|
-
triggerBody: { text: 'Hello from Slack' },
|
|
61
|
-
appName: 'Slack',
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// Other triggers won't add any messages by default
|
|
65
|
-
const otherResult = await agent.invoke({
|
|
66
|
-
triggerName: 'SomeOtherTrigger',
|
|
67
|
-
triggerBody: { text: 'Hello' },
|
|
68
|
-
appName: 'OtherApp',
|
|
69
|
-
});
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
### Validate Trigger Input
|
|
73
|
-
|
|
74
|
-
```typescript
|
|
75
|
-
// ✅ Good - Input validation
|
|
76
|
-
agent.on(AgentEvents.TRIGGER_EVENT, async ({ triggerName, triggerBody }) => {
|
|
77
|
-
if (!triggerBody.customerId || !triggerBody.message) {
|
|
78
|
-
return false; // Disqualify invalid triggers
|
|
79
|
-
}
|
|
80
|
-
// Process valid trigger
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
// ❌ Avoid - No validation
|
|
84
|
-
agent.on(AgentEvents.TRIGGER_EVENT, async ({ triggerBody }) => {
|
|
85
|
-
// Process without validation
|
|
86
|
-
});
|
|
87
|
-
```
|