@minded-ai/mindedjs 1.0.90 → 1.0.91-beta-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +13 -5
- package/dist/agent.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/nodes/addAppToolNode.d.ts.map +1 -1
- package/dist/nodes/addAppToolNode.js +2 -2
- package/dist/nodes/addAppToolNode.js.map +1 -1
- package/dist/nodes/addJumpToNode.d.ts.map +1 -1
- package/dist/nodes/addJumpToNode.js +2 -2
- package/dist/nodes/addJumpToNode.js.map +1 -1
- package/dist/nodes/addJunctionNode.d.ts +7 -0
- package/dist/nodes/addJunctionNode.d.ts.map +1 -0
- package/dist/nodes/addJunctionNode.js +20 -0
- package/dist/nodes/addJunctionNode.js.map +1 -0
- package/dist/nodes/addPromptNode.d.ts.map +1 -1
- package/dist/nodes/addPromptNode.js +2 -2
- package/dist/nodes/addPromptNode.js.map +1 -1
- package/dist/nodes/addToolNode.d.ts.map +1 -1
- package/dist/nodes/addToolNode.js +2 -2
- package/dist/nodes/addToolNode.js.map +1 -1
- package/dist/nodes/addToolRunNode.d.ts.map +1 -1
- package/dist/nodes/addToolRunNode.js +1 -2
- package/dist/nodes/addToolRunNode.js.map +1 -1
- package/dist/nodes/addTriggerNode.d.ts.map +1 -1
- package/dist/nodes/addTriggerNode.js +1 -2
- package/dist/nodes/addTriggerNode.js.map +1 -1
- package/dist/nodes/nodeFactory.d.ts.map +1 -1
- package/dist/nodes/nodeFactory.js +2 -5
- package/dist/nodes/nodeFactory.js.map +1 -1
- package/dist/types/Agent.types.d.ts +11 -6
- package/dist/types/Agent.types.d.ts.map +1 -1
- package/dist/types/Agent.types.js +1 -0
- package/dist/types/Agent.types.js.map +1 -1
- package/docs/.gitbook/assets/ADLC.png +0 -0
- package/docs/.gitbook/assets/PII-masking.png +0 -0
- package/docs/.gitbook/assets/image.png +0 -0
- package/docs/README.md +54 -0
- package/docs/SUMMARY.md +39 -0
- package/docs/examples/order-refund-flow.md +566 -0
- package/docs/getting-started/environment-configuration.md +98 -0
- package/docs/getting-started/installation.md +44 -0
- package/docs/getting-started/project-configuration.md +206 -0
- package/docs/getting-started/quick-start.md +262 -0
- package/docs/integrations/zendesk.md +554 -0
- package/docs/low-code-editor/edges.md +392 -0
- package/docs/low-code-editor/flows.md +74 -0
- package/docs/low-code-editor/nodes.md +331 -0
- package/docs/low-code-editor/playbooks.md +262 -0
- package/docs/low-code-editor/tools.md +303 -0
- package/docs/low-code-editor/triggers.md +156 -0
- package/docs/platform/events.md +374 -0
- package/docs/platform/logging.md +72 -0
- package/docs/platform/memory.md +219 -0
- package/docs/platform/pii-masking.md +220 -0
- package/docs/platform/secrets.md +99 -0
- package/docs/resources/your-first-eval.md +108 -0
- package/docs-structure.md +141 -0
- package/package.json +5 -3
- package/src/agent.ts +19 -12
- package/src/index.ts +0 -1
- package/src/nodes/addAppToolNode.ts +3 -3
- package/src/nodes/addJumpToNode.ts +3 -3
- package/src/nodes/addJunctionNode.ts +19 -0
- package/src/nodes/addPromptNode.ts +3 -3
- package/src/nodes/addToolNode.ts +2 -3
- package/src/nodes/addToolRunNode.ts +2 -3
- package/src/nodes/addTriggerNode.ts +3 -3
- package/src/nodes/nodeFactory.ts +1 -5
- package/src/types/Agent.types.ts +11 -5
|
@@ -0,0 +1,303 @@
|
|
|
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, state, agent }) => Promise<{ state?; 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, current state (including memory), and the agent instance, then returns updated state and/or result.
|
|
22
|
+
|
|
23
|
+
### Parameters
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
execute: ({ input, state, agent }) => Promise<{ state?; result? }>;
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
- **`input`**: Validated data matching your Zod schema - contains the parameters the LLM extracted from the conversation
|
|
30
|
+
- **`state`**: Current conversation state including memory, sessionId, and other context data
|
|
31
|
+
- **`agent`**: Agent instance providing access to PII gateway, logging, and other platform features
|
|
32
|
+
|
|
33
|
+
### Return Value
|
|
34
|
+
|
|
35
|
+
The execute function returns a Promise with an object containing:
|
|
36
|
+
|
|
37
|
+
- **`state?`** (optional): Updated state object that will be merged with existing state. This is a partial object - you only need to return the parts that changed
|
|
38
|
+
- **`result?`** (optional): Result that gets sent back to the LLM as the tool's response
|
|
39
|
+
|
|
40
|
+
## State Object Structure
|
|
41
|
+
|
|
42
|
+
The `state` object contains:
|
|
43
|
+
|
|
44
|
+
- **`memory`**: Your user-defined memory schema - the main working memory for your agent
|
|
45
|
+
- **`sessionId`**: Unique identifier for the current session
|
|
46
|
+
- **`messages`**: Array of conversation messages (AI, Human, System, etc.)
|
|
47
|
+
- **`history`**: Array of HistoryStep objects tracking the flow execution (node visits, trigger events, tool calls)
|
|
48
|
+
- **Other platform context**: Additional fields managed by the platform
|
|
49
|
+
|
|
50
|
+
## Basic Tool Example
|
|
51
|
+
|
|
52
|
+
Here's a simple refund processing tool:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { z } from 'zod';
|
|
56
|
+
import { Tool } from 'mindedjs/src/types/Tools.types';
|
|
57
|
+
import { logger } from 'mindedjs';
|
|
58
|
+
import memorySchema from '../schema';
|
|
59
|
+
|
|
60
|
+
type Memory = z.infer<typeof memorySchema>;
|
|
61
|
+
|
|
62
|
+
const schema = z.object({
|
|
63
|
+
orderId: z.string(),
|
|
64
|
+
customerName: z.string(),
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const refundOrderTool: Tool<typeof schema, Memory> = {
|
|
68
|
+
name: 'refundOrder',
|
|
69
|
+
description: 'Process a customer refund for their order',
|
|
70
|
+
input: schema,
|
|
71
|
+
execute: async ({ input, state, agent }) => {
|
|
72
|
+
// Access current memory
|
|
73
|
+
const currentMemory = state.memory;
|
|
74
|
+
|
|
75
|
+
// Use the provided logger
|
|
76
|
+
logger.info('Processing refund', {
|
|
77
|
+
sessionId: state.sessionId,
|
|
78
|
+
orderId: input.orderId,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Your business logic here
|
|
82
|
+
const refundAmount = await processRefundInSystem(input.orderId);
|
|
83
|
+
|
|
84
|
+
// Return partial state update - only the parts that changed
|
|
85
|
+
return {
|
|
86
|
+
state: {
|
|
87
|
+
memory: {
|
|
88
|
+
orderId: input.orderId,
|
|
89
|
+
customerName: input.customerName,
|
|
90
|
+
issue: `Refund processed: $${refundAmount}`,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
result: `Refund processed successfully for order ${input.orderId}`,
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export default refundOrderTool;
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Input Schema Configuration
|
|
102
|
+
|
|
103
|
+
Input schemas use Zod for validation and provide important metadata to help the LLM understand how to better use each input parameter.
|
|
104
|
+
|
|
105
|
+
### Parameter Descriptions
|
|
106
|
+
|
|
107
|
+
Add descriptions to parameters using Zod's `.describe()` method. These descriptions help the LLM understand what each parameter represents:
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
const schema = z.object({
|
|
111
|
+
orderId: z.string().describe('The unique identifier of the customer order to process'),
|
|
112
|
+
customerName: z.string().describe('Full name of the customer requesting the refund'),
|
|
113
|
+
refundAmount: z.number().describe('Amount to refund in dollars (optional if full refund)'),
|
|
114
|
+
reason: z.string().describe('Reason for the refund request'),
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Optional Parameters
|
|
119
|
+
|
|
120
|
+
Make parameters optional using Zod's `.optional()` method. Optional parameters don't need to be provided by the LLM:
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
const schema = z.object({
|
|
124
|
+
orderId: z.string().describe('The unique identifier of the customer order'),
|
|
125
|
+
customerName: z.string().describe('Full name of the customer'),
|
|
126
|
+
refundAmount: z.number().optional().describe('Specific refund amount, defaults to full order amount'),
|
|
127
|
+
expedited: z.boolean().optional().describe('Whether to expedite the refund process'),
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Combining Descriptions and Optional Parameters
|
|
132
|
+
|
|
133
|
+
You can chain Zod methods to create descriptive optional parameters:
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
const updateOrderSchema = z.object({
|
|
137
|
+
orderId: z.string().describe('The order ID that needs to be updated'),
|
|
138
|
+
newAddress: z.string().optional().describe('Updated shipping address if customer wants to change it'),
|
|
139
|
+
specialInstructions: z.string().optional().describe('Any special delivery instructions from the customer'),
|
|
140
|
+
urgentDelivery: z.boolean().optional().describe('Whether customer needs urgent delivery (additional charges may apply)'),
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Tool Registration
|
|
145
|
+
|
|
146
|
+
### Global Tools
|
|
147
|
+
|
|
148
|
+
Mark tools as global if you want them to be available in all LLM calls.
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
const auditLogTool: Tool<typeof auditSchema, Memory> = {
|
|
152
|
+
name: 'auditLog',
|
|
153
|
+
description: 'Log user action for compliance',
|
|
154
|
+
isGlobal: true, // Available in all flows
|
|
155
|
+
input: z.object({
|
|
156
|
+
action: z.string(),
|
|
157
|
+
details: z.string(),
|
|
158
|
+
}),
|
|
159
|
+
execute: async ({ input, state, agent }) => {
|
|
160
|
+
logger.info('Audit log entry', {
|
|
161
|
+
sessionId: state.sessionId,
|
|
162
|
+
action: input.action,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
await auditService.log({
|
|
166
|
+
userId: state.memory.userId,
|
|
167
|
+
action: input.action,
|
|
168
|
+
details: input.details,
|
|
169
|
+
timestamp: new Date(),
|
|
170
|
+
});
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## State Management
|
|
176
|
+
|
|
177
|
+
Tools can read and update state including memory:
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
const updateProfileTool: Tool<typeof profileSchema, Memory> = {
|
|
181
|
+
name: 'updateProfile',
|
|
182
|
+
description: 'Update customer profile information',
|
|
183
|
+
input: z.object({
|
|
184
|
+
field: z.string(),
|
|
185
|
+
value: z.string(),
|
|
186
|
+
}),
|
|
187
|
+
execute: async ({ input, state, agent }) => {
|
|
188
|
+
// Read current memory from state
|
|
189
|
+
console.log(`Current customer: ${state.memory.customerName}`);
|
|
190
|
+
|
|
191
|
+
// Update external system
|
|
192
|
+
await profileService.update(state.memory.customerId, {
|
|
193
|
+
[input.field]: input.value,
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// Return partial state update
|
|
197
|
+
return {
|
|
198
|
+
state: {
|
|
199
|
+
memory: {
|
|
200
|
+
[`${input.field}Updated`]: true,
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Error Handling
|
|
209
|
+
|
|
210
|
+
Handle errors gracefully in tools:
|
|
211
|
+
|
|
212
|
+
````ts
|
|
213
|
+
const paymentTool: Tool<typeof paymentSchema, Memory> = {
|
|
214
|
+
name: 'processPayment',
|
|
215
|
+
description: 'Process customer payment',
|
|
216
|
+
input: z.object({
|
|
217
|
+
amount: z.number(),
|
|
218
|
+
cardToken: z.string(),
|
|
219
|
+
}),
|
|
220
|
+
execute: async ({ input, state, agent }) => {
|
|
221
|
+
try {
|
|
222
|
+
const result = await paymentService.charge({
|
|
223
|
+
amount: input.amount,
|
|
224
|
+
cardToken: input.cardToken,
|
|
225
|
+
customerId: state.memory.customerId,
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
return {
|
|
229
|
+
result: `Payment successful: ${result.transactionId}`,
|
|
230
|
+
state: {
|
|
231
|
+
memory: { lastPaymentId: result.transactionId },
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
} catch (error) {
|
|
235
|
+
logger.error('Payment failed', {
|
|
236
|
+
sessionId: state.sessionId,
|
|
237
|
+
error: error.message,
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
return {
|
|
241
|
+
result: 'Payment failed. Please try again or contact support.',
|
|
242
|
+
state: {
|
|
243
|
+
memory: { paymentError: error.message },
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
## Best Practices
|
|
251
|
+
|
|
252
|
+
1. **Clear Descriptions**: Write descriptions that help the LLM understand when to use the tool
|
|
253
|
+
2. **Input Validation**: Use Zod schemas to validate all inputs
|
|
254
|
+
3. **State Updates**: Return partial state updates - only include the parts that changed
|
|
255
|
+
4. **Error Handling**: Always handle errors gracefully and provide meaningful messages
|
|
256
|
+
5. **Async Operations**: Use async/await for external API calls and database operations
|
|
257
|
+
6. **Logging**: Use the provided logger for consistent, structured logging with session context
|
|
258
|
+
|
|
259
|
+
## Tool Nodes
|
|
260
|
+
|
|
261
|
+
Tool nodes force execution of specific tools at defined points in your flow, bypassing LLM decision-making.
|
|
262
|
+
|
|
263
|
+
### Configuration
|
|
264
|
+
|
|
265
|
+
```yaml
|
|
266
|
+
nodes:
|
|
267
|
+
- name: 'Force Refund Processing'
|
|
268
|
+
type: 'tool'
|
|
269
|
+
toolName: 'refundOrder'
|
|
270
|
+
````
|
|
271
|
+
|
|
272
|
+
### Tool Node vs Automatic Tool Calls
|
|
273
|
+
|
|
274
|
+
| Feature | Tool Nodes | Automatic Tool Calls |
|
|
275
|
+
| ------------- | ------------------------------- | ----------------------------------- |
|
|
276
|
+
| **Execution** | Guaranteed when node is reached | Only when LLM decides to call |
|
|
277
|
+
| **Control** | Explicit flow control | LLM-driven decision |
|
|
278
|
+
| **Use Case** | Required business logic steps | Flexible, context-dependent actions |
|
|
279
|
+
|
|
280
|
+
### Example
|
|
281
|
+
|
|
282
|
+
```yaml
|
|
283
|
+
nodes:
|
|
284
|
+
- name: 'Customer Support Start'
|
|
285
|
+
type: 'prompt'
|
|
286
|
+
prompt: 'How can I help you today?'
|
|
287
|
+
- name: 'Log Interaction'
|
|
288
|
+
type: 'tool'
|
|
289
|
+
toolName: 'auditLog'
|
|
290
|
+
|
|
291
|
+
edges:
|
|
292
|
+
- source: 'Customer Support Start'
|
|
293
|
+
target: 'Log Interaction'
|
|
294
|
+
type: 'always'
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### Best Practices
|
|
298
|
+
|
|
299
|
+
1. **Strategic Placement**: Use for critical business logic that must always execute
|
|
300
|
+
2. **Clear Context**: Ensure conversation provides context for parameter extraction
|
|
301
|
+
3. **Error Handling**: Handle errors gracefully since they bypass LLM error recovery
|
|
302
|
+
|
|
303
|
+
Tool parameters are automatically extracted from conversation context and memory state using an internal LLM agent.
|
|
@@ -0,0 +1,156 @@
|
|
|
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
|
+
MindedJS supports three types of triggers:
|
|
8
|
+
|
|
9
|
+
### 1. Manual Triggers
|
|
10
|
+
|
|
11
|
+
- **Invocation**: Triggered directly by calling the `agent.invoke()` method in your code
|
|
12
|
+
- **Use Case**: Perfect for testing or programmatic agent invocation
|
|
13
|
+
- **Setup**: No platform configuration required - simply call the method with your parameters
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
// Manual trigger example
|
|
17
|
+
const result = await agent.invoke({
|
|
18
|
+
triggerName: 'manual-trigger',
|
|
19
|
+
triggerBody: { message: 'Hello agent' },
|
|
20
|
+
sessionId: 'user-session-123',
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### 2. App Triggers
|
|
25
|
+
|
|
26
|
+
- **Invocation**: Triggered by specific applications and external integrations (e.g., Slack, Zendesk)
|
|
27
|
+
- **Setup**: Configured through the Minded platform interface
|
|
28
|
+
- **Identification**: Each app trigger is identified by a unique `appTriggerId`
|
|
29
|
+
- **Data Handling**: Supports automatic message conversion for certain apps (e.g., Slack messages)
|
|
30
|
+
|
|
31
|
+
### 3. Webhook Triggers
|
|
32
|
+
|
|
33
|
+
- **Invocation**: Triggered by HTTP requests to specific endpoints in the Minded platform
|
|
34
|
+
- **Setup**: Configured through the Minded platform interface
|
|
35
|
+
- **Agent Specific**: Each webhook trigger belongs to a specific agent and cannot be shared between agents
|
|
36
|
+
- **Use Case**: Ideal for receiving data from external systems, APIs, or third-party services that can send HTTP requests
|
|
37
|
+
|
|
38
|
+
> **Note**: Both app triggers and webhook triggers are configured and managed through the Minded platform. All triggers are agent-specific and cannot be shared between different agents.
|
|
39
|
+
|
|
40
|
+
### Trigger Invocation History
|
|
41
|
+
|
|
42
|
+
When a trigger is invoked, it creates a comprehensive record of the event that is:
|
|
43
|
+
|
|
44
|
+
1. Added to the flow history for tracking and debugging
|
|
45
|
+
2. Preserved throughout the flow's execution as a history step
|
|
46
|
+
|
|
47
|
+
This history allows tools and handlers to:
|
|
48
|
+
|
|
49
|
+
- Access the original trigger context
|
|
50
|
+
- Make decisions based on the triggering event
|
|
51
|
+
- Maintain conversation continuity
|
|
52
|
+
- Debug flow execution
|
|
53
|
+
- Track the agent's execution path through different nodes
|
|
54
|
+
|
|
55
|
+
Each history step contains the following information:
|
|
56
|
+
|
|
57
|
+
- `step`: Sequential step number in the agent's execution flow
|
|
58
|
+
- `type`: Type of the step (TRIGGER_NODE, APP_TRIGGER_NODE, TOOL_NODE, etc.)
|
|
59
|
+
- `nodeId`: ID of the node that was executed
|
|
60
|
+
- `nodeDisplayName`: Human-readable name of the node
|
|
61
|
+
- `raw`: Raw data associated with the step (e.g., trigger input, tool output)
|
|
62
|
+
- `messageIds`: IDs of messages associated with this step
|
|
63
|
+
|
|
64
|
+
Example:
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
const tool: Tool = {
|
|
68
|
+
name: 'myTool',
|
|
69
|
+
execute: async ({ input, state }) => {
|
|
70
|
+
// Access trigger information from history
|
|
71
|
+
const triggerStep = state.history.find((step) => step.type === 'TRIGGER_NODE' || step.type === 'APP_TRIGGER_NODE');
|
|
72
|
+
|
|
73
|
+
if (triggerStep) {
|
|
74
|
+
console.log(`Processing request from node: ${triggerStep.nodeDisplayName}`);
|
|
75
|
+
|
|
76
|
+
// Handle different trigger types based on history
|
|
77
|
+
if (triggerStep.nodeDisplayName === 'manual-trigger') {
|
|
78
|
+
// Handle manual trigger
|
|
79
|
+
console.log('Manual trigger data:', triggerStep.raw);
|
|
80
|
+
} else if (triggerStep.type === 'APP_TRIGGER_NODE' && triggerStep.appName === 'Slack') {
|
|
81
|
+
// Handle app trigger from Slack
|
|
82
|
+
console.log('Slack trigger data:', triggerStep.raw);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return { result: 'Success' };
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Default Message Behavior
|
|
92
|
+
|
|
93
|
+
MindedJS provides intelligent message handling for a few app triggers through the `triggerTypeToDefaultMessage` mapping. This system:
|
|
94
|
+
|
|
95
|
+
- Automatically converts trigger data into appropriate message formats
|
|
96
|
+
- Maintains conversation context without manual intervention
|
|
97
|
+
- Supports different message types for different applications
|
|
98
|
+
- Can be overridden using the `onTriggerEvent` handler
|
|
99
|
+
|
|
100
|
+
Currently supported default messages:
|
|
101
|
+
|
|
102
|
+
- **App Triggers (Slack)**: For "New Direct Message (Instant)" triggers, the message text is automatically converted to a human message
|
|
103
|
+
- **Manual Triggers**: No automatic message conversion - you control the flow entirely
|
|
104
|
+
- **Webhook Triggers**: Flexible message handling based on the HTTP payload structure
|
|
105
|
+
|
|
106
|
+
Example:
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
// Manual trigger - full control over the flow
|
|
110
|
+
const manualResult = await agent.invoke({
|
|
111
|
+
triggerName: 'manual-trigger',
|
|
112
|
+
triggerBody: { customData: 'Hello manually' },
|
|
113
|
+
sessionId: 'manual-session-123',
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// App trigger (Slack) - automatic message conversion
|
|
117
|
+
const slackResult = await agent.invoke({
|
|
118
|
+
triggerName: 'New Direct Message (Instant)',
|
|
119
|
+
triggerBody: { text: 'Hello from Slack' },
|
|
120
|
+
appName: 'Slack',
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// Webhook trigger - handled based on HTTP payload
|
|
124
|
+
const webhookResult = await agent.invoke({
|
|
125
|
+
triggerName: 'webhook-endpoint-name',
|
|
126
|
+
triggerBody: { payload: 'Hello from webhook' },
|
|
127
|
+
appName: 'Webhook',
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Validate Trigger Input
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
// ✅ Good - Input validation
|
|
135
|
+
agent.on(AgentEvents.TRIGGER_EVENT, async ({ triggerName, triggerBody, sessionId }) => {
|
|
136
|
+
if (!triggerBody.customerId || !triggerBody.message) {
|
|
137
|
+
return { isQualified: false }; // Disqualify invalid triggers
|
|
138
|
+
}
|
|
139
|
+
// Process valid trigger
|
|
140
|
+
return { isQualified: true };
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// ❌ Avoid - No validation
|
|
144
|
+
agent.on(AgentEvents.TRIGGER_EVENT, async ({ triggerBody, sessionId }) => {
|
|
145
|
+
// Process without validation
|
|
146
|
+
return { isQualified: true };
|
|
147
|
+
});
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Session ID in Trigger Events
|
|
151
|
+
|
|
152
|
+
The `sessionId` parameter in `TRIGGER_EVENT` is automatically provided by the platform in different environments:
|
|
153
|
+
|
|
154
|
+
- **Sandbox Playground**: The platform automatically generates and provides a default `sessionId` for each trigger execution. It's important to pass it forward in sandbox environment.
|
|
155
|
+
- **Production Applications**: Users are expected to provide their own `sessionId` if they wish to suppport resuming sessions.
|
|
156
|
+
- **Session Continuity**: When a `sessionId` is provided that matches an existing session, the agent will resume from the previous state instead of starting fresh
|