@memberjunction/ai-agents 6.2.0-edge.1 → 6.2.0-edge.3
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 +18 -0
- package/dist/AgentDecisionService.d.ts +90 -0
- package/dist/AgentDecisionService.d.ts.map +1 -0
- package/dist/AgentDecisionService.js +159 -0
- package/dist/AgentDecisionService.js.map +1 -0
- package/dist/AgentRunner.d.ts +9 -0
- package/dist/AgentRunner.d.ts.map +1 -1
- package/dist/AgentRunner.js +23 -7
- package/dist/AgentRunner.js.map +1 -1
- package/dist/ConversationCompactionManager.d.ts +7 -1
- package/dist/ConversationCompactionManager.d.ts.map +1 -1
- package/dist/ConversationCompactionManager.js +4 -1
- package/dist/ConversationCompactionManager.js.map +1 -1
- package/dist/KnowledgeAgent.d.ts.map +1 -1
- package/dist/KnowledgeAgent.js +6 -6
- package/dist/KnowledgeAgent.js.map +1 -1
- package/dist/PayloadFeedbackManager.d.ts +116 -14
- package/dist/PayloadFeedbackManager.d.ts.map +1 -1
- package/dist/PayloadFeedbackManager.js +229 -88
- package/dist/PayloadFeedbackManager.js.map +1 -1
- package/dist/agent-context-injector.d.ts +47 -3
- package/dist/agent-context-injector.d.ts.map +1 -1
- package/dist/agent-context-injector.js +77 -10
- package/dist/agent-context-injector.js.map +1 -1
- package/dist/agent-memory-context-builder.d.ts +13 -0
- package/dist/agent-memory-context-builder.d.ts.map +1 -1
- package/dist/agent-memory-context-builder.js +24 -5
- package/dist/agent-memory-context-builder.js.map +1 -1
- package/dist/agent-types/flow-agent-type.d.ts +97 -0
- package/dist/agent-types/flow-agent-type.d.ts.map +1 -1
- package/dist/agent-types/flow-agent-type.js +281 -24
- package/dist/agent-types/flow-agent-type.js.map +1 -1
- package/dist/agent-types/flow-graph-executor.d.ts +12 -1
- package/dist/agent-types/flow-graph-executor.d.ts.map +1 -1
- package/dist/agent-types/flow-graph-executor.js +25 -1
- package/dist/agent-types/flow-graph-executor.js.map +1 -1
- package/dist/agent-types/loop-agent-prompt-params.d.ts +239 -66
- package/dist/agent-types/loop-agent-prompt-params.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-prompt-params.js +47 -2
- package/dist/agent-types/loop-agent-prompt-params.js.map +1 -1
- package/dist/agent-types/loop-agent-response-type.d.ts +12 -1
- package/dist/agent-types/loop-agent-response-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-response-type.js.map +1 -1
- package/dist/agent-types/loop-agent-type.d.ts +26 -0
- package/dist/agent-types/loop-agent-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-type.js +115 -5
- package/dist/agent-types/loop-agent-type.js.map +1 -1
- package/dist/base-agent.d.ts +527 -10
- package/dist/base-agent.d.ts.map +1 -1
- package/dist/base-agent.js +1779 -110
- package/dist/base-agent.js.map +1 -1
- package/dist/catalog-narrowing.d.ts +136 -0
- package/dist/catalog-narrowing.d.ts.map +1 -0
- package/dist/catalog-narrowing.js +212 -0
- package/dist/catalog-narrowing.js.map +1 -0
- package/dist/decision-discovery.d.ts +401 -0
- package/dist/decision-discovery.d.ts.map +1 -0
- package/dist/decision-discovery.js +511 -0
- package/dist/decision-discovery.js.map +1 -0
- package/dist/finish-if-mode-warnings.d.ts +39 -0
- package/dist/finish-if-mode-warnings.d.ts.map +1 -0
- package/dist/finish-if-mode-warnings.js +78 -0
- package/dist/finish-if-mode-warnings.js.map +1 -0
- package/dist/finish-if-state.d.ts +72 -0
- package/dist/finish-if-state.d.ts.map +1 -0
- package/dist/finish-if-state.js +109 -0
- package/dist/finish-if-state.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -1
- package/dist/memory-manager-agent.d.ts +108 -2
- package/dist/memory-manager-agent.d.ts.map +1 -1
- package/dist/memory-manager-agent.js +172 -9
- package/dist/memory-manager-agent.js.map +1 -1
- package/dist/memory-note-gate.d.ts +208 -0
- package/dist/memory-note-gate.d.ts.map +1 -0
- package/dist/memory-note-gate.js +294 -0
- package/dist/memory-note-gate.js.map +1 -0
- package/dist/native-tools/action-tool-builder.d.ts +14 -0
- package/dist/native-tools/action-tool-builder.d.ts.map +1 -1
- package/dist/native-tools/action-tool-builder.js +62 -7
- package/dist/native-tools/action-tool-builder.js.map +1 -1
- package/dist/native-tools/control-tools.d.ts +17 -1
- package/dist/native-tools/control-tools.d.ts.map +1 -1
- package/dist/native-tools/control-tools.js +40 -3
- package/dist/native-tools/control-tools.js.map +1 -1
- package/dist/realtime/bridge-host-params.d.ts +22 -0
- package/dist/realtime/bridge-host-params.d.ts.map +1 -0
- package/dist/realtime/bridge-host-params.js +53 -0
- package/dist/realtime/bridge-host-params.js.map +1 -0
- package/dist/realtime/bridge-realtime-session-factory.d.ts +23 -2
- package/dist/realtime/bridge-realtime-session-factory.d.ts.map +1 -1
- package/dist/realtime/bridge-realtime-session-factory.js +22 -6
- 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 +15 -9
- package/dist/realtime/bridge-room-transcript-sink.js.map +1 -1
- package/dist/realtime/bridge-session-transcript-sink.d.ts +37 -0
- package/dist/realtime/bridge-session-transcript-sink.d.ts.map +1 -0
- package/dist/realtime/bridge-session-transcript-sink.js +58 -0
- package/dist/realtime/bridge-session-transcript-sink.js.map +1 -0
- package/dist/realtime/realtime-client-session-service.d.ts +117 -12
- package/dist/realtime/realtime-client-session-service.d.ts.map +1 -1
- package/dist/realtime/realtime-client-session-service.js +162 -39
- package/dist/realtime/realtime-client-session-service.js.map +1 -1
- package/dist/realtime/realtime-coagent-resolution.d.ts +90 -0
- package/dist/realtime/realtime-coagent-resolution.d.ts.map +1 -0
- package/dist/realtime/realtime-coagent-resolution.js +186 -0
- package/dist/realtime/realtime-coagent-resolution.js.map +1 -0
- package/dist/realtime/realtime-delegation-narrator.d.ts +97 -0
- package/dist/realtime/realtime-delegation-narrator.d.ts.map +1 -0
- package/dist/realtime/realtime-delegation-narrator.js +162 -0
- package/dist/realtime/realtime-delegation-narrator.js.map +1 -0
- package/dist/realtime/realtime-session-runner.d.ts +2 -82
- package/dist/realtime/realtime-session-runner.d.ts.map +1 -1
- package/dist/realtime/realtime-session-runner.js +12 -187
- package/dist/realtime/realtime-session-runner.js.map +1 -1
- package/dist/realtime/realtime-vendor-resolution.d.ts +8 -3
- package/dist/realtime/realtime-vendor-resolution.d.ts.map +1 -1
- package/dist/realtime/realtime-vendor-resolution.js +3 -3
- package/dist/realtime/realtime-vendor-resolution.js.map +1 -1
- package/dist/rubric-evaluation-agent-runner.d.ts +2 -0
- package/dist/rubric-evaluation-agent-runner.d.ts.map +1 -0
- package/dist/rubric-evaluation-agent-runner.js +47 -0
- package/dist/rubric-evaluation-agent-runner.js.map +1 -0
- package/dist/self-check.d.ts +101 -0
- package/dist/self-check.d.ts.map +1 -0
- package/dist/self-check.js +74 -0
- package/dist/self-check.js.map +1 -0
- package/package.json +19 -18
|
@@ -6,13 +6,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
var MemoryManagerAgent_1;
|
|
8
8
|
import { BaseAgent } from './base-agent.js';
|
|
9
|
-
import { RegisterClass, CleanAndParseJSON } from '@memberjunction/global';
|
|
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
12
|
import { AIPromptRunner } from '@memberjunction/ai-prompts';
|
|
13
|
-
import { AIPromptParams } from '@memberjunction/ai-core-plus';
|
|
13
|
+
import { AIPromptParams, DescribeAnsweringModel } from '@memberjunction/ai-core-plus';
|
|
14
14
|
import { AIEngine } from '@memberjunction/aiengine';
|
|
15
15
|
import { UUIDsEqual } from '@memberjunction/global';
|
|
16
|
+
import { AgentDecisionService } from './AgentDecisionService.js';
|
|
17
|
+
import { BuildMemoryNoteQuestions, BuildMemoryNoteState, JudgeMemoryNotes, MemoryNotePromptQuestionCap, ChunkMemoryNotes, GroupMemoryNotesByConversation, MEMORY_NOTE_MIN_PROBABILITY } from './memory-note-gate.js';
|
|
16
18
|
/**
|
|
17
19
|
* Configuration for extraction limits to ensure sparsity
|
|
18
20
|
*/
|
|
@@ -131,7 +133,7 @@ const SOURCE_RUN_SCOPE_FIELDS = ['AgentID', 'CompanyID', 'UserID', 'PrimaryScope
|
|
|
131
133
|
* This agent runs on a schedule (every 15 minutes) and analyzes high-quality conversations
|
|
132
134
|
* and agent runs to extract learnings and example interactions.
|
|
133
135
|
*/
|
|
134
|
-
let MemoryManagerAgent =
|
|
136
|
+
let MemoryManagerAgent = class MemoryManagerAgent extends BaseAgent {
|
|
135
137
|
constructor() {
|
|
136
138
|
super(...arguments);
|
|
137
139
|
/** Verbose logging flag from params.verbose */
|
|
@@ -142,6 +144,21 @@ let MemoryManagerAgent = MemoryManagerAgent_1 = class MemoryManagerAgent extends
|
|
|
142
144
|
this._stepCounter = 0;
|
|
143
145
|
/** Context user for step operations */
|
|
144
146
|
this._contextUser = null;
|
|
147
|
+
/** Flag to enable typed decision gate instead of self-confidence threshold */
|
|
148
|
+
this._enableDecisionGate = false;
|
|
149
|
+
}
|
|
150
|
+
static { MemoryManagerAgent_1 = this; }
|
|
151
|
+
/**
|
|
152
|
+
* Whether the typed decision gate is enabled for filtering extracted memory notes.
|
|
153
|
+
* When false (default), uses the self-reported confidence filter (confidence >= 80).
|
|
154
|
+
* The gate also needs the master switch: the run's agent-type prompt params must set
|
|
155
|
+
* `decisionsEnabled: true` ({@link DecisionsEnabled}), or the confidence filter is used.
|
|
156
|
+
*/
|
|
157
|
+
get EnableDecisionGate() {
|
|
158
|
+
return this._enableDecisionGate;
|
|
159
|
+
}
|
|
160
|
+
set EnableDecisionGate(value) {
|
|
161
|
+
this._enableDecisionGate = value;
|
|
145
162
|
}
|
|
146
163
|
/** Check if a string is a valid UUID format. Filters out LLM-generated placeholders like "user-uuid-here". */
|
|
147
164
|
static isValidUUID(id) {
|
|
@@ -152,6 +169,7 @@ let MemoryManagerAgent = MemoryManagerAgent_1 = class MemoryManagerAgent extends
|
|
|
152
169
|
/**
|
|
153
170
|
* Create an agent run step record for observability.
|
|
154
171
|
* Returns null if agentRunID is not set (defensive check).
|
|
172
|
+
* Protected so a test can stand in for the database.
|
|
155
173
|
*/
|
|
156
174
|
async createRunStep(stepType, stepName, inputData, targetId) {
|
|
157
175
|
if (!this._agentRunID || !this._contextUser) {
|
|
@@ -468,7 +486,7 @@ let MemoryManagerAgent = MemoryManagerAgent_1 = class MemoryManagerAgent extends
|
|
|
468
486
|
companyId: n.CompanyID
|
|
469
487
|
}))
|
|
470
488
|
};
|
|
471
|
-
return this.executeNoteExtraction(promptData, existingNotes, contextUser);
|
|
489
|
+
return this.executeNoteExtraction(promptData, existingNotes, contextUser, true);
|
|
472
490
|
}
|
|
473
491
|
/**
|
|
474
492
|
* Mine corrective ("avoid this") memory from failed/cancelled agent runs. Each failed run
|
|
@@ -508,7 +526,9 @@ let MemoryManagerAgent = MemoryManagerAgent_1 = class MemoryManagerAgent extends
|
|
|
508
526
|
companyId: n.CompanyID
|
|
509
527
|
}))
|
|
510
528
|
};
|
|
511
|
-
|
|
529
|
+
// The decision gate was measured on conversation notes only; a corrective lesson from a failed run
|
|
530
|
+
// is not the durable user fact its question asks about, so these keep the self-reported rule.
|
|
531
|
+
const extracted = await this.executeNoteExtraction(promptData, existingNotes, contextUser, false);
|
|
512
532
|
return this.markCorrectiveNotes(extracted);
|
|
513
533
|
}
|
|
514
534
|
/**
|
|
@@ -546,7 +566,7 @@ let MemoryManagerAgent = MemoryManagerAgent_1 = class MemoryManagerAgent extends
|
|
|
546
566
|
*
|
|
547
567
|
* Each step is its own private helper so the pipeline can be read top-to-bottom.
|
|
548
568
|
*/
|
|
549
|
-
async executeNoteExtraction(promptData, existingNotes, contextUser) {
|
|
569
|
+
async executeNoteExtraction(promptData, existingNotes, contextUser, decisionGateApplies) {
|
|
550
570
|
// Step 1: run the extraction prompt and parse out the raw notes
|
|
551
571
|
const rawNotes = await this.runNoteExtractionPrompt(promptData, existingNotes.length, contextUser);
|
|
552
572
|
if (!rawNotes)
|
|
@@ -559,11 +579,11 @@ let MemoryManagerAgent = MemoryManagerAgent_1 = class MemoryManagerAgent extends
|
|
|
559
579
|
LogStatus(`Memory Manager: Raw note: [${note.type}] "${note.content}" (confidence: ${note.confidence})${note.mergeWithExistingIds?.length ? ` mergeWith: ${note.mergeWithExistingIds.join(', ')}` : ''}`);
|
|
560
580
|
}
|
|
561
581
|
}
|
|
562
|
-
// Step 3: filter by
|
|
563
|
-
const candidateNotes = this.
|
|
582
|
+
// Step 3: filter by decision gate or confidence/content length
|
|
583
|
+
const candidateNotes = await this.filterCandidateNotes(rawNotes, promptData.conversationThreads, contextUser, decisionGateApplies);
|
|
564
584
|
if (candidateNotes.length === 0) {
|
|
565
585
|
if (this._verbose)
|
|
566
|
-
LogStatus('Memory Manager: No candidates passed
|
|
586
|
+
LogStatus('Memory Manager: No candidates passed gating thresholds');
|
|
567
587
|
return [];
|
|
568
588
|
}
|
|
569
589
|
// Step 4: apply per-message and per-conversation sparsity caps
|
|
@@ -689,6 +709,134 @@ let MemoryManagerAgent = MemoryManagerAgent_1 = class MemoryManagerAgent extends
|
|
|
689
709
|
}
|
|
690
710
|
return filtered;
|
|
691
711
|
}
|
|
712
|
+
/**
|
|
713
|
+
* Filters candidate notes using either the typed decision gate (if enabled, with the master switch
|
|
714
|
+
* on, and the notes are ones it was measured on) or the traditional self-reported confidence and
|
|
715
|
+
* length filters. Protected so a test can run the gate the way extraction does.
|
|
716
|
+
*
|
|
717
|
+
* @param decisionGateApplies Whether these notes may be gated: conversation notes only.
|
|
718
|
+
*/
|
|
719
|
+
async filterCandidateNotes(notes, conversationThreads, contextUser, decisionGateApplies) {
|
|
720
|
+
if (!this._enableDecisionGate || !this.DecisionsEnabled(this._runPromptParams) || !decisionGateApplies) {
|
|
721
|
+
return this.filterByConfidenceAndLength(notes);
|
|
722
|
+
}
|
|
723
|
+
return this.filterWithDecisionGate(notes, conversationThreads, contextUser);
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* Evaluates candidate notes through the typed decision gate, one conversation at a time: each note
|
|
727
|
+
* is judged against the conversation it came from, as the gate was measured and calibrated, in
|
|
728
|
+
* batches no larger than the prompt models' declared MaxQuestionsPerCall. A note whose conversation
|
|
729
|
+
* can't be told keeps the self-reported rule. The kept notes keep their original order.
|
|
730
|
+
*/
|
|
731
|
+
async filterWithDecisionGate(notes, conversationThreads, contextUser) {
|
|
732
|
+
const lengthFiltered = notes.filter(n => n.content && n.content.length >= EXTRACTION_CONFIG.minContentLength);
|
|
733
|
+
if (lengthFiltered.length === 0) {
|
|
734
|
+
if (this._verbose)
|
|
735
|
+
LogStatus('Memory Manager: No candidates passed content length check before decision gate');
|
|
736
|
+
return [];
|
|
737
|
+
}
|
|
738
|
+
const cap = MemoryNotePromptQuestionCap(AIEngine.Instance, 'Default Decision');
|
|
739
|
+
const grouping = GroupMemoryNotesByConversation(lengthFiltered, conversationThreads.map(t => ({
|
|
740
|
+
ConversationId: t.conversationId,
|
|
741
|
+
Turns: t.messages.map(m => ({ role: m.role, text: m.message }))
|
|
742
|
+
})));
|
|
743
|
+
const kept = new Set(this.filterByConfidenceAndLength(grouping.Unattributed));
|
|
744
|
+
if (grouping.Unattributed.length > 0) {
|
|
745
|
+
LogStatus(`Memory Manager: ${grouping.Unattributed.length} note(s) name no conversation of this batch, so they keep the confidence filter`);
|
|
746
|
+
}
|
|
747
|
+
for (const conversation of grouping.Batches) {
|
|
748
|
+
for (const batch of ChunkMemoryNotes(conversation.Notes, cap)) {
|
|
749
|
+
const batchPassed = await this.judgeDecisionBatch(batch, conversation.ConversationId, conversation.Excerpt, contextUser, cap);
|
|
750
|
+
batchPassed.forEach(note => kept.add(note));
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
return lengthFiltered.filter(note => kept.has(note));
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* Runs a decision prompt call for a single batch of candidate notes from one conversation, falling
|
|
757
|
+
* back to the confidence filter if the decision call fails. The call's step joins the agent run's
|
|
758
|
+
* steps, and carries the call's prompt run, so the run's cost and token totals count it.
|
|
759
|
+
*/
|
|
760
|
+
async judgeDecisionBatch(batch, conversationId, excerpt, contextUser, modelCap) {
|
|
761
|
+
const questions = BuildMemoryNoteQuestions(batch);
|
|
762
|
+
const state = BuildMemoryNoteState(batch, excerpt);
|
|
763
|
+
const step = await this.createRunStep('Decision', 'Judge Extracted Notes', {
|
|
764
|
+
conversationId,
|
|
765
|
+
noteCount: batch.length,
|
|
766
|
+
modelCap
|
|
767
|
+
});
|
|
768
|
+
if (step) {
|
|
769
|
+
this.AgentRun?.Steps.push(step);
|
|
770
|
+
}
|
|
771
|
+
const decisionService = this._agentDecisionService ?? new AgentDecisionService();
|
|
772
|
+
const result = await decisionService.Ask({
|
|
773
|
+
ContextUser: contextUser,
|
|
774
|
+
PromptName: 'Default Decision',
|
|
775
|
+
State: state,
|
|
776
|
+
Questions: questions,
|
|
777
|
+
AgentID: this.AgentRun?.AgentID ?? undefined,
|
|
778
|
+
CancellationToken: this._cancellationToken
|
|
779
|
+
});
|
|
780
|
+
await this.recordDecisionStep(step, result);
|
|
781
|
+
if (!result.success) {
|
|
782
|
+
LogStatus(`Memory Manager: Decision call failed (${result.errorMessage ?? 'unknown error'}), falling back to confidence filter for batch`);
|
|
783
|
+
return this.filterByConfidenceAndLength(batch);
|
|
784
|
+
}
|
|
785
|
+
const answeredBy = { ModelName: result.modelInfo?.modelName, ResolvedModel: result.DecisionResult?.ResolvedModel };
|
|
786
|
+
return this.evaluateDecisionVerdict(batch, result.Answers, answeredBy);
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* Puts the decision's prompt run on its step, which is how the agent run counts the call's cost
|
|
790
|
+
* and tokens, and marks the step complete.
|
|
791
|
+
*/
|
|
792
|
+
async recordDecisionStep(step, result) {
|
|
793
|
+
if (!step)
|
|
794
|
+
return;
|
|
795
|
+
this.attachDecisionPromptRun(step, result);
|
|
796
|
+
await this.finalizeRunStep(step, result.success, { answers: result.Answers, model: result.modelInfo?.modelName, resolvedModel: result.DecisionResult?.ResolvedModel }, result.promptRun?.ID, result.errorMessage);
|
|
797
|
+
}
|
|
798
|
+
/** The answering models already logged as having no memory-note calibration, so each is logged once per process. */
|
|
799
|
+
static { this._uncalibratedGateModelsLogged = new Set(); }
|
|
800
|
+
/**
|
|
801
|
+
* Logs, once per model, that the decision gate fell back to the confidence filter because the
|
|
802
|
+
* model that answered has no memory-note calibration. That happens on a failover, when a decision
|
|
803
|
+
* model is added or renamed, or when a vendor model moves to another version (Jev's `APIName`).
|
|
804
|
+
*/
|
|
805
|
+
static logUncalibratedGateModel(answeredBy) {
|
|
806
|
+
const described = DescribeAnsweringModel(answeredBy);
|
|
807
|
+
if (MemoryManagerAgent_1._uncalibratedGateModelsLogged.has(described)) {
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
810
|
+
MemoryManagerAgent_1._uncalibratedGateModelsLogged.add(described);
|
|
811
|
+
LogStatus(`Memory Manager: ${described} has no memory-note calibration (MEMORY_NOTE_DECISION_CALIBRATION), so the decision gate falls back to the confidence filter for its batches`);
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* Applies calibrated probabilities to judge which candidate notes to keep. A note the calibrated
|
|
815
|
+
* model gave no usable answer for keeps the self-reported rule, as a failed call's batch does.
|
|
816
|
+
*/
|
|
817
|
+
evaluateDecisionVerdict(batch, answers, answeredBy) {
|
|
818
|
+
const verdict = JudgeMemoryNotes(answers, batch, answeredBy, MEMORY_NOTE_MIN_PROBABILITY);
|
|
819
|
+
// Only a calibrated model replaces the self-reported confidence: one that answered without a
|
|
820
|
+
// calibration (a failover, or a calibrated model at another version) has not been shown to
|
|
821
|
+
// beat it, so the batch falls back to it.
|
|
822
|
+
if (!verdict.Calibrated) {
|
|
823
|
+
MemoryManagerAgent_1.logUncalibratedGateModel(answeredBy);
|
|
824
|
+
return this.filterByConfidenceAndLength(batch);
|
|
825
|
+
}
|
|
826
|
+
if (this._verbose) {
|
|
827
|
+
LogStatus(`Memory Manager: Decision gate evaluated ${batch.length} notes (calibrated: ${verdict.Calibrated}): kept ${verdict.KeptNotes.length}`);
|
|
828
|
+
for (const judged of verdict.JudgedNotes) {
|
|
829
|
+
LogStatus(`Memory Manager: Note [${judged.Note.type}] "${judged.Note.content.slice(0, 50)}..." -> kept: ${judged.Kept} (prob: ${judged.CalibratedProbability ?? judged.RawProbability ?? 'none'}), reason: ${judged.Reason}`);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
const unanswered = verdict.JudgedNotes.filter(j => j.CalibratedProbability === undefined).map(j => j.Note);
|
|
833
|
+
if (unanswered.length === 0) {
|
|
834
|
+
return verdict.KeptNotes;
|
|
835
|
+
}
|
|
836
|
+
LogStatus(`Memory Manager: ${DescribeAnsweringModel(answeredBy)} gave no usable answer for ${unanswered.length} of ${batch.length} note(s), which keep the confidence filter`);
|
|
837
|
+
const kept = new Set([...verdict.KeptNotes, ...this.filterByConfidenceAndLength(unanswered)]);
|
|
838
|
+
return batch.filter(note => kept.has(note));
|
|
839
|
+
}
|
|
692
840
|
/**
|
|
693
841
|
* Enforce per-message and per-conversation note caps from EXTRACTION_CONFIG.
|
|
694
842
|
* Drops any candidates that would exceed either cap.
|
|
@@ -2886,6 +3034,16 @@ let MemoryManagerAgent = MemoryManagerAgent_1 = class MemoryManagerAgent extends
|
|
|
2886
3034
|
});
|
|
2887
3035
|
return created;
|
|
2888
3036
|
}
|
|
3037
|
+
/**
|
|
3038
|
+
* The run's merged agent-type prompt params: the agent type's defaults, then the Memory Manager
|
|
3039
|
+
* agent's own `AgentTypePromptParams`, then the run's `data.__agentTypePromptParams`. This agent
|
|
3040
|
+
* renders no Loop prompt, so it merges them itself, once per run.
|
|
3041
|
+
*/
|
|
3042
|
+
runPromptParams(params) {
|
|
3043
|
+
const agentType = AIEngine.Instance.AgentTypes.find(at => UUIDsEqual(at.ID, params.agent.TypeID));
|
|
3044
|
+
const override = params.data?.__agentTypePromptParams;
|
|
3045
|
+
return this.buildAgentTypePromptParams(agentType, params.agent, IsPlainObject(override) ? override : undefined);
|
|
3046
|
+
}
|
|
2889
3047
|
/**
|
|
2890
3048
|
* Main execution method called by scheduler
|
|
2891
3049
|
*/
|
|
@@ -2893,6 +3051,11 @@ let MemoryManagerAgent = MemoryManagerAgent_1 = class MemoryManagerAgent extends
|
|
|
2893
3051
|
try {
|
|
2894
3052
|
// Use verbose flag from agent execution params or data payload (UI passes it via data)
|
|
2895
3053
|
this._verbose = params.verbose || params.data?.verbose || false;
|
|
3054
|
+
if (typeof params.data?.enableDecisionGate === 'boolean') {
|
|
3055
|
+
this._enableDecisionGate = params.data.enableDecisionGate;
|
|
3056
|
+
}
|
|
3057
|
+
this._runPromptParams = this.runPromptParams(params);
|
|
3058
|
+
this._cancellationToken = params.cancellationToken;
|
|
2896
3059
|
// Initialize observability state for this run
|
|
2897
3060
|
this._agentRunID = this.AgentRun?.ID || null;
|
|
2898
3061
|
this._stepCounter = 0;
|