@minded-ai/mindedjs 1.0.103-beta-1 → 1.0.103-beta-4
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 +44 -31
- package/dist/agent.js.map +1 -1
- package/dist/browserTask/executeBrowserTask.d.ts +12 -0
- package/dist/browserTask/executeBrowserTask.d.ts.map +1 -0
- package/dist/browserTask/executeBrowserTask.js +181 -0
- package/dist/browserTask/executeBrowserTask.js.map +1 -0
- package/dist/checkpointer/checkpointSaverFactory.js +1 -1
- package/dist/checkpointer/checkpointSaverFactory.js.map +1 -1
- package/dist/cli/index.js +14 -14
- package/dist/cli/index.js.map +1 -1
- package/dist/edges/createDirectEdge.d.ts +2 -1
- package/dist/edges/createDirectEdge.d.ts.map +1 -1
- package/dist/edges/createDirectEdge.js +6 -2
- package/dist/edges/createDirectEdge.js.map +1 -1
- package/dist/edges/createLogicalRouter.d.ts.map +1 -1
- package/dist/edges/createLogicalRouter.js +23 -6
- package/dist/edges/createLogicalRouter.js.map +1 -1
- package/dist/edges/createPromptRouter.d.ts.map +1 -1
- package/dist/edges/createPromptRouter.js +12 -6
- package/dist/edges/createPromptRouter.js.map +1 -1
- package/dist/edges/edgeFactory.d.ts.map +1 -1
- package/dist/edges/edgeFactory.js +8 -3
- package/dist/edges/edgeFactory.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/interrupts/BaseInterruptSessionManager.d.ts +4 -0
- package/dist/interrupts/BaseInterruptSessionManager.d.ts.map +1 -1
- package/dist/interrupts/BaseInterruptSessionManager.js +1 -1
- package/dist/interrupts/BaseInterruptSessionManager.js.map +1 -1
- package/dist/interrupts/MemoryInterruptSessionManager.d.ts +2 -0
- package/dist/interrupts/MemoryInterruptSessionManager.d.ts.map +1 -1
- package/dist/interrupts/MemoryInterruptSessionManager.js +6 -0
- package/dist/interrupts/MemoryInterruptSessionManager.js.map +1 -1
- package/dist/interrupts/MindedInterruptSessionManager.d.ts +2 -0
- package/dist/interrupts/MindedInterruptSessionManager.d.ts.map +1 -1
- package/dist/interrupts/MindedInterruptSessionManager.js +26 -0
- package/dist/interrupts/MindedInterruptSessionManager.js.map +1 -1
- package/dist/interrupts/interruptSessionManagerFactory.js +2 -2
- package/dist/interrupts/interruptSessionManagerFactory.js.map +1 -1
- package/dist/llm/createLlmInstance.d.ts +1 -1
- package/dist/llm/createLlmInstance.d.ts.map +1 -1
- package/dist/llm/createLlmInstance.js +18 -1
- package/dist/llm/createLlmInstance.js.map +1 -1
- package/dist/nodes/addAppToolNode.d.ts.map +1 -1
- package/dist/nodes/addAppToolNode.js +5 -4
- package/dist/nodes/addAppToolNode.js.map +1 -1
- package/dist/nodes/addBrowserTaskNode.d.ts +13 -0
- package/dist/nodes/addBrowserTaskNode.d.ts.map +1 -0
- package/dist/nodes/addBrowserTaskNode.js +232 -0
- package/dist/nodes/addBrowserTaskNode.js.map +1 -0
- package/dist/nodes/addBrowserTaskRunNode.d.ts +13 -0
- package/dist/nodes/addBrowserTaskRunNode.d.ts.map +1 -0
- package/dist/nodes/addBrowserTaskRunNode.js +130 -0
- package/dist/nodes/addBrowserTaskRunNode.js.map +1 -0
- package/dist/nodes/addHumanInTheLoopNode.d.ts.map +1 -1
- package/dist/nodes/addHumanInTheLoopNode.js +1 -1
- package/dist/nodes/addHumanInTheLoopNode.js.map +1 -1
- package/dist/nodes/addJumpToNode.d.ts.map +1 -1
- package/dist/nodes/addJumpToNode.js +2 -1
- package/dist/nodes/addJumpToNode.js.map +1 -1
- package/dist/nodes/addJunctionNode.d.ts.map +1 -1
- package/dist/nodes/addJunctionNode.js +1 -0
- package/dist/nodes/addJunctionNode.js.map +1 -1
- package/dist/nodes/addPromptNode.d.ts.map +1 -1
- package/dist/nodes/addPromptNode.js +7 -17
- 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 +2 -1
- package/dist/nodes/addToolRunNode.js.map +1 -1
- package/dist/nodes/addTriggerNode.d.ts.map +1 -1
- package/dist/nodes/addTriggerNode.js +2 -1
- package/dist/nodes/addTriggerNode.js.map +1 -1
- package/dist/nodes/nodeFactory.d.ts.map +1 -1
- package/dist/nodes/nodeFactory.js +4 -0
- package/dist/nodes/nodeFactory.js.map +1 -1
- package/dist/platform/mindedConnection.js +13 -13
- package/dist/platform/mindedConnection.js.map +1 -1
- package/dist/platform/mindedConnectionTypes.d.ts +3 -1
- package/dist/platform/mindedConnectionTypes.d.ts.map +1 -1
- package/dist/platform/mindedConnectionTypes.js +2 -0
- package/dist/platform/mindedConnectionTypes.js.map +1 -1
- package/dist/platform/models/mindedChatOpenAI.d.ts +20 -0
- package/dist/platform/models/mindedChatOpenAI.d.ts.map +1 -0
- package/dist/platform/models/mindedChatOpenAI.js +32 -0
- package/dist/platform/models/mindedChatOpenAI.js.map +1 -0
- package/dist/platform/models/parallelWrapper.d.ts +17 -0
- package/dist/platform/models/parallelWrapper.d.ts.map +1 -0
- package/dist/platform/models/parallelWrapper.js +105 -0
- package/dist/platform/models/parallelWrapper.js.map +1 -0
- package/dist/playbooks/playbooks.js +6 -6
- package/dist/playbooks/playbooks.js.map +1 -1
- package/dist/types/Flows.types.d.ts +18 -3
- package/dist/types/Flows.types.d.ts.map +1 -1
- package/dist/types/Flows.types.js +2 -0
- package/dist/types/Flows.types.js.map +1 -1
- package/dist/types/LLM.types.d.ts.map +1 -1
- package/dist/types/LLM.types.js +1 -1
- package/dist/types/LLM.types.js.map +1 -1
- package/dist/types/LangGraph.types.d.ts +2 -0
- package/dist/types/LangGraph.types.d.ts.map +1 -1
- package/dist/types/LangGraph.types.js +5 -0
- package/dist/types/LangGraph.types.js.map +1 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +1 -2
- package/dist/utils/logger.js.map +1 -1
- package/dist/voice/voiceSession.d.ts.map +1 -1
- package/dist/voice/voiceSession.js +19 -18
- package/dist/voice/voiceSession.js.map +1 -1
- package/docs/SUMMARY.md +1 -0
- package/docs/low-code-editor/nodes.md +27 -0
- package/docs/low-code-editor/tools.md +32 -0
- package/docs/platform/parallel-llm.md +242 -0
- package/package.json +2 -1
- package/src/agent.ts +45 -33
- package/src/browserTask/executeBrowserTask.ts +213 -0
- package/src/checkpointer/checkpointSaverFactory.ts +1 -1
- package/src/cli/index.ts +14 -14
- package/src/edges/createDirectEdge.ts +7 -2
- package/src/edges/createLogicalRouter.ts +23 -6
- package/src/edges/createPromptRouter.ts +13 -6
- package/src/edges/edgeFactory.ts +20 -4
- package/src/index.ts +6 -0
- package/src/interrupts/BaseInterruptSessionManager.ts +5 -2
- package/src/interrupts/MemoryInterruptSessionManager.ts +8 -0
- package/src/interrupts/MindedInterruptSessionManager.ts +25 -0
- package/src/interrupts/interruptSessionManagerFactory.ts +2 -2
- package/src/llm/createLlmInstance.ts +25 -2
- package/src/nodes/addAppToolNode.ts +5 -4
- package/src/nodes/addBrowserTaskNode.ts +231 -0
- package/src/nodes/addBrowserTaskRunNode.ts +144 -0
- package/src/nodes/addHumanInTheLoopNode.ts +2 -1
- package/src/nodes/addJumpToNode.ts +2 -1
- package/src/nodes/addJunctionNode.ts +1 -0
- package/src/nodes/addPromptNode.ts +8 -16
- package/src/nodes/addToolNode.ts +3 -2
- package/src/nodes/addToolRunNode.ts +3 -1
- package/src/nodes/addTriggerNode.ts +2 -1
- package/src/nodes/nodeFactory.ts +5 -1
- package/src/platform/mindedConnection.ts +13 -13
- package/src/platform/mindedConnectionTypes.ts +2 -0
- package/src/platform/models/mindedChatOpenAI.ts +49 -0
- package/src/platform/models/parallelWrapper.ts +141 -0
- package/src/playbooks/playbooks.ts +6 -6
- package/src/types/Flows.types.ts +17 -1
- package/src/types/LLM.types.ts +5 -5
- package/src/types/LangGraph.types.ts +5 -0
- package/src/utils/logger.ts +1 -2
- package/src/voice/voiceSession.ts +20 -19
- package/src/platform/mindedChatOpenAI.ts +0 -19
|
@@ -322,6 +322,33 @@ nodes:
|
|
|
322
322
|
prompt: 'Help the customer with anything they need'
|
|
323
323
|
```
|
|
324
324
|
|
|
325
|
+
## Browser Task Nodes
|
|
326
|
+
|
|
327
|
+
Browser task nodes allow your agent to interact with web pages using AI-powered automation.
|
|
328
|
+
|
|
329
|
+
### Basic Browser Task
|
|
330
|
+
|
|
331
|
+
```yaml
|
|
332
|
+
- type: browserTask
|
|
333
|
+
name: search_products
|
|
334
|
+
displayName: Search Products
|
|
335
|
+
prompt: 'Go to amazon.com and search for wireless headphones under $100'
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### Browser Task with Custom Model
|
|
339
|
+
|
|
340
|
+
You can specify which AI model to use for browser automation:
|
|
341
|
+
|
|
342
|
+
```yaml
|
|
343
|
+
- type: browserTask
|
|
344
|
+
name: complex_task
|
|
345
|
+
displayName: Complex Web Task
|
|
346
|
+
prompt: 'Navigate to the support page and fill out the contact form'
|
|
347
|
+
model: 'gpt-4o' # Options: gpt-4o (default), gpt-4-turbo, claude-3-opus, etc.
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
The browser task will execute the prompt using the browser-use CLI tool, which provides AI-powered browser automation capabilities.
|
|
351
|
+
|
|
325
352
|
## Next Steps
|
|
326
353
|
|
|
327
354
|
* [**Edges**](edges.md) - Connect nodes with intelligent routing
|
|
@@ -247,6 +247,38 @@ const paymentTool: Tool<typeof paymentSchema, Memory> = {
|
|
|
247
247
|
},
|
|
248
248
|
};
|
|
249
249
|
|
|
250
|
+
## Flow Control with goto
|
|
251
|
+
|
|
252
|
+
Tools can control the flow by returning a `goto` property in their state update. This allows tools to programmatically move the conversation to a specific node.
|
|
253
|
+
|
|
254
|
+
### Basic goto Usage
|
|
255
|
+
|
|
256
|
+
```ts
|
|
257
|
+
const moveToAnotherRepresentativeTool: Tool<typeof schema, Memory> = {
|
|
258
|
+
name: 'moveToAnotherRepresentative',
|
|
259
|
+
description: 'Transfer the conversation to another representative or department',
|
|
260
|
+
input: schema,
|
|
261
|
+
execute: async ({ input, state }) => {
|
|
262
|
+
logger.info({
|
|
263
|
+
message: 'Moving conversation to another representative',
|
|
264
|
+
sessionId: state.sessionId,
|
|
265
|
+
department: input.department,
|
|
266
|
+
reason: input.reason,
|
|
267
|
+
priority: input.priority,
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
return {
|
|
271
|
+
state: {
|
|
272
|
+
goto: 'share-new-representative',
|
|
273
|
+
memory: {
|
|
274
|
+
orderId: 'share-new-representative',
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
```
|
|
281
|
+
|
|
250
282
|
## Best Practices
|
|
251
283
|
|
|
252
284
|
1. **Clear Descriptions**: Write descriptions that help the LLM understand when to use the tool
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
# Parallel LLM Requests
|
|
2
|
+
|
|
3
|
+
Parallel LLM requests can significantly reduce latency by sending multiple identical requests and using the fastest response. This feature can reduce response times by 30-50% in scenarios with variable network conditions.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
The easiest way to enable parallel requests is through your `minded.json` configuration:
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
{
|
|
11
|
+
"flows": ["./src/flows"],
|
|
12
|
+
"tools": ["./src/tools"],
|
|
13
|
+
"agent": "./src/agent.ts",
|
|
14
|
+
"llm": {
|
|
15
|
+
"name": "MindedChatOpenAI",
|
|
16
|
+
"properties": {
|
|
17
|
+
"model": "gpt-4o",
|
|
18
|
+
"numParallelRequests": 3,
|
|
19
|
+
"logTimings": true
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Your agent will automatically use parallel requests for all LLM calls:
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { Agent } from '@minded-ai/mindedjs';
|
|
29
|
+
import memorySchema from './agentMemorySchema';
|
|
30
|
+
import config from '../minded.json';
|
|
31
|
+
import tools from './tools';
|
|
32
|
+
|
|
33
|
+
const agent = new Agent({
|
|
34
|
+
memorySchema,
|
|
35
|
+
config, // Parallel configuration is automatically applied
|
|
36
|
+
tools,
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Configuration Options
|
|
41
|
+
|
|
42
|
+
### MindedChatOpenAI (Recommended)
|
|
43
|
+
|
|
44
|
+
For agents running on the Minded platform, use `MindedChatOpenAI` with parallel configuration:
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"llm": {
|
|
49
|
+
"name": "MindedChatOpenAI",
|
|
50
|
+
"properties": {
|
|
51
|
+
"model": "gpt-4o",
|
|
52
|
+
"numParallelRequests": 3,
|
|
53
|
+
"logTimings": true,
|
|
54
|
+
"temperature": 0.7
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### AzureChatOpenAI
|
|
61
|
+
|
|
62
|
+
For Azure OpenAI deployments:
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"llm": {
|
|
67
|
+
"name": "AzureChatOpenAI",
|
|
68
|
+
"properties": {
|
|
69
|
+
"model": "gpt-4o",
|
|
70
|
+
"numParallelRequests": 3,
|
|
71
|
+
"logTimings": true,
|
|
72
|
+
"azureOpenAIApiVersion": "2024-02-01"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Required environment variables:
|
|
79
|
+
|
|
80
|
+
```env
|
|
81
|
+
AZURE_OPENAI_API_KEY=your_azure_key
|
|
82
|
+
AZURE_OPENAI_API_INSTANCE_NAME=your_instance_name
|
|
83
|
+
AZURE_OPENAI_API_DEPLOYMENT_NAME=your_deployment_name
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### ChatOpenAI
|
|
87
|
+
|
|
88
|
+
For standard OpenAI API:
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"llm": {
|
|
93
|
+
"name": "ChatOpenAI",
|
|
94
|
+
"properties": {
|
|
95
|
+
"model": "gpt-4o",
|
|
96
|
+
"numParallelRequests": 3,
|
|
97
|
+
"logTimings": true,
|
|
98
|
+
"openAIApiKey": "${OPENAI_API_KEY}"
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Configuration Parameters
|
|
105
|
+
|
|
106
|
+
| Parameter | Type | Default | Description |
|
|
107
|
+
| --------------------- | ------- | ------- | --------------------------------------------- |
|
|
108
|
+
| `numParallelRequests` | number | 1 | Number of parallel requests (2-5 recommended) |
|
|
109
|
+
| `logTimings` | boolean | false | Enable detailed timing logs |
|
|
110
|
+
|
|
111
|
+
## Performance Notes
|
|
112
|
+
|
|
113
|
+
- **Optimal Range**: 2-3 parallel requests usually provide the best latency/cost balance
|
|
114
|
+
- **Cost Impact**: You pay for all parallel requests made
|
|
115
|
+
- **Best Use Cases**: Variable network conditions, consistency requirements
|
|
116
|
+
- **Latency Reduction**: Typically 30-50% faster response times
|
|
117
|
+
|
|
118
|
+
## Monitoring Performance
|
|
119
|
+
|
|
120
|
+
When `logTimings: true` is enabled, you'll see detailed performance logs:
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
[Model] Fastest request completed { requestTime: 1.234, numParallelRequests: 3 }
|
|
124
|
+
[Model] Time saved using parallel requests {
|
|
125
|
+
fastestRequestTime: 1.234,
|
|
126
|
+
secondFastestRequestTime: 1.567,
|
|
127
|
+
allFinishTime: 2.345,
|
|
128
|
+
timeSaved: 1.111,
|
|
129
|
+
timeSavedFromSecond: 0.333
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Advanced Usage
|
|
134
|
+
|
|
135
|
+
### Dynamic Configuration
|
|
136
|
+
|
|
137
|
+
You can adjust parallel requests based on environment:
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{
|
|
141
|
+
"llm": {
|
|
142
|
+
"name": "MindedChatOpenAI",
|
|
143
|
+
"properties": {
|
|
144
|
+
"model": "gpt-4o",
|
|
145
|
+
"numParallelRequests": "${NODE_ENV === 'production' ? 3 : 1}",
|
|
146
|
+
"logTimings": "${NODE_ENV === 'development'}"
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Manual Instantiation with createParallelWrapper
|
|
153
|
+
|
|
154
|
+
For advanced use cases where you need direct control over the LLM instance, you can manually apply parallel wrapping:
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { createParallelWrapper } from '@minded-ai/mindedjs';
|
|
158
|
+
import { ChatOpenAI, AzureChatOpenAI } from '@langchain/openai';
|
|
159
|
+
|
|
160
|
+
// Manual wrapping for ChatOpenAI
|
|
161
|
+
const parallelOpenAI = createParallelWrapper(
|
|
162
|
+
new ChatOpenAI({
|
|
163
|
+
openAIApiKey: process.env.OPENAI_API_KEY,
|
|
164
|
+
model: 'gpt-4o',
|
|
165
|
+
temperature: 0.7,
|
|
166
|
+
}),
|
|
167
|
+
{
|
|
168
|
+
numParallelRequests: 3,
|
|
169
|
+
logTimings: true,
|
|
170
|
+
},
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
// Manual wrapping for AzureChatOpenAI
|
|
174
|
+
const parallelAzure = createParallelWrapper(
|
|
175
|
+
new AzureChatOpenAI({
|
|
176
|
+
azureOpenAIApiKey: process.env.AZURE_OPENAI_API_KEY,
|
|
177
|
+
azureOpenAIApiInstanceName: process.env.AZURE_OPENAI_INSTANCE!,
|
|
178
|
+
azureOpenAIApiDeploymentName: process.env.AZURE_OPENAI_DEPLOYMENT!,
|
|
179
|
+
azureOpenAIApiVersion: '2024-02-01',
|
|
180
|
+
}),
|
|
181
|
+
{
|
|
182
|
+
numParallelRequests: 2,
|
|
183
|
+
logTimings: false,
|
|
184
|
+
},
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
// Use directly with Agent (bypassing configuration)
|
|
188
|
+
const agent = new Agent({
|
|
189
|
+
memorySchema,
|
|
190
|
+
config: {
|
|
191
|
+
flows: ['./flows'],
|
|
192
|
+
tools: [],
|
|
193
|
+
llm: parallelOpenAI as any, // Direct LLM instance
|
|
194
|
+
},
|
|
195
|
+
tools: [],
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
**Note**: The configuration-based approach is recommended for most use cases as it's simpler and more maintainable. Use manual instantiation only when you need specific control over LLM creation or are integrating with existing LangChain workflows.
|
|
200
|
+
|
|
201
|
+
## How It Works
|
|
202
|
+
|
|
203
|
+
### MindedChatOpenAI (Backend Processing)
|
|
204
|
+
|
|
205
|
+
- Parallel requests are handled on the Minded platform backend
|
|
206
|
+
- Multiple requests sent to Azure OpenAI from the backend
|
|
207
|
+
- Fastest response returned to your agent
|
|
208
|
+
- Optimal for production deployments
|
|
209
|
+
|
|
210
|
+
### Other LLM Providers (Client-Side Processing)
|
|
211
|
+
|
|
212
|
+
- Parallel requests handled in your application
|
|
213
|
+
- Multiple requests sent directly to the LLM provider
|
|
214
|
+
- Good for development and custom deployments
|
|
215
|
+
|
|
216
|
+
## Best Practices
|
|
217
|
+
|
|
218
|
+
1. **Start Small**: Begin with 2-3 parallel requests
|
|
219
|
+
2. **Monitor Costs**: Each parallel request counts toward your usage
|
|
220
|
+
3. **Enable Logging**: Use `logTimings: true` during development to measure improvements
|
|
221
|
+
4. **Environment-Specific**: Use fewer parallel requests in development
|
|
222
|
+
5. **Configuration Over Code**: Prefer `minded.json` configuration over manual instantiation
|
|
223
|
+
|
|
224
|
+
## Troubleshooting
|
|
225
|
+
|
|
226
|
+
### No Performance Improvement
|
|
227
|
+
|
|
228
|
+
- Check network latency variability
|
|
229
|
+
- Ensure `numParallelRequests > 1`
|
|
230
|
+
- Verify timing logs are showing multiple requests
|
|
231
|
+
|
|
232
|
+
### Increased Costs
|
|
233
|
+
|
|
234
|
+
- Reduce `numParallelRequests`
|
|
235
|
+
- Consider cost vs. latency trade-offs
|
|
236
|
+
- Monitor usage patterns
|
|
237
|
+
|
|
238
|
+
### Rate Limiting
|
|
239
|
+
|
|
240
|
+
- Lower `numParallelRequests`
|
|
241
|
+
- Implement backoff strategies
|
|
242
|
+
- Contact provider about rate limits
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@minded-ai/mindedjs",
|
|
3
|
-
"version": "1.0.103-beta-
|
|
3
|
+
"version": "1.0.103-beta-4",
|
|
4
4
|
"description": "MindedJS is a TypeScript library for building agents.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"order-refund": "cd examples/orderRefundAgent && nodemon --watch '**/*.ts' --exec 'ts-node' orderRefundAgent.ts",
|
|
22
22
|
"zendesk": "cd examples/zendesk && nodemon --watch '**/*.ts' --exec 'ts-node' zendeskAgent.ts",
|
|
23
23
|
"example-voice": "cd examples/voice && nodemon --watch '**/*.ts' --exec 'ts-node' voiceAgent.ts",
|
|
24
|
+
"example-browser": "cd examples/browserUsingAgent && nodemon --watch '**/*.ts' --exec 'ts-node' browserUsingAgent.ts",
|
|
24
25
|
"lint": "eslint .",
|
|
25
26
|
"lintFix": "eslint --fix .",
|
|
26
27
|
"generateApiDocs": "typedoc src --out docs/api-reference ./src"
|
package/src/agent.ts
CHANGED
|
@@ -304,9 +304,17 @@ export class Agent {
|
|
|
304
304
|
|
|
305
305
|
// Add edge from start to first node if no triggers exist
|
|
306
306
|
const hasTrigger = nodes.some((node) => node.type === NodeType.TRIGGER && node.triggerType !== TriggerType.MANUAL);
|
|
307
|
-
if (!hasTrigger
|
|
308
|
-
|
|
309
|
-
|
|
307
|
+
if (!hasTrigger) {
|
|
308
|
+
// Find the Main flow
|
|
309
|
+
const mainFlow = this.flows.find((flow) => flow.name === 'Main flow');
|
|
310
|
+
if (mainFlow && mainFlow.nodes.length > 0) {
|
|
311
|
+
this.startingNodeId = mainFlow.nodes[0].name;
|
|
312
|
+
graph.addEdge('__start__', mainFlow.nodes[0].name as any);
|
|
313
|
+
} else if (nodes.length > 0) {
|
|
314
|
+
// Fallback to first node if Main flow not found
|
|
315
|
+
this.startingNodeId = nodes[0].name;
|
|
316
|
+
graph.addEdge('__start__', nodes[0].name as any);
|
|
317
|
+
}
|
|
310
318
|
} else {
|
|
311
319
|
nodes.forEach((node) => {
|
|
312
320
|
if (node.type === NodeType.TRIGGER && node.triggerType !== TriggerType.MANUAL) {
|
|
@@ -348,6 +356,7 @@ export class Agent {
|
|
|
348
356
|
sessionId: state.sessionId || uuidv4(), // Preserve existing sessionId or generate new one
|
|
349
357
|
sessionType: state.sessionType || SessionType.TEXT,
|
|
350
358
|
overrideStartFromNodeId: null,
|
|
359
|
+
goto: null,
|
|
351
360
|
};
|
|
352
361
|
|
|
353
362
|
// Emit INIT event with the initial state
|
|
@@ -421,7 +430,7 @@ export class Agent {
|
|
|
421
430
|
// Try to acquire lock atomically (unless bypassing session check)
|
|
422
431
|
if (!bypassSessionCheck && !(await this.interruptSessionManager.lock(sessionId))) {
|
|
423
432
|
// Could not acquire lock, session is being processed - enqueue the message
|
|
424
|
-
logger.info({
|
|
433
|
+
logger.info({ msg: 'Enqueuing message', sessionId, triggerBody, triggerName, appName });
|
|
425
434
|
await this.interruptSessionManager.enqueueMessage(sessionId, {
|
|
426
435
|
triggerBody,
|
|
427
436
|
triggerName,
|
|
@@ -458,7 +467,7 @@ export class Agent {
|
|
|
458
467
|
const handlerResult = results.find((r) => r !== undefined);
|
|
459
468
|
if (handlerResult) {
|
|
460
469
|
if (!handlerResult.isQualified) {
|
|
461
|
-
logger.info({ message:
|
|
470
|
+
logger.info({ message: '[Trigger] Disqualified', triggerName, triggerBody, sessionId });
|
|
462
471
|
await this.interruptSessionManager.release(sessionId);
|
|
463
472
|
return;
|
|
464
473
|
}
|
|
@@ -469,7 +478,7 @@ export class Agent {
|
|
|
469
478
|
}
|
|
470
479
|
}
|
|
471
480
|
|
|
472
|
-
logger.info({
|
|
481
|
+
logger.info({ msg: '[Trigger] Received', triggerName, triggerBody, sessionId });
|
|
473
482
|
const langraphConfig = this.getLangraphConfig(sessionId || uuidv4());
|
|
474
483
|
const state = await this.compiledGraph.getState(langraphConfig);
|
|
475
484
|
const suffixes = Object.values(internalNodesSuffix);
|
|
@@ -478,7 +487,10 @@ export class Agent {
|
|
|
478
487
|
? state.values.overrideStartFromNodeId
|
|
479
488
|
? state.values.overrideStartFromNodeId
|
|
480
489
|
: state.next[0]
|
|
481
|
-
: this.startingNodeId
|
|
490
|
+
: this.startingNodeId;
|
|
491
|
+
if (!nodeToBeInvoked) {
|
|
492
|
+
throw new Error('No node to be invoked');
|
|
493
|
+
}
|
|
482
494
|
nodeToBeInvoked = nodeToBeInvoked.replace(new RegExp(suffixes.join('|'), 'g'), '');
|
|
483
495
|
const historyStep = this.createTriggerHistoryStep(
|
|
484
496
|
state.values.history,
|
|
@@ -543,23 +555,22 @@ export class Agent {
|
|
|
543
555
|
langraphConfig,
|
|
544
556
|
);
|
|
545
557
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
}
|
|
558
|
+
// const nextMessage = await this.interruptSessionManager.dequeue(sessionId);
|
|
559
|
+
// if (nextMessage) {
|
|
560
|
+
// // Dequeue the first message and process it recursively
|
|
561
|
+
// // Recursively process the next message with bypass flag
|
|
562
|
+
// const invokeParams: AgentInvokeParams = {
|
|
563
|
+
// triggerBody: nextMessage.triggerBody,
|
|
564
|
+
// triggerName: nextMessage.triggerName,
|
|
565
|
+
// sessionId: sessionId,
|
|
566
|
+
// bypassSessionCheck: true,
|
|
567
|
+
// };
|
|
568
|
+
// if (nextMessage.appName) {
|
|
569
|
+
// invokeParams.appName = nextMessage.appName;
|
|
570
|
+
// }
|
|
571
|
+
// logger.info({ msg: 'Invoking next message in the queue', invokeParams });
|
|
572
|
+
// return await this.invoke(invokeParams);
|
|
573
|
+
// }
|
|
563
574
|
|
|
564
575
|
// Release the session lock
|
|
565
576
|
await this.interruptSessionManager.release(sessionId);
|
|
@@ -567,7 +578,7 @@ export class Agent {
|
|
|
567
578
|
return res;
|
|
568
579
|
} catch (error: any) {
|
|
569
580
|
logger.error({
|
|
570
|
-
|
|
581
|
+
msg: '[Trigger] Error',
|
|
571
582
|
errorMessage: error.message,
|
|
572
583
|
stack: error.stack,
|
|
573
584
|
sessionId,
|
|
@@ -805,7 +816,7 @@ export class Agent {
|
|
|
805
816
|
// Skip secret loading in local development
|
|
806
817
|
const { runLocally } = getConfig();
|
|
807
818
|
if (runLocally) {
|
|
808
|
-
logger.
|
|
819
|
+
logger.debug({ msg: '[Agent] Secrets loaded from local .env file' });
|
|
809
820
|
return {};
|
|
810
821
|
}
|
|
811
822
|
if (!mindedConnection.isConnected()) {
|
|
@@ -832,10 +843,10 @@ export class Agent {
|
|
|
832
843
|
const secrets = response.secrets || {};
|
|
833
844
|
|
|
834
845
|
// Load secrets into process.env
|
|
835
|
-
logger.debug(`Loading ${Object.keys(secrets).length} secrets into environment variables`);
|
|
836
846
|
Object.entries(secrets).forEach(([key, value]) => {
|
|
837
847
|
process.env[key] = value;
|
|
838
848
|
});
|
|
849
|
+
logger.debug(`[Agent] Loaded ${Object.keys(secrets).length} secrets from platform`);
|
|
839
850
|
|
|
840
851
|
// Cache the secrets for future requests
|
|
841
852
|
this.secretsCache = secrets;
|
|
@@ -851,7 +862,7 @@ export class Agent {
|
|
|
851
862
|
}
|
|
852
863
|
|
|
853
864
|
private setupVoice(): void {
|
|
854
|
-
logger.info(
|
|
865
|
+
logger.info('[Voice] Setting up voice');
|
|
855
866
|
if (!mindedConnection.isConnected()) {
|
|
856
867
|
throw new Error('Minded connection is required');
|
|
857
868
|
}
|
|
@@ -874,7 +885,7 @@ export class Agent {
|
|
|
874
885
|
voiceSession.sendAudio(audioMessage.audioData);
|
|
875
886
|
} else {
|
|
876
887
|
logger.trace({
|
|
877
|
-
message: 'Audio received; voice session not found for sessionId',
|
|
888
|
+
message: '[Voice] Audio received; voice session not found for sessionId',
|
|
878
889
|
sessionId: audioMessage.sessionId,
|
|
879
890
|
activeSessions: Array.from(this.voiceSessions.keys()),
|
|
880
891
|
});
|
|
@@ -884,13 +895,13 @@ export class Agent {
|
|
|
884
895
|
// Hangup / end session handler
|
|
885
896
|
connection.on(mindedConnectionSocketMessageType.DASHBOARD_VOICE_SESSION_END, (message) => {
|
|
886
897
|
const hangup = message as BaseVoiceMessage;
|
|
887
|
-
logger.debug({
|
|
898
|
+
logger.debug({ msg: '[Voice] Dashboard eneded voice session', sessionId: hangup.sessionId });
|
|
888
899
|
const voiceSession = this.voiceSessions.get(hangup.sessionId);
|
|
889
900
|
if (voiceSession) {
|
|
890
901
|
voiceSession.hangup();
|
|
891
902
|
} else {
|
|
892
903
|
logger.trace({
|
|
893
|
-
message: 'Session ended; voice session not found for sessionId',
|
|
904
|
+
message: '[Voice] Session ended; voice session not found for sessionId',
|
|
894
905
|
sessionId: hangup.sessionId,
|
|
895
906
|
activeSessions: this.voiceSessions.keys(),
|
|
896
907
|
});
|
|
@@ -917,7 +928,8 @@ export class Agent {
|
|
|
917
928
|
voiceId: voiceTrigger.voiceId,
|
|
918
929
|
});
|
|
919
930
|
await voiceSession.init();
|
|
920
|
-
logger.debug({
|
|
931
|
+
logger.debug({ msg: '[Voice] Voice session initialized', sessionId: params.sessionId });
|
|
932
|
+
|
|
921
933
|
this.voiceSessions.set(params.sessionId, voiceSession);
|
|
922
934
|
|
|
923
935
|
// Emit voice session start event
|
|
@@ -945,7 +957,7 @@ export class Agent {
|
|
|
945
957
|
To be used by the Lambda wrapper to restore checkpoints
|
|
946
958
|
*/
|
|
947
959
|
public async restoreCheckpoint(sessionId: string, checkpointId: string): Promise<void> {
|
|
948
|
-
logger.info({
|
|
960
|
+
logger.info({ msg: '[Agent]Restoring checkpoint', sessionId, checkpointId });
|
|
949
961
|
const langraphConfig = this.getLangraphConfig(sessionId, checkpointId);
|
|
950
962
|
await this.compiledGraph.invoke(
|
|
951
963
|
new Command({
|