@memberjunction/ai-agents 6.2.2 → 6.3.0-edge.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/README.md +29 -6
- package/dist/AgentContextAssembler.d.ts +127 -0
- package/dist/AgentContextAssembler.d.ts.map +1 -0
- package/dist/AgentContextAssembler.js +482 -0
- package/dist/AgentContextAssembler.js.map +1 -0
- package/dist/AgentDataPreloader.d.ts +14 -3
- package/dist/AgentDataPreloader.d.ts.map +1 -1
- package/dist/AgentDataPreloader.js +147 -22
- package/dist/AgentDataPreloader.js.map +1 -1
- package/dist/AgentDecisionService.d.ts +10 -1
- package/dist/AgentDecisionService.d.ts.map +1 -1
- package/dist/AgentDecisionService.js +28 -13
- package/dist/AgentDecisionService.js.map +1 -1
- package/dist/AgentFeedbackCoordinator.d.ts +169 -0
- package/dist/AgentFeedbackCoordinator.d.ts.map +1 -0
- package/dist/AgentFeedbackCoordinator.js +593 -0
- package/dist/AgentFeedbackCoordinator.js.map +1 -0
- package/dist/AgentRunner.d.ts +57 -15
- package/dist/AgentRunner.d.ts.map +1 -1
- package/dist/AgentRunner.js +692 -101
- package/dist/AgentRunner.js.map +1 -1
- package/dist/AgentStepDispatcher.d.ts +211 -0
- package/dist/AgentStepDispatcher.d.ts.map +1 -0
- package/dist/AgentStepDispatcher.js +729 -0
- package/dist/AgentStepDispatcher.js.map +1 -0
- package/dist/AgentTreeBudgetTracker.d.ts +163 -0
- package/dist/AgentTreeBudgetTracker.d.ts.map +1 -0
- package/dist/AgentTreeBudgetTracker.js +415 -0
- package/dist/AgentTreeBudgetTracker.js.map +1 -0
- package/dist/AgentWakeTriggerService.d.ts +41 -1
- package/dist/AgentWakeTriggerService.d.ts.map +1 -1
- package/dist/AgentWakeTriggerService.js +154 -8
- package/dist/AgentWakeTriggerService.js.map +1 -1
- package/dist/ArtifactToolManager.d.ts +134 -39
- package/dist/ArtifactToolManager.d.ts.map +1 -1
- package/dist/ArtifactToolManager.js +2761 -321
- package/dist/ArtifactToolManager.js.map +1 -1
- package/dist/GovernedArtifactService.d.ts +367 -0
- package/dist/GovernedArtifactService.d.ts.map +1 -0
- package/dist/GovernedArtifactService.js +2569 -0
- package/dist/GovernedArtifactService.js.map +1 -0
- package/dist/MJAIAgentRequestEntityServer.d.ts +32 -1
- package/dist/MJAIAgentRequestEntityServer.d.ts.map +1 -1
- package/dist/MJAIAgentRequestEntityServer.js +105 -3
- package/dist/MJAIAgentRequestEntityServer.js.map +1 -1
- package/dist/SkillMarkdownConverter.d.ts +1 -1
- package/dist/SkillMarkdownConverter.d.ts.map +1 -1
- package/dist/SkillMarkdownConverter.js +8 -6
- package/dist/SkillMarkdownConverter.js.map +1 -1
- package/dist/agent-context-injector.d.ts +2 -25
- package/dist/agent-context-injector.d.ts.map +1 -1
- package/dist/agent-context-injector.js +38 -153
- package/dist/agent-context-injector.js.map +1 -1
- package/dist/agent-instance.d.ts +28 -0
- package/dist/agent-instance.d.ts.map +1 -0
- package/dist/agent-instance.js +39 -0
- package/dist/agent-instance.js.map +1 -0
- package/dist/agent-memory-context-builder.d.ts.map +1 -1
- package/dist/agent-memory-context-builder.js +46 -42
- package/dist/agent-memory-context-builder.js.map +1 -1
- package/dist/agent-pre-execution-rag.d.ts +5 -0
- package/dist/agent-pre-execution-rag.d.ts.map +1 -1
- package/dist/agent-pre-execution-rag.js +10 -0
- package/dist/agent-pre-execution-rag.js.map +1 -1
- package/dist/agent-run-watchdog.d.ts +38 -6
- package/dist/agent-run-watchdog.d.ts.map +1 -1
- package/dist/agent-run-watchdog.js +75 -13
- package/dist/agent-run-watchdog.js.map +1 -1
- package/dist/agent-types/flow-agent-type.d.ts +6 -1
- package/dist/agent-types/flow-agent-type.d.ts.map +1 -1
- package/dist/agent-types/flow-agent-type.js +30 -7
- package/dist/agent-types/flow-agent-type.js.map +1 -1
- package/dist/agent-types/loop-agent-prompt-params.d.ts +18 -0
- package/dist/agent-types/loop-agent-prompt-params.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-prompt-params.js +2 -0
- package/dist/agent-types/loop-agent-prompt-params.js.map +1 -1
- package/dist/agent-types/loop-agent-type.d.ts +4 -0
- package/dist/agent-types/loop-agent-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-type.js +29 -0
- package/dist/agent-types/loop-agent-type.js.map +1 -1
- package/dist/artifact-presence-locator.d.ts +132 -0
- package/dist/artifact-presence-locator.d.ts.map +1 -0
- package/dist/artifact-presence-locator.js +472 -0
- package/dist/artifact-presence-locator.js.map +1 -0
- package/dist/artifact-tools/CSVToolLibrary.d.ts +2 -2
- package/dist/artifact-tools/CSVToolLibrary.d.ts.map +1 -1
- package/dist/artifact-tools/CSVToolLibrary.js +41 -14
- package/dist/artifact-tools/CSVToolLibrary.js.map +1 -1
- package/dist/artifact-tools/DataSnapshotToolLibrary.d.ts +2 -2
- package/dist/artifact-tools/DataSnapshotToolLibrary.d.ts.map +1 -1
- package/dist/artifact-tools/DataSnapshotToolLibrary.js +53 -21
- package/dist/artifact-tools/DataSnapshotToolLibrary.js.map +1 -1
- package/dist/artifact-tools/DocumentToolLibrary.d.ts +101 -0
- package/dist/artifact-tools/DocumentToolLibrary.d.ts.map +1 -0
- package/dist/artifact-tools/DocumentToolLibrary.js +1846 -0
- package/dist/artifact-tools/DocumentToolLibrary.js.map +1 -0
- package/dist/artifact-tools/DocxToolLibrary.d.ts +2 -4
- package/dist/artifact-tools/DocxToolLibrary.d.ts.map +1 -1
- package/dist/artifact-tools/DocxToolLibrary.js +42 -30
- package/dist/artifact-tools/DocxToolLibrary.js.map +1 -1
- package/dist/artifact-tools/ExcelToolLibrary.d.ts +2 -3
- package/dist/artifact-tools/ExcelToolLibrary.d.ts.map +1 -1
- package/dist/artifact-tools/ExcelToolLibrary.js +105 -49
- package/dist/artifact-tools/ExcelToolLibrary.js.map +1 -1
- package/dist/artifact-tools/GenericBinaryToolLibrary.d.ts +2 -2
- package/dist/artifact-tools/GenericBinaryToolLibrary.d.ts.map +1 -1
- package/dist/artifact-tools/GenericBinaryToolLibrary.js +3 -2
- package/dist/artifact-tools/GenericBinaryToolLibrary.js.map +1 -1
- package/dist/artifact-tools/JSONToolLibrary.d.ts +4 -4
- package/dist/artifact-tools/JSONToolLibrary.d.ts.map +1 -1
- package/dist/artifact-tools/JSONToolLibrary.js +32 -11
- package/dist/artifact-tools/JSONToolLibrary.js.map +1 -1
- package/dist/artifact-tools/PDFToolLibrary.d.ts +27 -3
- package/dist/artifact-tools/PDFToolLibrary.d.ts.map +1 -1
- package/dist/artifact-tools/PDFToolLibrary.js +36 -21
- package/dist/artifact-tools/PDFToolLibrary.js.map +1 -1
- package/dist/artifact-tools/SearchResultSetToolLibrary.d.ts +2 -2
- package/dist/artifact-tools/SearchResultSetToolLibrary.d.ts.map +1 -1
- package/dist/artifact-tools/SearchResultSetToolLibrary.js +83 -24
- package/dist/artifact-tools/SearchResultSetToolLibrary.js.map +1 -1
- package/dist/artifact-tools/SlideDeckToolLibrary.d.ts +50 -0
- package/dist/artifact-tools/SlideDeckToolLibrary.d.ts.map +1 -0
- package/dist/artifact-tools/SlideDeckToolLibrary.js +1617 -0
- package/dist/artifact-tools/SlideDeckToolLibrary.js.map +1 -0
- package/dist/artifact-tools/SpreadsheetToolLibrary.d.ts +87 -0
- package/dist/artifact-tools/SpreadsheetToolLibrary.d.ts.map +1 -0
- package/dist/artifact-tools/SpreadsheetToolLibrary.js +3351 -0
- package/dist/artifact-tools/SpreadsheetToolLibrary.js.map +1 -0
- package/dist/artifact-tools/TextToolLibrary.d.ts +3 -3
- package/dist/artifact-tools/TextToolLibrary.d.ts.map +1 -1
- package/dist/artifact-tools/TextToolLibrary.js +34 -24
- package/dist/artifact-tools/TextToolLibrary.js.map +1 -1
- package/dist/artifact-tools/WhiteboardToolLibrary.d.ts +69 -0
- package/dist/artifact-tools/WhiteboardToolLibrary.d.ts.map +1 -0
- package/dist/artifact-tools/WhiteboardToolLibrary.js +555 -0
- package/dist/artifact-tools/WhiteboardToolLibrary.js.map +1 -0
- package/dist/artifact-tools/artifact-comment-suggestion-helper.d.ts +98 -0
- package/dist/artifact-tools/artifact-comment-suggestion-helper.d.ts.map +1 -0
- package/dist/artifact-tools/artifact-comment-suggestion-helper.js +851 -0
- package/dist/artifact-tools/artifact-comment-suggestion-helper.js.map +1 -0
- package/dist/artifact-tools/artifact-tool-helpers.d.ts +21 -0
- package/dist/artifact-tools/artifact-tool-helpers.d.ts.map +1 -0
- package/dist/artifact-tools/artifact-tool-helpers.js +74 -0
- package/dist/artifact-tools/artifact-tool-helpers.js.map +1 -0
- package/dist/artifact-tools/grepHelper.d.ts +27 -0
- package/dist/artifact-tools/grepHelper.d.ts.map +1 -0
- package/dist/artifact-tools/grepHelper.js +229 -0
- package/dist/artifact-tools/grepHelper.js.map +1 -0
- package/dist/artifact-tools/node-vm-safe-regex.d.ts +10 -0
- package/dist/artifact-tools/node-vm-safe-regex.d.ts.map +1 -0
- package/dist/artifact-tools/node-vm-safe-regex.js +148 -0
- package/dist/artifact-tools/node-vm-safe-regex.js.map +1 -0
- package/dist/base-agent.d.ts +151 -137
- package/dist/base-agent.d.ts.map +1 -1
- package/dist/base-agent.js +727 -1550
- package/dist/base-agent.js.map +1 -1
- package/dist/catalog-narrowing.d.ts +112 -5
- package/dist/catalog-narrowing.d.ts.map +1 -1
- package/dist/catalog-narrowing.js +181 -6
- package/dist/catalog-narrowing.js.map +1 -1
- package/dist/decision-discovery.d.ts +42 -15
- package/dist/decision-discovery.d.ts.map +1 -1
- package/dist/decision-discovery.js +90 -20
- package/dist/decision-discovery.js.map +1 -1
- package/dist/index.d.ts +17 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -3
- package/dist/index.js.map +1 -1
- package/dist/memory-decision-uses.d.ts +206 -0
- package/dist/memory-decision-uses.d.ts.map +1 -0
- package/dist/memory-decision-uses.js +259 -0
- package/dist/memory-decision-uses.js.map +1 -0
- package/dist/memory-manager-agent.d.ts +66 -6
- package/dist/memory-manager-agent.d.ts.map +1 -1
- package/dist/memory-manager-agent.js +184 -31
- package/dist/memory-manager-agent.js.map +1 -1
- package/dist/memory-note-gate.d.ts +12 -9
- package/dist/memory-note-gate.d.ts.map +1 -1
- package/dist/memory-note-gate.js +16 -11
- package/dist/memory-note-gate.js.map +1 -1
- package/dist/native-tools/control-tools.d.ts +8 -1
- package/dist/native-tools/control-tools.d.ts.map +1 -1
- package/dist/native-tools/control-tools.js +38 -5
- package/dist/native-tools/control-tools.js.map +1 -1
- package/dist/native-tools/framework-tools.d.ts +3 -3
- package/dist/native-tools/framework-tools.d.ts.map +1 -1
- package/dist/native-tools/framework-tools.js +20 -8
- package/dist/native-tools/framework-tools.js.map +1 -1
- package/dist/pipeline/operators.d.ts.map +1 -1
- package/dist/pipeline/operators.js +1 -1
- package/dist/pipeline/operators.js.map +1 -1
- package/dist/pipeline/pipeline-executor.d.ts +29 -1
- package/dist/pipeline/pipeline-executor.d.ts.map +1 -1
- package/dist/pipeline/pipeline-executor.js +159 -2
- package/dist/pipeline/pipeline-executor.js.map +1 -1
- package/dist/pipeline/pipeline.types.d.ts +19 -1
- package/dist/pipeline/pipeline.types.d.ts.map +1 -1
- package/dist/pipeline/template.d.ts +16 -0
- package/dist/pipeline/template.d.ts.map +1 -1
- package/dist/pipeline/template.js +55 -6
- package/dist/pipeline/template.js.map +1 -1
- package/dist/realtime/artifact-workspace-channel-server.d.ts +27 -0
- package/dist/realtime/artifact-workspace-channel-server.d.ts.map +1 -0
- package/dist/realtime/artifact-workspace-channel-server.js +43 -0
- package/dist/realtime/artifact-workspace-channel-server.js.map +1 -0
- package/dist/realtime/bridge-realtime-session-factory.d.ts +2 -2
- package/dist/realtime/bridge-realtime-session-factory.d.ts.map +1 -1
- package/dist/realtime/bridge-realtime-session-factory.js +7 -56
- package/dist/realtime/bridge-realtime-session-factory.js.map +1 -1
- package/dist/realtime/bridge-room-transcript-sink.d.ts.map +1 -1
- package/dist/realtime/bridge-room-transcript-sink.js +28 -1
- package/dist/realtime/bridge-room-transcript-sink.js.map +1 -1
- package/dist/realtime/media-channel-server.js +1 -1
- package/dist/realtime/media-channel-server.js.map +1 -1
- package/dist/realtime/realtime-artifact-helpers.d.ts +37 -0
- package/dist/realtime/realtime-artifact-helpers.d.ts.map +1 -0
- package/dist/realtime/realtime-artifact-helpers.js +150 -0
- package/dist/realtime/realtime-artifact-helpers.js.map +1 -0
- package/dist/realtime/realtime-client-session-service.d.ts +209 -19
- package/dist/realtime/realtime-client-session-service.d.ts.map +1 -1
- package/dist/realtime/realtime-client-session-service.js +670 -41
- package/dist/realtime/realtime-client-session-service.js.map +1 -1
- package/dist/realtime/realtime-coagent-config.d.ts +26 -9
- package/dist/realtime/realtime-coagent-config.d.ts.map +1 -1
- package/dist/realtime/realtime-coagent-config.js +47 -60
- package/dist/realtime/realtime-coagent-config.js.map +1 -1
- package/dist/realtime/realtime-delegation-narrator.js +1 -1
- package/dist/realtime/realtime-delegation-narrator.js.map +1 -1
- package/dist/realtime/realtime-moderator-decision.d.ts +86 -0
- package/dist/realtime/realtime-moderator-decision.d.ts.map +1 -0
- package/dist/realtime/realtime-moderator-decision.js +131 -0
- package/dist/realtime/realtime-moderator-decision.js.map +1 -0
- package/dist/realtime/realtime-session-runner.d.ts +2 -0
- package/dist/realtime/realtime-session-runner.d.ts.map +1 -1
- package/dist/realtime/realtime-session-runner.js +24 -3
- package/dist/realtime/realtime-session-runner.js.map +1 -1
- package/dist/realtime/realtime-tool-broker.d.ts +6 -0
- package/dist/realtime/realtime-tool-broker.d.ts.map +1 -1
- package/dist/realtime/realtime-tool-broker.js +4 -2
- package/dist/realtime/realtime-tool-broker.js.map +1 -1
- package/dist/realtime/realtime-turn-moderator.d.ts +20 -0
- package/dist/realtime/realtime-turn-moderator.d.ts.map +1 -1
- package/dist/realtime/realtime-turn-moderator.js +63 -8
- package/dist/realtime/realtime-turn-moderator.js.map +1 -1
- package/dist/repeated-failing-step.d.ts +50 -0
- package/dist/repeated-failing-step.d.ts.map +1 -0
- package/dist/repeated-failing-step.js +130 -0
- package/dist/repeated-failing-step.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +20 -20
|
@@ -9,12 +9,13 @@ import { BaseAgent } from './base-agent.js';
|
|
|
9
9
|
import { RegisterClass, CleanAndParseJSON, IsPlainObject } from '@memberjunction/global';
|
|
10
10
|
import { RunView, RunQuery, LogError, LogStatus, LogStatusEx } from '@memberjunction/core';
|
|
11
11
|
import { IsInjectableNoteStatus } from '@memberjunction/core-entities';
|
|
12
|
-
import { AIPromptRunner } from '@memberjunction/ai-prompts';
|
|
12
|
+
import { AIPromptRunner, RunDecisionUse, ResolveDecisionUseMode } from '@memberjunction/ai-prompts';
|
|
13
13
|
import { AIPromptParams, DescribeAnsweringModel } from '@memberjunction/ai-core-plus';
|
|
14
14
|
import { AIEngine } from '@memberjunction/aiengine';
|
|
15
15
|
import { UUIDsEqual } from '@memberjunction/global';
|
|
16
16
|
import { AgentDecisionService } from './AgentDecisionService.js';
|
|
17
17
|
import { BuildMemoryNoteQuestions, BuildMemoryNoteState, JudgeMemoryNotes, MemoryNotePromptQuestionCap, ChunkMemoryNotes, GroupMemoryNotesByConversation, MEMORY_NOTE_MIN_PROBABILITY } from './memory-note-gate.js';
|
|
18
|
+
import { BuildContradictionDecision, BuildExampleDedupeDecision, BuildNoteDedupeDecision, CompareContradictionDecision, CompareDedupeDecision, ContradictionVerdictFromDecision, DedupeVerdictFromDecision, MEMORY_CONTRADICTION_USE, MEMORY_DECISION_DEFAULT_MODE, MEMORY_EXAMPLE_DEDUPE_CALIBRATION_KEY, MEMORY_EXAMPLE_DEDUPE_USE, MEMORY_NOTE_DEDUPE_CALIBRATION_KEY, MEMORY_NOTE_DEDUPE_USE } from './memory-decision-uses.js';
|
|
18
19
|
/**
|
|
19
20
|
* Configuration for extraction limits to ensure sparsity
|
|
20
21
|
*/
|
|
@@ -119,6 +120,21 @@ function isValidNoteType(value) {
|
|
|
119
120
|
}
|
|
120
121
|
/** Reusable parameter object for deterministic (temperature=0) LLM prompt calls. */
|
|
121
122
|
const DETERMINISTIC_PROMPT_PARAMS = { temperature: 0 };
|
|
123
|
+
/** The model that answered a decision, as its result reports it. */
|
|
124
|
+
function answeredByOf(run) {
|
|
125
|
+
return { ModelName: run.modelInfo?.modelName, ResolvedModel: run.DecisionResult?.ResolvedModel };
|
|
126
|
+
}
|
|
127
|
+
/** A stored note as the contradiction decision and its authority rule read it. */
|
|
128
|
+
function contradictionNoteOf(note) {
|
|
129
|
+
return {
|
|
130
|
+
ID: note.ID,
|
|
131
|
+
Type: note.Type,
|
|
132
|
+
Note: note.Note,
|
|
133
|
+
CreatedAt: note.__mj_CreatedAt,
|
|
134
|
+
ImportanceScore: note.ImportanceScore,
|
|
135
|
+
AccessCount: note.AccessCount
|
|
136
|
+
};
|
|
137
|
+
}
|
|
122
138
|
/**
|
|
123
139
|
* Hard cap on `resolveOriginalSources()` recursion depth.
|
|
124
140
|
* The `visited` set already prevents cycles, but a depth limit protects against
|
|
@@ -144,15 +160,24 @@ let MemoryManagerAgent = class MemoryManagerAgent extends BaseAgent {
|
|
|
144
160
|
this._stepCounter = 0;
|
|
145
161
|
/** Context user for step operations */
|
|
146
162
|
this._contextUser = null;
|
|
147
|
-
/**
|
|
148
|
-
|
|
163
|
+
/**
|
|
164
|
+
* Whether the typed decision gate may replace the self-confidence threshold. On by default; it
|
|
165
|
+
* still needs the master switch ({@link DecisionsEnabled}), and a run turns it off with
|
|
166
|
+
* `data.enableDecisionGate: false`.
|
|
167
|
+
*/
|
|
168
|
+
this._enableDecisionGate = true;
|
|
169
|
+
/**
|
|
170
|
+
* How the run answers its dedupe and contradiction calls (`data.memoryDecisionMode`), see
|
|
171
|
+
* {@link MEMORY_DECISION_DEFAULT_MODE}.
|
|
172
|
+
*/
|
|
173
|
+
this._memoryDecisionMode = MEMORY_DECISION_DEFAULT_MODE;
|
|
149
174
|
}
|
|
150
175
|
static { MemoryManagerAgent_1 = this; }
|
|
151
176
|
/**
|
|
152
|
-
* Whether the typed decision gate is enabled for filtering extracted memory notes.
|
|
153
|
-
* When false
|
|
154
|
-
*
|
|
155
|
-
*
|
|
177
|
+
* Whether the typed decision gate is enabled for filtering extracted memory notes. True by
|
|
178
|
+
* default. When false, or when the master switch is off (the run's agent-type prompt params must
|
|
179
|
+
* set `decisionsEnabled: true`, {@link DecisionsEnabled}), the self-reported confidence filter
|
|
180
|
+
* (confidence >= 80) is used.
|
|
156
181
|
*/
|
|
157
182
|
get EnableDecisionGate() {
|
|
158
183
|
return this._enableDecisionGate;
|
|
@@ -737,7 +762,7 @@ let MemoryManagerAgent = class MemoryManagerAgent extends BaseAgent {
|
|
|
737
762
|
LogStatus('Memory Manager: No candidates passed content length check before decision gate');
|
|
738
763
|
return [];
|
|
739
764
|
}
|
|
740
|
-
const cap = MemoryNotePromptQuestionCap(AIEngine.Instance,
|
|
765
|
+
const cap = MemoryNotePromptQuestionCap(AIEngine.Instance, this.decisionPromptName());
|
|
741
766
|
const grouping = GroupMemoryNotesByConversation(lengthFiltered, conversationThreads.map(t => ({
|
|
742
767
|
ConversationId: t.conversationId,
|
|
743
768
|
Turns: t.messages.map(m => ({ role: m.role, text: m.message }))
|
|
@@ -773,10 +798,11 @@ let MemoryManagerAgent = class MemoryManagerAgent extends BaseAgent {
|
|
|
773
798
|
const decisionService = this._agentDecisionService ?? new AgentDecisionService();
|
|
774
799
|
const result = await decisionService.Ask({
|
|
775
800
|
ContextUser: contextUser,
|
|
776
|
-
PromptName:
|
|
801
|
+
PromptName: this.decisionPromptName(),
|
|
777
802
|
State: state,
|
|
778
803
|
Questions: questions,
|
|
779
804
|
AgentID: this.AgentRun?.AgentID ?? undefined,
|
|
805
|
+
ExecutionScope: this._memoryDecisionScope,
|
|
780
806
|
CancellationToken: this._cancellationToken
|
|
781
807
|
});
|
|
782
808
|
await this.recordDecisionStep(step, result);
|
|
@@ -810,7 +836,7 @@ let MemoryManagerAgent = class MemoryManagerAgent extends BaseAgent {
|
|
|
810
836
|
return;
|
|
811
837
|
}
|
|
812
838
|
MemoryManagerAgent_1._uncalibratedGateModelsLogged.add(described);
|
|
813
|
-
LogStatus(`Memory Manager: ${described} has no memory-note calibration (
|
|
839
|
+
LogStatus(`Memory Manager: ${described} has no memory-note calibration (use 'memory-note-gate' in its ModelConfiguration.Decision.Calibrations), so the decision gate falls back to the confidence filter for its batches`);
|
|
814
840
|
}
|
|
815
841
|
/**
|
|
816
842
|
* Applies calibrated probabilities to judge which candidate notes to keep. A note the calibrated
|
|
@@ -938,7 +964,7 @@ let MemoryManagerAgent = class MemoryManagerAgent extends BaseAgent {
|
|
|
938
964
|
LogStatus(`Memory Manager: Approved note (no similar notes found): "${candidate.content.substring(0, 50)}..."`);
|
|
939
965
|
return true;
|
|
940
966
|
}
|
|
941
|
-
const decision = await this.
|
|
967
|
+
const decision = await this.decideNoteDedupe(runner, dedupePrompt, candidate, similarNotes, contextUser);
|
|
942
968
|
stats.llmCallCount++;
|
|
943
969
|
if (decision.shouldAdd) {
|
|
944
970
|
if (this._verbose)
|
|
@@ -977,6 +1003,131 @@ let MemoryManagerAgent = class MemoryManagerAgent extends BaseAgent {
|
|
|
977
1003
|
}
|
|
978
1004
|
return { shouldAdd: false, reason: result.result?.reason || 'too similar to existing notes' };
|
|
979
1005
|
}
|
|
1006
|
+
/**
|
|
1007
|
+
* Whether a candidate note adds to its similar stored notes, answered in the run's memory decision
|
|
1008
|
+
* mode: by the dedupe prompt, by the prompt with a decision recorded beside it (`Shadow`), or by a
|
|
1009
|
+
* calibrated decision that falls back to the prompt when unsure (`Decision`). Fails closed as the
|
|
1010
|
+
* prompt does: no path adds a note on a failure.
|
|
1011
|
+
*/
|
|
1012
|
+
async decideNoteDedupe(runner, dedupePrompt, candidate, similarNotes, contextUser) {
|
|
1013
|
+
const request = BuildNoteDedupeDecision(candidate, similarNotes.map(s => ({
|
|
1014
|
+
type: s.note.Type,
|
|
1015
|
+
content: s.note.Note ?? '',
|
|
1016
|
+
similarity: s.similarity
|
|
1017
|
+
})));
|
|
1018
|
+
return this.runMemoryDecisionUse(MEMORY_NOTE_DEDUPE_USE, request, contextUser, {
|
|
1019
|
+
FromDecision: (run, answeredBy) => DedupeVerdictFromDecision(run.Answers, MEMORY_NOTE_DEDUPE_CALIBRATION_KEY, answeredBy),
|
|
1020
|
+
Compare: (answers, existing, answeredBy) => CompareDedupeDecision(answers, existing, MEMORY_NOTE_DEDUPE_CALIBRATION_KEY, answeredBy),
|
|
1021
|
+
RunExisting: () => this.runDedupePromptForCandidate(runner, dedupePrompt, candidate, similarNotes, contextUser)
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* Whether a candidate example adds to its similar stored examples, answered in the run's memory
|
|
1026
|
+
* decision mode, as {@link decideNoteDedupe} answers it for notes.
|
|
1027
|
+
*/
|
|
1028
|
+
async decideExampleDedupe(runner, dedupePrompt, candidate, similarExamples, contextUser) {
|
|
1029
|
+
const request = BuildExampleDedupeDecision(candidate, similarExamples.map(s => ({
|
|
1030
|
+
input: s.example.ExampleInput ?? '',
|
|
1031
|
+
output: s.example.ExampleOutput ?? '',
|
|
1032
|
+
successScore: s.example.SuccessScore,
|
|
1033
|
+
similarity: s.similarity
|
|
1034
|
+
})));
|
|
1035
|
+
return this.runMemoryDecisionUse(MEMORY_EXAMPLE_DEDUPE_USE, request, contextUser, {
|
|
1036
|
+
FromDecision: (run, answeredBy) => DedupeVerdictFromDecision(run.Answers, MEMORY_EXAMPLE_DEDUPE_CALIBRATION_KEY, answeredBy),
|
|
1037
|
+
Compare: (answers, existing, answeredBy) => CompareDedupeDecision(answers, existing, MEMORY_EXAMPLE_DEDUPE_CALIBRATION_KEY, answeredBy),
|
|
1038
|
+
RunExisting: () => this.runExampleDedupePrompt(runner, dedupePrompt, candidate, similarExamples, contextUser)
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
* Invoke the example dedupe LLM prompt for one candidate against its similar stored examples. A
|
|
1043
|
+
* failed or unreadable call skips the example.
|
|
1044
|
+
*/
|
|
1045
|
+
async runExampleDedupePrompt(runner, dedupePrompt, candidate, similarExamples, contextUser) {
|
|
1046
|
+
const dedupeParams = new AIPromptParams();
|
|
1047
|
+
dedupeParams.prompt = dedupePrompt;
|
|
1048
|
+
dedupeParams.data = {
|
|
1049
|
+
candidateExample: candidate,
|
|
1050
|
+
similarExamples: similarExamples.map(s => ({
|
|
1051
|
+
input: s.example.ExampleInput,
|
|
1052
|
+
output: s.example.ExampleOutput,
|
|
1053
|
+
successScore: s.example.SuccessScore,
|
|
1054
|
+
similarity: s.similarity
|
|
1055
|
+
}))
|
|
1056
|
+
};
|
|
1057
|
+
dedupeParams.contextUser = contextUser;
|
|
1058
|
+
dedupeParams.attemptJSONRepair = true;
|
|
1059
|
+
dedupeParams.additionalParameters = { temperature: 0 };
|
|
1060
|
+
const result = await runner.ExecutePrompt(dedupeParams);
|
|
1061
|
+
if (result.success && result.result) {
|
|
1062
|
+
return { shouldAdd: result.result.shouldAdd === true, reason: result.result.reason || '' };
|
|
1063
|
+
}
|
|
1064
|
+
return { shouldAdd: false, reason: result.result?.reason || 'too similar' };
|
|
1065
|
+
}
|
|
1066
|
+
/**
|
|
1067
|
+
* Answers one Memory Manager closed-set call through `RunDecisionUse`, in the run's mode. The
|
|
1068
|
+
* decision is built from the run's decision prompt and execution scope, and asked only in `Shadow`
|
|
1069
|
+
* and `Decision` modes.
|
|
1070
|
+
*/
|
|
1071
|
+
async runMemoryDecisionUse(use, request, contextUser, handlers) {
|
|
1072
|
+
const outcome = await RunDecisionUse({
|
|
1073
|
+
Use: use,
|
|
1074
|
+
Mode: this.effectiveMemoryDecisionMode(),
|
|
1075
|
+
BuildDecision: () => this.buildMemoryDecision(request, contextUser),
|
|
1076
|
+
FromDecision: run => handlers.FromDecision(run, answeredByOf(run)),
|
|
1077
|
+
RunExisting: handlers.RunExisting,
|
|
1078
|
+
Compare: (answers, existing, run) => handlers.Compare(answers, existing, answeredByOf(run)),
|
|
1079
|
+
Runner: this.CreateMemoryDecisionRunner()
|
|
1080
|
+
});
|
|
1081
|
+
if (this._verbose && outcome.AnsweredBy === 'Decision') {
|
|
1082
|
+
LogStatus(`Memory Manager: '${use}' answered by the decision model`);
|
|
1083
|
+
}
|
|
1084
|
+
return outcome.Value;
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* The mode the run's dedupe and contradiction calls use: the configured `data.memoryDecisionMode`,
|
|
1088
|
+
* or `Prompt` when the master switch for decision-model use is off ({@link DecisionsEnabled}),
|
|
1089
|
+
* since a shadow decision is a decision call too.
|
|
1090
|
+
*/
|
|
1091
|
+
effectiveMemoryDecisionMode() {
|
|
1092
|
+
return this.DecisionsEnabled(this._runPromptParams) ? this._memoryDecisionMode : 'Prompt';
|
|
1093
|
+
}
|
|
1094
|
+
/** A Memory Manager decision as the runner takes it, or null when the decision prompt is missing. */
|
|
1095
|
+
buildMemoryDecision(request, contextUser) {
|
|
1096
|
+
return AgentDecisionService.BuildDecisionParams({
|
|
1097
|
+
ContextUser: contextUser,
|
|
1098
|
+
PromptName: this.decisionPromptName(),
|
|
1099
|
+
State: request.State,
|
|
1100
|
+
Questions: request.Questions,
|
|
1101
|
+
AgentID: this.AgentRun?.AgentID ?? undefined,
|
|
1102
|
+
ExecutionScope: this._memoryDecisionScope,
|
|
1103
|
+
CancellationToken: this._cancellationToken
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
/**
|
|
1107
|
+
* The runner `RunDecisionUse` asks the Memory Manager's decisions with, or undefined for a new
|
|
1108
|
+
* `AIDecisionRunner`. An override point for tests and for hosts that route decisions elsewhere.
|
|
1109
|
+
*/
|
|
1110
|
+
CreateMemoryDecisionRunner() {
|
|
1111
|
+
return undefined;
|
|
1112
|
+
}
|
|
1113
|
+
/** The run's decision prompt: its agent-type prompt params' `decisionPromptName`, else `Default Decision`. */
|
|
1114
|
+
decisionPromptName() {
|
|
1115
|
+
const name = this._runPromptParams?.decisionPromptName;
|
|
1116
|
+
return typeof name === 'string' && name.trim().length > 0 ? name : AgentDecisionService.DEFAULT_PROMPT_NAME;
|
|
1117
|
+
}
|
|
1118
|
+
/**
|
|
1119
|
+
* The run's execution scope for its decision calls: the scope `BaseAgent` recorded for the run,
|
|
1120
|
+
* or, when this run did not start through `Execute`, the same scope built from its params.
|
|
1121
|
+
*/
|
|
1122
|
+
memoryDecisionScope(params) {
|
|
1123
|
+
return this.RunExecutionScope ?? {
|
|
1124
|
+
contextUser: params.contextUser,
|
|
1125
|
+
provider: params.provider,
|
|
1126
|
+
configurationId: params.configurationId,
|
|
1127
|
+
apiKeys: params.apiKeys,
|
|
1128
|
+
CredentialScope: params.CredentialScope
|
|
1129
|
+
};
|
|
1130
|
+
}
|
|
980
1131
|
/**
|
|
981
1132
|
* Populate userId and sourceAgentRunId on approved notes from the source
|
|
982
1133
|
* conversation's context. Only fills fields the LLM didn't already set.
|
|
@@ -1082,32 +1233,18 @@ let MemoryManagerAgent = class MemoryManagerAgent extends BaseAgent {
|
|
|
1082
1233
|
// Ask LLM if this candidate adds value given existing similar examples
|
|
1083
1234
|
const dedupePrompt = AIEngine.Instance.Prompts.find(p => p.Name === 'Memory Manager - Deduplicate Example' && p.Category === 'MJ: System');
|
|
1084
1235
|
if (dedupePrompt && similarExamples.length > 0) {
|
|
1085
|
-
const
|
|
1086
|
-
dedupeParams.prompt = dedupePrompt;
|
|
1087
|
-
dedupeParams.data = {
|
|
1088
|
-
candidateExample: candidate,
|
|
1089
|
-
similarExamples: similarExamples.map(s => ({
|
|
1090
|
-
input: s.example.ExampleInput,
|
|
1091
|
-
output: s.example.ExampleOutput,
|
|
1092
|
-
successScore: s.example.SuccessScore,
|
|
1093
|
-
similarity: s.similarity
|
|
1094
|
-
}))
|
|
1095
|
-
};
|
|
1096
|
-
dedupeParams.contextUser = contextUser;
|
|
1097
|
-
dedupeParams.attemptJSONRepair = true;
|
|
1098
|
-
dedupeParams.additionalParameters = { temperature: 0 };
|
|
1099
|
-
const dedupeResult = await runner.ExecutePrompt(dedupeParams);
|
|
1236
|
+
const verdict = await this.decideExampleDedupe(runner, dedupePrompt, candidate, similarExamples, contextUser);
|
|
1100
1237
|
exampleDedupeLlmCallCount++;
|
|
1101
|
-
if (
|
|
1238
|
+
if (verdict.shouldAdd) {
|
|
1102
1239
|
approvedExamples.push(candidate);
|
|
1103
1240
|
if (this._verbose) {
|
|
1104
|
-
LogStatus(`Memory Manager: Approved example - ${
|
|
1241
|
+
LogStatus(`Memory Manager: Approved example - ${verdict.reason}`);
|
|
1105
1242
|
}
|
|
1106
1243
|
}
|
|
1107
1244
|
else {
|
|
1108
1245
|
exampleDedupeRejectedCount++;
|
|
1109
1246
|
if (this._verbose) {
|
|
1110
|
-
LogStatus(`Memory Manager: Skipped duplicate example - ${
|
|
1247
|
+
LogStatus(`Memory Manager: Skipped duplicate example - ${verdict.reason || 'too similar'}`);
|
|
1111
1248
|
}
|
|
1112
1249
|
}
|
|
1113
1250
|
}
|
|
@@ -1881,7 +2018,7 @@ let MemoryManagerAgent = class MemoryManagerAgent extends BaseAgent {
|
|
|
1881
2018
|
const md = this.ProviderToUse;
|
|
1882
2019
|
for (const [noteA, noteB] of candidatePairs) {
|
|
1883
2020
|
result.pairsAnalyzed++;
|
|
1884
|
-
const llmResult = await this.
|
|
2021
|
+
const llmResult = await this.decideContradiction(noteA, noteB, prompt, runner, contextUser);
|
|
1885
2022
|
if (!llmResult)
|
|
1886
2023
|
continue;
|
|
1887
2024
|
result.entityTriplesExtracted += llmResult.triplesExtracted;
|
|
@@ -1919,6 +2056,20 @@ let MemoryManagerAgent = class MemoryManagerAgent extends BaseAgent {
|
|
|
1919
2056
|
}
|
|
1920
2057
|
return pairs;
|
|
1921
2058
|
}
|
|
2059
|
+
/**
|
|
2060
|
+
* Whether two stored notes contradict each other, answered in the run's memory decision mode. The
|
|
2061
|
+
* decision answers only whether they conflict; the winner follows the prompt's own stated rule
|
|
2062
|
+
* (`PickContradictionAuthority`). A failed prompt still skips the pair.
|
|
2063
|
+
*/
|
|
2064
|
+
async decideContradiction(noteA, noteB, prompt, runner, contextUser) {
|
|
2065
|
+
const a = contradictionNoteOf(noteA);
|
|
2066
|
+
const b = contradictionNoteOf(noteB);
|
|
2067
|
+
return this.runMemoryDecisionUse(MEMORY_CONTRADICTION_USE, BuildContradictionDecision(a, b), contextUser, {
|
|
2068
|
+
FromDecision: (run, answeredBy) => ContradictionVerdictFromDecision(run.Answers, a, b, answeredBy),
|
|
2069
|
+
Compare: (answers, existing, answeredBy) => CompareContradictionDecision(answers, existing, answeredBy),
|
|
2070
|
+
RunExisting: () => this.evaluateContradictionPair(noteA, noteB, prompt, runner, contextUser)
|
|
2071
|
+
});
|
|
2072
|
+
}
|
|
1922
2073
|
/** Evaluate a single note pair for contradiction using the LLM prompt. */
|
|
1923
2074
|
async evaluateContradictionPair(noteA, noteB, prompt, runner, contextUser) {
|
|
1924
2075
|
const params = new AIPromptParams();
|
|
@@ -2743,7 +2894,7 @@ let MemoryManagerAgent = class MemoryManagerAgent extends BaseAgent {
|
|
|
2743
2894
|
userId: note.UserID || undefined,
|
|
2744
2895
|
companyId: note.CompanyID || undefined,
|
|
2745
2896
|
};
|
|
2746
|
-
const decision = await this.
|
|
2897
|
+
const decision = await this.decideNoteDedupe(runner, dedupePrompt, candidate, similar, contextUser);
|
|
2747
2898
|
if (!decision.shouldAdd) {
|
|
2748
2899
|
const target = similar[0].note;
|
|
2749
2900
|
note.Status = 'Archived';
|
|
@@ -3073,8 +3224,10 @@ let MemoryManagerAgent = class MemoryManagerAgent extends BaseAgent {
|
|
|
3073
3224
|
if (typeof params.data?.enableDecisionGate === 'boolean') {
|
|
3074
3225
|
this._enableDecisionGate = params.data.enableDecisionGate;
|
|
3075
3226
|
}
|
|
3227
|
+
this._memoryDecisionMode = ResolveDecisionUseMode(params.data?.memoryDecisionMode, MEMORY_DECISION_DEFAULT_MODE);
|
|
3076
3228
|
this._runPromptParams = this.runPromptParams(params);
|
|
3077
3229
|
this._cancellationToken = params.cancellationToken;
|
|
3230
|
+
this._memoryDecisionScope = this.memoryDecisionScope(params);
|
|
3078
3231
|
// Initialize observability state for this run
|
|
3079
3232
|
this._agentRunID = this.AgentRun?.ID || null;
|
|
3080
3233
|
this._stepCounter = 0;
|