@minded-ai/mindedjs 1.0.151-beta-1 → 2.0.0-beta1
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 +2 -2
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +33 -55
- package/dist/agent.js.map +1 -1
- package/dist/cli/index.js +0 -0
- package/dist/edges/createLogicalRouter.d.ts.map +1 -1
- package/dist/edges/createLogicalRouter.js +4 -18
- package/dist/edges/createLogicalRouter.js.map +1 -1
- package/dist/events/AgentEvents.d.ts +5 -14
- package/dist/events/AgentEvents.d.ts.map +1 -1
- package/dist/guidelines/guidelinesManager.d.ts +37 -0
- package/dist/guidelines/guidelinesManager.d.ts.map +1 -0
- package/dist/guidelines/guidelinesManager.js +172 -0
- package/dist/guidelines/guidelinesManager.js.map +1 -0
- package/dist/internalTools/documentExtraction.d.ts +69 -0
- package/dist/internalTools/documentExtraction.d.ts.map +1 -0
- package/dist/internalTools/documentExtraction.js +65 -0
- package/dist/internalTools/documentExtraction.js.map +1 -0
- package/dist/internalTools/libraryActionRunnerTool.d.ts.map +1 -1
- package/dist/internalTools/libraryActionRunnerTool.js +0 -1
- package/dist/internalTools/libraryActionRunnerTool.js.map +1 -1
- package/dist/internalTools/managedDocumentParser/managedDocumentParser.d.ts +10 -0
- package/dist/internalTools/managedDocumentParser/managedDocumentParser.d.ts.map +1 -0
- package/dist/internalTools/managedDocumentParser/managedDocumentParser.js +80 -0
- package/dist/internalTools/managedDocumentParser/managedDocumentParser.js.map +1 -0
- package/dist/internalTools/retell.js +7 -17
- package/dist/internalTools/retell.js.map +1 -1
- package/dist/internalTools/sendPlaceholderMessage.js +7 -17
- package/dist/internalTools/sendPlaceholderMessage.js.map +1 -1
- package/dist/interrupts/BaseInterruptSessionManager.d.ts +2 -2
- package/dist/interrupts/BaseInterruptSessionManager.d.ts.map +1 -1
- package/dist/interrupts/BaseInterruptSessionManager.js +1 -7
- package/dist/interrupts/BaseInterruptSessionManager.js.map +1 -1
- package/dist/nodes/addAppToolNode.d.ts.map +1 -1
- package/dist/nodes/addAppToolNode.js +24 -18
- package/dist/nodes/addAppToolNode.js.map +1 -1
- package/dist/nodes/addBrowserTaskNode.d.ts.map +1 -1
- package/dist/nodes/addBrowserTaskNode.js +30 -27
- package/dist/nodes/addBrowserTaskNode.js.map +1 -1
- package/dist/nodes/addBrowserTaskRunNode.d.ts.map +1 -1
- package/dist/nodes/addBrowserTaskRunNode.js +18 -20
- package/dist/nodes/addBrowserTaskRunNode.js.map +1 -1
- package/dist/nodes/addJumpToNode.d.ts.map +1 -1
- package/dist/nodes/addJumpToNode.js +8 -9
- package/dist/nodes/addJumpToNode.js.map +1 -1
- package/dist/nodes/addJunctionNode.d.ts.map +1 -1
- package/dist/nodes/addJunctionNode.js +8 -9
- package/dist/nodes/addJunctionNode.js.map +1 -1
- package/dist/nodes/addPromptNode.d.ts.map +1 -1
- package/dist/nodes/addPromptNode.js +107 -270
- package/dist/nodes/addPromptNode.js.map +1 -1
- package/dist/nodes/addToolNode.d.ts.map +1 -1
- package/dist/nodes/addToolNode.js +33 -20
- package/dist/nodes/addToolNode.js.map +1 -1
- package/dist/nodes/addToolRunNode.d.ts.map +1 -1
- package/dist/nodes/addToolRunNode.js +15 -21
- package/dist/nodes/addToolRunNode.js.map +1 -1
- package/dist/nodes/addTriggerNode.js +9 -11
- package/dist/nodes/addTriggerNode.js.map +1 -1
- package/dist/nodes/compilePrompt.d.ts.map +1 -1
- package/dist/nodes/compilePrompt.js +2 -0
- package/dist/nodes/compilePrompt.js.map +1 -1
- package/dist/pii-gateway/gateway.d.ts +17 -0
- package/dist/pii-gateway/gateway.d.ts.map +1 -0
- package/dist/pii-gateway/gateway.js +77 -0
- package/dist/pii-gateway/gateway.js.map +1 -0
- package/dist/pii-gateway/index.d.ts +4 -0
- package/dist/pii-gateway/index.d.ts.map +1 -0
- package/dist/pii-gateway/index.js +14 -0
- package/dist/pii-gateway/index.js.map +1 -0
- package/dist/pii-gateway/proxy.d.ts +80 -0
- package/dist/pii-gateway/proxy.d.ts.map +1 -0
- package/dist/pii-gateway/proxy.js +106 -0
- package/dist/pii-gateway/proxy.js.map +1 -0
- package/dist/pii-gateway/types.d.ts +27 -0
- package/dist/pii-gateway/types.d.ts.map +1 -0
- package/dist/pii-gateway/types.js +3 -0
- package/dist/pii-gateway/types.js.map +1 -0
- package/dist/platform/mindedChatOpenAI.d.ts +5 -0
- package/dist/platform/mindedChatOpenAI.d.ts.map +1 -0
- package/dist/platform/mindedChatOpenAI.js +23 -0
- package/dist/platform/mindedChatOpenAI.js.map +1 -0
- package/dist/platform/mindedCheckpointSaver.js.map +1 -1
- package/dist/platform/mindedUtils.d.ts +1 -0
- package/dist/platform/mindedUtils.d.ts.map +1 -0
- package/dist/platform/mindedUtils.js +2 -0
- package/dist/platform/mindedUtils.js.map +1 -0
- package/dist/platform/parallelAzureChatOpenAI.d.ts +39 -0
- package/dist/platform/parallelAzureChatOpenAI.d.ts.map +1 -0
- package/dist/platform/parallelAzureChatOpenAI.js +114 -0
- package/dist/platform/parallelAzureChatOpenAI.js.map +1 -0
- package/dist/platform/parallelChatOpenAI.d.ts +38 -0
- package/dist/platform/parallelChatOpenAI.d.ts.map +1 -0
- package/dist/platform/parallelChatOpenAI.js +111 -0
- package/dist/platform/parallelChatOpenAI.js.map +1 -0
- package/dist/platform/parallelMindedChatOpenAI.d.ts +39 -0
- package/dist/platform/parallelMindedChatOpenAI.d.ts.map +1 -0
- package/dist/platform/parallelMindedChatOpenAI.js +111 -0
- package/dist/platform/parallelMindedChatOpenAI.js.map +1 -0
- package/dist/platform/piiGateway/proxy.d.ts +20 -0
- package/dist/platform/piiGateway/proxy.d.ts.map +1 -0
- package/dist/platform/piiGateway/proxy.js +24 -0
- package/dist/platform/piiGateway/proxy.js.map +1 -0
- package/dist/platform/toolExecutor.d.ts.map +1 -1
- package/dist/platform/toolExecutor.js +4 -20
- package/dist/platform/toolExecutor.js.map +1 -1
- package/dist/playbooks/playbooks.d.ts +1 -1
- package/dist/playbooks/playbooks.d.ts.map +1 -1
- package/dist/playbooks/playbooks.js +1 -1
- package/dist/playbooks/playbooks.js.map +1 -1
- package/dist/toolsLibrary/classifier.d.ts.map +1 -1
- package/dist/toolsLibrary/classifier.js +5 -9
- package/dist/toolsLibrary/classifier.js.map +1 -1
- package/dist/toolsLibrary/extraction.d.ts.map +1 -1
- package/dist/toolsLibrary/extraction.js +5 -9
- package/dist/toolsLibrary/extraction.js.map +1 -1
- package/dist/toolsLibrary/parseDocument.d.ts.map +1 -1
- package/dist/toolsLibrary/parseDocument.js +6 -14
- package/dist/toolsLibrary/parseDocument.js.map +1 -1
- package/dist/types/Agent.d.ts +2 -0
- package/dist/types/Agent.d.ts.map +1 -0
- package/dist/types/Agent.js +18 -0
- package/dist/types/Agent.js.map +1 -0
- package/dist/types/Agent.types.d.ts +1 -1
- package/dist/types/Agent.types.d.ts.map +1 -1
- package/dist/types/Flows.d.ts +2 -0
- package/dist/types/Flows.d.ts.map +1 -0
- package/dist/types/Flows.js +18 -0
- package/dist/types/Flows.js.map +1 -0
- package/dist/types/LLM.d.ts +2 -0
- package/dist/types/LLM.d.ts.map +1 -0
- package/dist/types/LLM.js +18 -0
- package/dist/types/LLM.js.map +1 -0
- package/dist/types/LangGraph.d.ts +2 -0
- package/dist/types/LangGraph.d.ts.map +1 -0
- package/dist/types/LangGraph.js +18 -0
- package/dist/types/LangGraph.js.map +1 -0
- package/dist/types/LangGraph.types.d.ts.map +1 -1
- package/dist/types/LangGraph.types.js +30 -42
- package/dist/types/LangGraph.types.js.map +1 -1
- package/dist/types/Platform.d.ts +2 -0
- package/dist/types/Platform.d.ts.map +1 -0
- package/dist/types/Platform.js +18 -0
- package/dist/types/Platform.js.map +1 -0
- package/dist/types/Tools.d.ts +2 -0
- package/dist/types/Tools.d.ts.map +1 -0
- package/dist/types/Tools.js +18 -0
- package/dist/types/Tools.js.map +1 -0
- package/dist/types/Tools.types.d.ts +2 -7
- package/dist/types/Tools.types.d.ts.map +1 -1
- package/dist/types/Triggers.d.ts +2 -0
- package/dist/types/Triggers.d.ts.map +1 -0
- package/dist/types/Triggers.js +18 -0
- package/dist/types/Triggers.js.map +1 -0
- package/dist/types/Triggers.types.d.ts +25 -0
- package/dist/types/Triggers.types.d.ts.map +1 -0
- package/dist/types/Triggers.types.js +3 -0
- package/dist/types/Triggers.types.js.map +1 -0
- package/dist/types/Voice.d.ts +2 -0
- package/dist/types/Voice.d.ts.map +1 -0
- package/dist/types/Voice.js +18 -0
- package/dist/types/Voice.js.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +25 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/LogicalConditionDebugger.d.ts +57 -0
- package/dist/utils/LogicalConditionDebugger.d.ts.map +1 -0
- package/dist/utils/LogicalConditionDebugger.js +143 -0
- package/dist/utils/LogicalConditionDebugger.js.map +1 -0
- package/dist/utils/documentProcessor.d.ts +87 -0
- package/dist/utils/documentProcessor.d.ts.map +1 -0
- package/dist/utils/documentProcessor.js +726 -0
- package/dist/utils/documentProcessor.js.map +1 -0
- package/dist/utils/extractStateMemoryResponse.d.ts +0 -4
- package/dist/utils/extractStateMemoryResponse.d.ts.map +1 -1
- package/dist/utils/extractStateMemoryResponse.js +87 -89
- package/dist/utils/extractStateMemoryResponse.js.map +1 -1
- package/dist/utils/extractToolGuidelineParams.d.ts +4 -0
- package/dist/utils/extractToolGuidelineParams.d.ts.map +1 -0
- package/dist/utils/extractToolGuidelineParams.js +20 -0
- package/dist/utils/extractToolGuidelineParams.js.map +1 -0
- package/dist/utils/extractToolMemoryResponse.d.ts +4 -0
- package/dist/utils/extractToolMemoryResponse.d.ts.map +1 -0
- package/dist/utils/extractToolMemoryResponse.js +16 -0
- package/dist/utils/extractToolMemoryResponse.js.map +1 -0
- package/dist/utils/parseAttachments.d.ts +14 -0
- package/dist/utils/parseAttachments.d.ts.map +1 -0
- package/dist/utils/parseAttachments.js +54 -0
- package/dist/utils/parseAttachments.js.map +1 -0
- package/docs/sdk/agent-api.md +1 -1
- package/package.json +1 -1
- package/src/agent.ts +37 -63
- package/src/edges/createLogicalRouter.ts +4 -19
- package/src/events/AgentEvents.ts +5 -14
- package/src/internalTools/libraryActionRunnerTool.ts +0 -1
- package/src/interrupts/BaseInterruptSessionManager.ts +3 -9
- package/src/nodes/addAppToolNode.ts +19 -11
- package/src/nodes/addBrowserTaskNode.ts +22 -16
- package/src/nodes/addBrowserTaskRunNode.ts +10 -9
- package/src/nodes/addJumpToNode.ts +5 -4
- package/src/nodes/addJunctionNode.ts +5 -4
- package/src/nodes/addPromptNode.ts +107 -299
- package/src/nodes/addToolNode.ts +34 -20
- package/src/nodes/addToolRunNode.ts +15 -15
- package/src/nodes/addTriggerNode.ts +5 -5
- package/src/nodes/compilePrompt.ts +3 -0
- package/src/platform/mindedCheckpointSaver.ts +13 -13
- package/src/platform/toolExecutor.ts +4 -20
- package/src/playbooks/playbooks.ts +2 -2
- package/src/toolsLibrary/classifier.ts +6 -9
- package/src/toolsLibrary/extraction.ts +6 -9
- package/src/toolsLibrary/parseDocument.ts +7 -14
- package/src/types/Agent.types.ts +1 -1
- package/src/types/LangGraph.types.ts +30 -41
- package/src/types/Tools.types.ts +2 -7
- package/dist/browserTask/README.md +0 -419
- package/dist/browserTask/browserAgent.py +0 -632
- package/dist/browserTask/captcha_isolated.png +0 -0
- package/dist/browserTask/executeBrowserTask.ts +0 -79
- package/dist/browserTask/requirements.txt +0 -8
- package/dist/browserTask/setup.sh +0 -144
- package/src/utils/extractStateMemoryResponse.ts +0 -94
package/src/agent.ts
CHANGED
|
@@ -28,14 +28,14 @@ import { createCheckpointSaver } from './checkpointer/checkpointSaverFactory';
|
|
|
28
28
|
import { getConfig } from './platform/config';
|
|
29
29
|
import { InterruptPayload, InterruptSessionManager, InterruptType } from './interrupts/BaseInterruptSessionManager';
|
|
30
30
|
import { createInterruptSessionManager } from './interrupts/interruptSessionManagerFactory';
|
|
31
|
-
import { HumanMessage } from '@langchain/core/messages';
|
|
31
|
+
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
32
32
|
import triggerTypeToDefaultMessage from './triggers/triggerTypeToDefaultMessage';
|
|
33
33
|
import appActionRunnerToolCreator from './internalTools/appActionRunnerTool';
|
|
34
34
|
import { VoiceSession } from './voice/voiceSession';
|
|
35
35
|
import { BaseVoiceMessage, OnVoiceAudioOut, VectorStoreQueryRequest, VectorStoreQueryResponse } from './platform/mindedConnectionTypes';
|
|
36
36
|
import { PIIGateway, PIIGatewayInstance } from './platform/piiGateway';
|
|
37
37
|
import { logger } from './utils/logger';
|
|
38
|
-
import { loadPlaybooks, Playbook } from './playbooks/playbooks';
|
|
38
|
+
import { combinePlaybooks, loadPlaybooks, Playbook } from './playbooks/playbooks';
|
|
39
39
|
import { createTriggerHistoryStep } from './utils/history';
|
|
40
40
|
import { timerHandlers } from './internalTools/timer';
|
|
41
41
|
import { parseAttachments, combineContentWithAttachments } from './platform/utils/parseAttachments';
|
|
@@ -43,6 +43,7 @@ import { ToolExecutor, ToolExecutionRequest, ToolExecutionResponse } from './pla
|
|
|
43
43
|
import { initLibraryActionsRunnerTools, loadFlows } from './utils/agentUtils';
|
|
44
44
|
import { Document } from '@langchain/core/documents';
|
|
45
45
|
import { getInitialState } from './types/LangGraph.types';
|
|
46
|
+
import { compilePrompt } from './nodes/compilePrompt';
|
|
46
47
|
|
|
47
48
|
type CreateAgentParams<Memory> = {
|
|
48
49
|
memorySchema: z.ZodSchema;
|
|
@@ -423,7 +424,7 @@ export class Agent {
|
|
|
423
424
|
// Try to acquire lock atomically (unless bypassing session check)
|
|
424
425
|
if (!bypassSessionCheck && !(await this.interruptSessionManager.lock(sessionId))) {
|
|
425
426
|
// Could not acquire lock, session is being processed - enqueue the message
|
|
426
|
-
logger.
|
|
427
|
+
logger.info({ msg: 'Enqueuing message', sessionId, triggerBody, triggerName, appName });
|
|
427
428
|
await this.interruptSessionManager.enqueueMessage(sessionId, {
|
|
428
429
|
triggerBody,
|
|
429
430
|
triggerName,
|
|
@@ -441,11 +442,20 @@ export class Agent {
|
|
|
441
442
|
state = getInitialState(this.memorySchema);
|
|
442
443
|
}
|
|
443
444
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
445
|
+
state.sessionId = sessionId;
|
|
446
|
+
state.sessionType = SessionType.TEXT;
|
|
447
|
+
|
|
448
|
+
// Add playbooks to messages
|
|
449
|
+
const combinedPlaybooks = combinePlaybooks(this.playbooks);
|
|
450
|
+
if (combinedPlaybooks) {
|
|
451
|
+
const compiledPrompt = compilePrompt(combinedPlaybooks, { memory: state.memory });
|
|
452
|
+
const systemMessage = new SystemMessage(compiledPrompt);
|
|
453
|
+
if (state.messages.length === 0 || state.messages[0].getType() === 'system') {
|
|
454
|
+
state.messages[0] = systemMessage;
|
|
455
|
+
} else {
|
|
456
|
+
state.messages.unshift(systemMessage);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
449
459
|
|
|
450
460
|
// Process special trigger types (dashboard/voice messages)
|
|
451
461
|
if (triggerName === KnownTriggerNames.DASHBOARD_MESSAGE || triggerName === KnownTriggerNames.VOICE_MESSAGE) {
|
|
@@ -453,21 +463,14 @@ export class Agent {
|
|
|
453
463
|
const attachmentsString = parseAttachments(triggerBody);
|
|
454
464
|
const finalContent = combineContentWithAttachments(triggerBody.content || '', attachmentsString);
|
|
455
465
|
if (finalContent) {
|
|
456
|
-
|
|
466
|
+
state.messages.push(new HumanMessage({ content: finalContent, id: uuidv4() }));
|
|
457
467
|
}
|
|
458
468
|
triggerBody.content = finalContent;
|
|
459
|
-
|
|
469
|
+
state.sessionType = triggerName === KnownTriggerNames.VOICE_MESSAGE ? SessionType.VOICE : SessionType.TEXT;
|
|
460
470
|
}
|
|
461
471
|
|
|
462
|
-
// Merge current state with any updates we've made so far
|
|
463
|
-
const currentState = { ...state, ...stateUpdate } as State<z.infer<typeof this.memorySchema>>;
|
|
464
|
-
|
|
465
472
|
// Emit trigger event and let handlers modify the state
|
|
466
|
-
const results = await this.emit(AgentEvents.TRIGGER_EVENT, {
|
|
467
|
-
triggerName,
|
|
468
|
-
triggerBody,
|
|
469
|
-
state: currentState,
|
|
470
|
-
});
|
|
473
|
+
const results = await this.emit(AgentEvents.TRIGGER_EVENT, { triggerName, triggerBody, state });
|
|
471
474
|
|
|
472
475
|
// Process handler results
|
|
473
476
|
const handlerResult = results.find((r) => r !== undefined);
|
|
@@ -477,18 +480,14 @@ export class Agent {
|
|
|
477
480
|
await this.interruptSessionManager.release(sessionId);
|
|
478
481
|
return;
|
|
479
482
|
}
|
|
480
|
-
// Merge handler's state updates
|
|
481
|
-
if (handlerResult.state) {
|
|
482
|
-
stateUpdate = { ...stateUpdate, ...handlerResult.state };
|
|
483
|
-
}
|
|
484
483
|
}
|
|
485
484
|
|
|
486
485
|
// If no messages were set by handler or initial processing, create default message
|
|
487
|
-
if (!
|
|
486
|
+
if (!state.messages || state.messages.length === 0) {
|
|
488
487
|
if (appName && triggerTypeToDefaultMessage[appName]?.[triggerName]) {
|
|
489
|
-
|
|
488
|
+
state.messages = triggerTypeToDefaultMessage[appName][triggerName](triggerBody);
|
|
490
489
|
} else {
|
|
491
|
-
|
|
490
|
+
state.messages = [new HumanMessage({ content: JSON.stringify(triggerBody), id: uuidv4() })];
|
|
492
491
|
}
|
|
493
492
|
}
|
|
494
493
|
|
|
@@ -501,13 +500,10 @@ export class Agent {
|
|
|
501
500
|
const suffixes = Object.values(internalNodesSuffix);
|
|
502
501
|
nodeToBeInvoked = nodeToBeInvoked.replace(new RegExp(suffixes.join('|'), 'g'), '');
|
|
503
502
|
|
|
504
|
-
// Create a history step
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
// History reducer expects an array or single item
|
|
509
|
-
stateUpdate.history = [historyStep];
|
|
510
|
-
}
|
|
503
|
+
// Create a history step
|
|
504
|
+
const messageIds = state.messages?.map((m) => m.id!) || [];
|
|
505
|
+
const historyStep = createTriggerHistoryStep(state.history, nodeToBeInvoked, messageIds, triggerName, triggerBody, appName);
|
|
506
|
+
state.history.push(historyStep);
|
|
511
507
|
|
|
512
508
|
// 3) Handle interrupts/goto, else normal invoke
|
|
513
509
|
let res;
|
|
@@ -519,30 +515,20 @@ export class Agent {
|
|
|
519
515
|
// For HUMAN_IN_THE_LOOP, use resume with the state update
|
|
520
516
|
res = await this.compiledGraph.invoke(
|
|
521
517
|
new Command({
|
|
522
|
-
resume: { ...
|
|
518
|
+
resume: { ...state, goto: null },
|
|
523
519
|
}),
|
|
524
520
|
langgraphConfig,
|
|
525
521
|
);
|
|
526
522
|
} else if (interruptValue?.type === InterruptType.NEW_TRIGGERS) {
|
|
527
|
-
// For NEW_TRIGGERS, merge with updateStateObject if present
|
|
528
|
-
const finalState: any = { ...stateUpdate };
|
|
529
523
|
const updatedInterruptState = interruptValue.updateStateObject;
|
|
530
524
|
if (updatedInterruptState) {
|
|
531
|
-
|
|
532
|
-
finalState.messages = [...(updatedInterruptState.messages || []), ...(stateUpdate.messages || [])];
|
|
533
|
-
finalState.history = [...(updatedInterruptState.history || []), ...(stateUpdate.history || [])];
|
|
534
|
-
// Merge other fields from updateStateObject
|
|
535
|
-
Object.keys(updatedInterruptState).forEach((key) => {
|
|
536
|
-
if (key !== 'messages' && key !== 'history') {
|
|
537
|
-
finalState[key] = updatedInterruptState[key as keyof typeof updatedInterruptState];
|
|
538
|
-
}
|
|
539
|
-
});
|
|
525
|
+
state = updatedInterruptState;
|
|
540
526
|
}
|
|
541
527
|
|
|
542
528
|
// Then use update with the full object and empty resume
|
|
543
529
|
res = await this.compiledGraph.invoke(
|
|
544
530
|
new Command({
|
|
545
|
-
update:
|
|
531
|
+
update: state,
|
|
546
532
|
resume: '',
|
|
547
533
|
}),
|
|
548
534
|
langgraphConfig,
|
|
@@ -552,7 +538,7 @@ export class Agent {
|
|
|
552
538
|
res = await this.compiledGraph.invoke(
|
|
553
539
|
new Command({
|
|
554
540
|
update: {
|
|
555
|
-
...
|
|
541
|
+
...state,
|
|
556
542
|
goto: null, //reset the goto
|
|
557
543
|
},
|
|
558
544
|
goto: state.goto,
|
|
@@ -560,7 +546,7 @@ export class Agent {
|
|
|
560
546
|
langgraphConfig,
|
|
561
547
|
);
|
|
562
548
|
} else {
|
|
563
|
-
res = await this.compiledGraph.invoke(
|
|
549
|
+
res = await this.compiledGraph.invoke(state, langgraphConfig);
|
|
564
550
|
}
|
|
565
551
|
const nextMessage = await this.interruptSessionManager.dequeue(sessionId);
|
|
566
552
|
if (nextMessage) {
|
|
@@ -574,7 +560,7 @@ export class Agent {
|
|
|
574
560
|
if (nextMessage.appName) {
|
|
575
561
|
invokeParams.appName = nextMessage.appName;
|
|
576
562
|
}
|
|
577
|
-
logger.
|
|
563
|
+
logger.info({ msg: 'Invoking next message in the queue', invokeParams });
|
|
578
564
|
return await this.invoke(invokeParams);
|
|
579
565
|
}
|
|
580
566
|
|
|
@@ -596,11 +582,6 @@ export class Agent {
|
|
|
596
582
|
const handlerResult = results.find((r) => r !== undefined);
|
|
597
583
|
let throwError = handlerResult === undefined;
|
|
598
584
|
if (handlerResult) {
|
|
599
|
-
// Merge handler's state updates
|
|
600
|
-
if (handlerResult.state) {
|
|
601
|
-
handlerResult.state = { ...state.values, ...handlerResult.state };
|
|
602
|
-
await this.compiledGraph.updateState(this.getLangraphConfig(sessionId), handlerResult.state);
|
|
603
|
-
}
|
|
604
585
|
// If one handler returns throwError, we throw the error
|
|
605
586
|
throwError = throwError || handlerResult.throwError;
|
|
606
587
|
}
|
|
@@ -668,9 +649,7 @@ export class Agent {
|
|
|
668
649
|
// Public API for registering event listeners
|
|
669
650
|
public on<E extends keyof AgentEventRequestPayloads<z.infer<typeof this.memorySchema>>>(
|
|
670
651
|
event: E,
|
|
671
|
-
handler: (
|
|
672
|
-
payload: AgentEventRequestPayloads<z.infer<typeof this.memorySchema>>[E],
|
|
673
|
-
) => Promise<AgentEventResponsePayloads<z.infer<typeof this.memorySchema>>[E] | void>,
|
|
652
|
+
handler: (payload: AgentEventRequestPayloads<z.infer<typeof this.memorySchema>>[E]) => Promise<AgentEventResponsePayloads[E] | void>,
|
|
674
653
|
): void {
|
|
675
654
|
if (!this.eventHandlers[event]) {
|
|
676
655
|
this.eventHandlers[event] = [];
|
|
@@ -683,7 +662,7 @@ export class Agent {
|
|
|
683
662
|
public async emit<E extends keyof AgentEventRequestPayloads<z.infer<typeof this.memorySchema>>>(
|
|
684
663
|
event: E,
|
|
685
664
|
payload: AgentEventRequestPayloads<z.infer<typeof this.memorySchema>>[E],
|
|
686
|
-
): Promise<AgentEventResponsePayloads
|
|
665
|
+
): Promise<AgentEventResponsePayloads[E][]> {
|
|
687
666
|
if (!this.eventHandlers[event]) {
|
|
688
667
|
return [];
|
|
689
668
|
}
|
|
@@ -843,16 +822,11 @@ export class Agent {
|
|
|
843
822
|
const state = await this.compiledGraph.getState(this.getLangraphConfig(params.sessionId));
|
|
844
823
|
|
|
845
824
|
// Emit voice session start event
|
|
846
|
-
|
|
825
|
+
await this.emit(AgentEvents.VOICE_SESSION_START, {
|
|
847
826
|
metadata: params.metadata,
|
|
848
827
|
state: state.values as State<z.infer<typeof this.memorySchema>>,
|
|
849
828
|
});
|
|
850
829
|
|
|
851
|
-
const handlerResult = results.find((r) => r !== undefined);
|
|
852
|
-
if (handlerResult && handlerResult.state) {
|
|
853
|
-
await this.compiledGraph.updateState(this.getLangraphConfig(params.sessionId), handlerResult.state);
|
|
854
|
-
}
|
|
855
|
-
|
|
856
830
|
return voiceSession;
|
|
857
831
|
}
|
|
858
832
|
|
|
@@ -30,17 +30,12 @@ export const createLogicalRouter = ({ edges, agent }: { edges: LogicalConditionE
|
|
|
30
30
|
logger.debug({ msg: '[LogicalCondition] Evaluating condition', edge, sessionId: state.sessionId });
|
|
31
31
|
|
|
32
32
|
// Emit ON_LOGICAL_CONDITION event
|
|
33
|
-
|
|
33
|
+
await agent.emit(AgentEvents.ON_LOGICAL_CONDITION, {
|
|
34
34
|
edge,
|
|
35
35
|
state,
|
|
36
36
|
condition: edge.condition,
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
const handlerResult = onLogicalConditionRes.find((r) => r !== undefined);
|
|
40
|
-
if (handlerResult && handlerResult.state) {
|
|
41
|
-
state = { ...state, ...handlerResult.state };
|
|
42
|
-
}
|
|
43
|
-
|
|
44
39
|
// Customer is responsible for providing valid JavaScript syntax
|
|
45
40
|
// We execute their condition in a sandboxed VM with timeout protection
|
|
46
41
|
const conditionCode = `
|
|
@@ -96,7 +91,7 @@ export const createLogicalRouter = ({ edges, agent }: { edges: LogicalConditionE
|
|
|
96
91
|
});
|
|
97
92
|
|
|
98
93
|
// Emit ON_LOGICAL_CONDITION_RESULT event
|
|
99
|
-
|
|
94
|
+
await agent.emit(AgentEvents.ON_LOGICAL_CONDITION_RESULT, {
|
|
100
95
|
edge,
|
|
101
96
|
state,
|
|
102
97
|
condition: edge.condition,
|
|
@@ -104,14 +99,8 @@ export const createLogicalRouter = ({ edges, agent }: { edges: LogicalConditionE
|
|
|
104
99
|
executionTimeMs: executionTime,
|
|
105
100
|
});
|
|
106
101
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (onLogicalConditionResultHandlerResult && onLogicalConditionResultHandlerResult.state) {
|
|
110
|
-
state = { ...state, ...onLogicalConditionResultHandlerResult.state };
|
|
111
|
-
goto = state.goto;
|
|
112
|
-
state.goto = null;
|
|
113
|
-
await agent.updateState({ sessionId: state.sessionId, state });
|
|
114
|
-
}
|
|
102
|
+
const goto = state.goto;
|
|
103
|
+
state.goto = null;
|
|
115
104
|
|
|
116
105
|
if (goto) {
|
|
117
106
|
logger.debug({ msg: `[Router] Jumping to node`, node: goto, sessionId: state.sessionId });
|
|
@@ -158,10 +147,6 @@ export const createLogicalRouter = ({ edges, agent }: { edges: LogicalConditionE
|
|
|
158
147
|
|
|
159
148
|
const onLogicalConditionResultHandlerResult = onLogicalConditionResultRes.find((r) => r !== undefined);
|
|
160
149
|
let throwError = false;
|
|
161
|
-
if (onLogicalConditionResultHandlerResult && onLogicalConditionResultHandlerResult.state) {
|
|
162
|
-
state = { ...state, ...onLogicalConditionResultHandlerResult.state };
|
|
163
|
-
await agent.updateState({ sessionId: state.sessionId, state });
|
|
164
|
-
}
|
|
165
150
|
throwError = onLogicalConditionResultHandlerResult?.throwError == true;
|
|
166
151
|
|
|
167
152
|
// Continue to next edge instead of failing completely
|
|
@@ -42,26 +42,17 @@ export type AgentEventRequestPayloads<Memory> = {
|
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
export type AgentEventResponsePayloads
|
|
46
|
-
[AgentEvents.AI_MESSAGE]:
|
|
47
|
-
state?: Partial<State<Memory>>;
|
|
48
|
-
};
|
|
45
|
+
export type AgentEventResponsePayloads = {
|
|
46
|
+
[AgentEvents.AI_MESSAGE]: void;
|
|
49
47
|
[AgentEvents.TRIGGER_EVENT]: {
|
|
50
48
|
isQualified: boolean;
|
|
51
|
-
state?: Partial<State<Memory>>;
|
|
52
|
-
};
|
|
53
|
-
[AgentEvents.VOICE_SESSION_START]: {
|
|
54
|
-
state?: Partial<State<Memory>>;
|
|
55
49
|
};
|
|
50
|
+
[AgentEvents.VOICE_SESSION_START]: void;
|
|
56
51
|
[AgentEvents.ERROR]: {
|
|
57
52
|
throwError: boolean;
|
|
58
|
-
state?: Partial<State<Memory>>;
|
|
59
|
-
};
|
|
60
|
-
[AgentEvents.ON_LOGICAL_CONDITION]: {
|
|
61
|
-
state?: Partial<State<Memory>>;
|
|
62
53
|
};
|
|
54
|
+
[AgentEvents.ON_LOGICAL_CONDITION]: void;
|
|
63
55
|
[AgentEvents.ON_LOGICAL_CONDITION_RESULT]: {
|
|
64
|
-
|
|
65
|
-
throwError?: boolean;
|
|
56
|
+
throwError: boolean;
|
|
66
57
|
};
|
|
67
58
|
};
|
|
@@ -14,7 +14,7 @@ export type QueuedMessage = TriggerEvent;
|
|
|
14
14
|
|
|
15
15
|
export interface InterruptPayload {
|
|
16
16
|
type: InterruptType;
|
|
17
|
-
updateStateObject?:
|
|
17
|
+
updateStateObject?: State;
|
|
18
18
|
id?: string;
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -57,20 +57,14 @@ export abstract class BaseInterruptSessionManager implements InterruptSessionMan
|
|
|
57
57
|
protected abstract getQueuedMessages(sessionId: string): QueuedMessage[] | Promise<QueuedMessage[]>;
|
|
58
58
|
|
|
59
59
|
// Common implementation of checkQueueAndInterrupt
|
|
60
|
-
async checkQueueAndInterrupt(sessionId: string, updateStateObject?:
|
|
60
|
+
async checkQueueAndInterrupt(sessionId: string, updateStateObject?: State): Promise<boolean> {
|
|
61
61
|
if (await this.hasQueuedMessages(sessionId)) {
|
|
62
62
|
logger.trace({ msg: 'graph has queued messagess, interrupting graph', sessionId });
|
|
63
63
|
|
|
64
64
|
// Interrupt the graph with NEW_TRIGGERS flag and optional updateStateObject
|
|
65
65
|
const interruptPayload: InterruptPayload = { type: InterruptType.NEW_TRIGGERS };
|
|
66
66
|
if (updateStateObject) {
|
|
67
|
-
interruptPayload.updateStateObject =
|
|
68
|
-
messages: updateStateObject.messages,
|
|
69
|
-
memory: updateStateObject.memory,
|
|
70
|
-
history: updateStateObject.history,
|
|
71
|
-
sessionId: updateStateObject.sessionId,
|
|
72
|
-
sessionType: updateStateObject.sessionType,
|
|
73
|
-
};
|
|
67
|
+
interruptPayload.updateStateObject = updateStateObject;
|
|
74
68
|
}
|
|
75
69
|
|
|
76
70
|
throw new GraphInterrupt([
|
|
@@ -12,6 +12,7 @@ import { createHistoryStep } from '../utils/history';
|
|
|
12
12
|
import { Tool } from '../types/Tools.types';
|
|
13
13
|
import { combinePlaybooks } from '../playbooks/playbooks';
|
|
14
14
|
import { compilePrompt } from './compilePrompt';
|
|
15
|
+
import { ToolMessage } from '@langchain/core/messages';
|
|
15
16
|
|
|
16
17
|
export const addAppToolNode = async ({
|
|
17
18
|
graph,
|
|
@@ -69,13 +70,15 @@ export const addAppToolNode = async ({
|
|
|
69
70
|
User instructions for choosing tool parameters are:
|
|
70
71
|
${node.prompt ? `${node.prompt}` : 'no instructions set by the user'}`;
|
|
71
72
|
|
|
72
|
-
const compiledPrompt = compilePrompt(message, { memory: state.memory
|
|
73
|
+
const compiledPrompt = compilePrompt(message, { memory: state.memory });
|
|
74
|
+
const systemMessage = new SystemMessage(compiledPrompt);
|
|
75
|
+
if (state.messages.length === 0 || state.messages[0].getType() === 'system') {
|
|
76
|
+
state.messages[0] = systemMessage;
|
|
77
|
+
} else {
|
|
78
|
+
state.messages.unshift(systemMessage);
|
|
79
|
+
}
|
|
73
80
|
|
|
74
|
-
const AIToolCallMessage = await llm
|
|
75
|
-
.bindTools([tool], {
|
|
76
|
-
tool_choice: tool.name,
|
|
77
|
-
})
|
|
78
|
-
.invoke([...state.messages, new SystemMessage(compiledPrompt)]);
|
|
81
|
+
const AIToolCallMessage = await llm.bindTools([tool], { tool_choice: tool.name }).invoke(state.messages);
|
|
79
82
|
AIToolCallMessage.tool_calls[0].args = {
|
|
80
83
|
...AIToolCallMessage.tool_calls[0].args,
|
|
81
84
|
...cleanedParameters, //user set parameters have priority over ai generated parameters
|
|
@@ -86,10 +89,14 @@ export const addAppToolNode = async ({
|
|
|
86
89
|
nodeType: NodeType.APP_TOOL,
|
|
87
90
|
},
|
|
88
91
|
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
|
|
93
|
+
state.goto = null;
|
|
94
|
+
state.messages.push(AIToolCallMessage);
|
|
95
|
+
if (toolCallMessage instanceof ToolMessage) {
|
|
96
|
+
state.messages.push(toolCallMessage);
|
|
97
|
+
}
|
|
98
|
+
state.history.push(
|
|
99
|
+
createHistoryStep<AppActionInvocationHistoryStep>(state.history, {
|
|
93
100
|
type: NodeType.APP_TOOL,
|
|
94
101
|
nodeId: node.name,
|
|
95
102
|
nodeDisplayName: node.displayName!,
|
|
@@ -97,7 +104,8 @@ export const addAppToolNode = async ({
|
|
|
97
104
|
appName: node.appName,
|
|
98
105
|
messageIds: [AIToolCallMessage.tool_calls[0].id],
|
|
99
106
|
}),
|
|
100
|
-
|
|
107
|
+
);
|
|
108
|
+
return state;
|
|
101
109
|
};
|
|
102
110
|
graph.addNode(node.name, callback);
|
|
103
111
|
};
|
|
@@ -54,22 +54,26 @@ export const addBrowserTaskNode = async ({ graph, node, agent, llm }: AddBrowser
|
|
|
54
54
|
const zodSchema = z.object(schemaFields);
|
|
55
55
|
|
|
56
56
|
// Create langchain tool
|
|
57
|
-
const tool = langchainTool(() => {
|
|
57
|
+
const tool = langchainTool(() => {}, {
|
|
58
58
|
name: 'browser-task',
|
|
59
59
|
description: node.prompt,
|
|
60
60
|
schema: zodSchema,
|
|
61
61
|
});
|
|
62
62
|
|
|
63
|
-
const combinedPlaybooks = combinePlaybooks(agent.playbooks)
|
|
64
|
-
|
|
63
|
+
const combinedPlaybooks = combinePlaybooks(agent.playbooks);
|
|
64
|
+
if (combinedPlaybooks) {
|
|
65
|
+
const compiledPrompt = compilePrompt(combinedPlaybooks, { memory: state.memory });
|
|
66
|
+
const systemMessage = new SystemMessage(compiledPrompt);
|
|
67
|
+
if (state.messages.length === 0 || state.messages[0].getType() === 'system') {
|
|
68
|
+
state.messages[0] = systemMessage;
|
|
69
|
+
} else {
|
|
70
|
+
state.messages.unshift(systemMessage);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
65
73
|
|
|
66
74
|
try {
|
|
67
75
|
// Use LLM to generate tool call
|
|
68
|
-
const AIToolCallMessage: AIMessage = await llm
|
|
69
|
-
.bindTools([tool], {
|
|
70
|
-
tool_choice: tool.name,
|
|
71
|
-
})
|
|
72
|
-
.invoke([...state.messages, new SystemMessage(systemPrompt)]);
|
|
76
|
+
const AIToolCallMessage: AIMessage = await llm.bindTools([tool], { tool_choice: tool.name }).invoke(state.messages);
|
|
73
77
|
await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId);
|
|
74
78
|
if (!AIToolCallMessage.tool_calls || AIToolCallMessage.tool_calls.length === 0) {
|
|
75
79
|
throw new Error('No tool calls generated by LLM');
|
|
@@ -141,16 +145,17 @@ ${Object.keys(inputParams).length > 0 ? `# Input parameters:\n${JSON.stringify(i
|
|
|
141
145
|
},
|
|
142
146
|
});
|
|
143
147
|
|
|
144
|
-
|
|
145
|
-
|
|
148
|
+
state.messages.push(toolCallingMessage);
|
|
149
|
+
state.history.push(
|
|
150
|
+
createHistoryStep<HistoryStep>(state.history, {
|
|
146
151
|
type: NodeType.BROWSER_TASK,
|
|
147
152
|
nodeId: node.name,
|
|
148
153
|
nodeDisplayName: node.displayName,
|
|
149
154
|
raw: { taskId: session.sessionId, liveUrl: session.liveViewUrl, inputParams },
|
|
150
155
|
messageIds: [toolCallingMessage.id!],
|
|
151
156
|
}),
|
|
152
|
-
|
|
153
|
-
|
|
157
|
+
);
|
|
158
|
+
return state;
|
|
154
159
|
} catch (error: any) {
|
|
155
160
|
logger.error(`Error creating browser task node ${node.displayName}: ${error}`);
|
|
156
161
|
|
|
@@ -180,16 +185,17 @@ ${Object.keys(inputParams).length > 0 ? `# Input parameters:\n${JSON.stringify(i
|
|
|
180
185
|
},
|
|
181
186
|
});
|
|
182
187
|
|
|
183
|
-
|
|
184
|
-
|
|
188
|
+
state.messages.push(toolCallingMessage);
|
|
189
|
+
state.history.push(
|
|
190
|
+
createHistoryStep<HistoryStep>(state.history, {
|
|
185
191
|
type: NodeType.BROWSER_TASK,
|
|
186
192
|
nodeId: node.name,
|
|
187
193
|
nodeDisplayName: node.displayName,
|
|
188
194
|
raw: error,
|
|
189
195
|
messageIds: [errorMessageId],
|
|
190
196
|
}),
|
|
191
|
-
|
|
192
|
-
|
|
197
|
+
);
|
|
198
|
+
return state;
|
|
193
199
|
}
|
|
194
200
|
};
|
|
195
201
|
graph.addNode(node.name, callback);
|
|
@@ -33,7 +33,6 @@ export const addBrowserTaskRunNode = async ({ graph, browserTaskNode, attachedTo
|
|
|
33
33
|
const { sessionId, cdpUrl, keepAlive, hooks, outputSchema } = toolCallMindedMetadata;
|
|
34
34
|
|
|
35
35
|
try {
|
|
36
|
-
|
|
37
36
|
if (inputParams.error) {
|
|
38
37
|
throw new Error(inputParams.error);
|
|
39
38
|
}
|
|
@@ -112,16 +111,17 @@ export const addBrowserTaskRunNode = async ({ graph, browserTaskNode, attachedTo
|
|
|
112
111
|
},
|
|
113
112
|
});
|
|
114
113
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
114
|
+
state.messages.push(toolMessage, updatedAIMessage);
|
|
115
|
+
state.history.push(
|
|
116
|
+
createHistoryStep<HistoryStep>(state.history, {
|
|
118
117
|
type: NodeType.BROWSER_TASK,
|
|
119
118
|
nodeId: browserTaskNode.name,
|
|
120
119
|
nodeDisplayName: browserTaskNode.displayName,
|
|
121
120
|
raw: result,
|
|
122
121
|
messageIds: [toolMessage.id!],
|
|
123
122
|
}),
|
|
124
|
-
|
|
123
|
+
);
|
|
124
|
+
return state;
|
|
125
125
|
} catch (error: any) {
|
|
126
126
|
logger.error({ msg: 'Error executing browser task run node', error: error.toString() });
|
|
127
127
|
|
|
@@ -163,16 +163,17 @@ export const addBrowserTaskRunNode = async ({ graph, browserTaskNode, attachedTo
|
|
|
163
163
|
},
|
|
164
164
|
});
|
|
165
165
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
166
|
+
state.messages.push(errorToolMessage, updatedAIMessage);
|
|
167
|
+
state.history.push(
|
|
168
|
+
createHistoryStep<HistoryStep>(state.history, {
|
|
169
169
|
type: NodeType.BROWSER_TASK,
|
|
170
170
|
nodeId: browserTaskNode.name,
|
|
171
171
|
nodeDisplayName: browserTaskNode.displayName,
|
|
172
172
|
raw: error,
|
|
173
173
|
messageIds: [],
|
|
174
174
|
}),
|
|
175
|
-
|
|
175
|
+
);
|
|
176
|
+
return state;
|
|
176
177
|
}
|
|
177
178
|
};
|
|
178
179
|
|
|
@@ -9,15 +9,16 @@ export const addJumpToNode = async ({ graph, node }: { graph: PreCompiledGraph;
|
|
|
9
9
|
const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
|
|
10
10
|
logger.info({ msg: `Executing jump node ${node.displayName} – jumping to ${node.targetNodeId}` });
|
|
11
11
|
// No state modifications are necessary; control flow is handled via edges.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
state.goto = node.targetNodeId;
|
|
13
|
+
state.history.push(
|
|
14
|
+
createHistoryStep<HistoryStep>(state.history, {
|
|
15
15
|
type: NodeType.JUMP_TO_NODE,
|
|
16
16
|
nodeId: node.name,
|
|
17
17
|
nodeDisplayName: node.displayName,
|
|
18
18
|
raw: '',
|
|
19
19
|
}),
|
|
20
|
-
|
|
20
|
+
);
|
|
21
|
+
return state;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
graph.addNode(node.name, callback);
|
|
@@ -6,15 +6,16 @@ import { HistoryStep } from '../types/Agent.types';
|
|
|
6
6
|
|
|
7
7
|
export const addJunctionNode = ({ graph, node }: { graph: PreCompiledGraph; node: JunctionNode }) => {
|
|
8
8
|
const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
state.goto = null;
|
|
10
|
+
state.history.push(
|
|
11
|
+
createHistoryStep<HistoryStep>(state.history, {
|
|
12
12
|
type: NodeType.JUNCTION,
|
|
13
13
|
nodeId: node.name,
|
|
14
14
|
nodeDisplayName: node.displayName,
|
|
15
15
|
raw: '',
|
|
16
16
|
}),
|
|
17
|
-
|
|
17
|
+
);
|
|
18
|
+
return state;
|
|
18
19
|
};
|
|
19
20
|
graph.addNode(node.name, callback);
|
|
20
21
|
};
|