@memberjunction/ai-agents 3.3.0 → 4.0.0
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/AgentDataPreloader.d.ts +117 -1
- package/dist/AgentDataPreloader.d.ts.map +1 -1
- package/dist/AgentDataPreloader.js +156 -58
- package/dist/AgentDataPreloader.js.map +1 -1
- package/dist/AgentRunner.d.ts +212 -0
- package/dist/AgentRunner.d.ts.map +1 -1
- package/dist/AgentRunner.js +354 -103
- package/dist/AgentRunner.js.map +1 -1
- package/dist/PayloadChangeAnalyzer.d.ts +68 -0
- package/dist/PayloadChangeAnalyzer.d.ts.map +1 -1
- package/dist/PayloadChangeAnalyzer.js +68 -32
- package/dist/PayloadChangeAnalyzer.js.map +1 -1
- package/dist/PayloadFeedbackManager.d.ts +57 -1
- package/dist/PayloadFeedbackManager.d.ts.map +1 -1
- package/dist/PayloadFeedbackManager.js +66 -21
- package/dist/PayloadFeedbackManager.js.map +1 -1
- package/dist/PayloadManager.d.ts +286 -1
- package/dist/PayloadManager.d.ts.map +1 -1
- package/dist/PayloadManager.js +423 -50
- package/dist/PayloadManager.js.map +1 -1
- package/dist/__tests__/action-changes.test.d.ts +13 -0
- package/dist/__tests__/action-changes.test.d.ts.map +1 -1
- package/dist/__tests__/action-changes.test.js +57 -4
- package/dist/__tests__/action-changes.test.js.map +1 -1
- package/dist/__tests__/agent-memory-features.test.d.ts +52 -0
- package/dist/__tests__/agent-memory-features.test.d.ts.map +1 -1
- package/dist/__tests__/agent-memory-features.test.js +96 -13
- package/dist/__tests__/agent-memory-features.test.js.map +1 -1
- package/dist/__tests__/agent-type-prompt-params.test.d.ts +12 -0
- package/dist/__tests__/agent-type-prompt-params.test.d.ts.map +1 -1
- package/dist/__tests__/agent-type-prompt-params.test.js +112 -20
- package/dist/__tests__/agent-type-prompt-params.test.js.map +1 -1
- package/dist/__tests__/chat-handling-option.test.d.ts +26 -0
- package/dist/__tests__/chat-handling-option.test.d.ts.map +1 -1
- package/dist/__tests__/chat-handling-option.test.js +41 -2
- package/dist/__tests__/chat-handling-option.test.js.map +1 -1
- package/dist/agent-context-injector.d.ts +114 -0
- package/dist/agent-context-injector.d.ts.map +1 -1
- package/dist/agent-context-injector.js +138 -19
- package/dist/agent-context-injector.js.map +1 -1
- package/dist/agent-types/base-agent-type.d.ts +354 -0
- package/dist/agent-types/base-agent-type.d.ts.map +1 -1
- package/dist/agent-types/base-agent-type.js +288 -17
- package/dist/agent-types/base-agent-type.js.map +1 -1
- package/dist/agent-types/flow-agent-type.d.ts +328 -2
- package/dist/agent-types/flow-agent-type.d.ts.map +1 -1
- package/dist/agent-types/flow-agent-type.js +503 -63
- package/dist/agent-types/flow-agent-type.js.map +1 -1
- package/dist/agent-types/index.d.ts +14 -3
- package/dist/agent-types/index.d.ts.map +1 -1
- package/dist/agent-types/index.js +14 -23
- package/dist/agent-types/index.js.map +1 -1
- package/dist/agent-types/loop-agent-prompt-params.d.ts +190 -0
- package/dist/agent-types/loop-agent-prompt-params.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-prompt-params.js +23 -6
- package/dist/agent-types/loop-agent-prompt-params.js.map +1 -1
- package/dist/agent-types/loop-agent-response-type.d.ts +62 -0
- package/dist/agent-types/loop-agent-response-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-response-type.js +3 -2
- package/dist/agent-types/loop-agent-response-type.js.map +1 -1
- package/dist/agent-types/loop-agent-type.d.ts +139 -2
- package/dist/agent-types/loop-agent-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-type.js +207 -35
- package/dist/agent-types/loop-agent-type.js.map +1 -1
- package/dist/base-agent.d.ts +1344 -1
- package/dist/base-agent.d.ts.map +1 -1
- package/dist/base-agent.js +2282 -211
- package/dist/base-agent.js.map +1 -1
- package/dist/index.d.ts +24 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -35
- package/dist/index.js.map +1 -1
- package/dist/memory-cleanup-agent.d.ts +53 -1
- package/dist/memory-cleanup-agent.d.ts.map +1 -1
- package/dist/memory-cleanup-agent.js +89 -21
- package/dist/memory-cleanup-agent.js.map +1 -1
- package/dist/memory-manager-agent.d.ts +61 -1
- package/dist/memory-manager-agent.d.ts.map +1 -1
- package/dist/memory-manager-agent.js +260 -116
- package/dist/memory-manager-agent.js.map +1 -1
- package/dist/services/AgentEmbeddingService.d.ts +16 -0
- package/dist/services/AgentEmbeddingService.d.ts.map +1 -0
- package/dist/services/AgentEmbeddingService.js +158 -0
- package/dist/services/AgentEmbeddingService.js.map +1 -0
- package/dist/types/AgentMatchResult.d.ts +18 -0
- package/dist/types/AgentMatchResult.d.ts.map +1 -0
- package/dist/types/AgentMatchResult.js +3 -0
- package/dist/types/AgentMatchResult.js.map +1 -0
- package/dist/types/payload-operations.d.ts +51 -0
- package/dist/types/payload-operations.d.ts.map +1 -1
- package/dist/types/payload-operations.js +54 -15
- package/dist/types/payload-operations.js.map +1 -1
- package/dist/utils/ConversationMessageResolver.d.ts +79 -1
- package/dist/utils/ConversationMessageResolver.d.ts.map +1 -1
- package/dist/utils/ConversationMessageResolver.js +99 -9
- package/dist/utils/ConversationMessageResolver.js.map +1 -1
- package/package.json +20 -19
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export * from './
|
|
12
|
-
export * from './agent-
|
|
13
|
-
export * from './
|
|
14
|
-
export
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Main export module for the MemberJunction AI Agent framework.
|
|
3
|
+
*
|
|
4
|
+
* This module exports all public APIs for the AI Agent system, including
|
|
5
|
+
* base classes, type definitions, and utility functions.
|
|
6
|
+
*
|
|
7
|
+
* @module @memberjunction/ai-agents
|
|
8
|
+
* @author MemberJunction.com
|
|
9
|
+
* @since 2.49.0
|
|
10
|
+
*/
|
|
11
|
+
export * from './agent-types/base-agent-type.js';
|
|
12
|
+
export * from './agent-types/loop-agent-response-type.js';
|
|
13
|
+
export * from './agent-types/loop-agent-prompt-params.js';
|
|
14
|
+
export * from './base-agent.js';
|
|
15
|
+
export * from './agent-types/index.js';
|
|
16
|
+
export * from './AgentRunner.js';
|
|
17
|
+
export * from './PayloadManager.js';
|
|
18
|
+
export * from './PayloadChangeAnalyzer.js';
|
|
19
|
+
export * from './PayloadFeedbackManager.js';
|
|
20
|
+
export * from './types/payload-operations.js';
|
|
21
|
+
export * from './AgentDataPreloader.js';
|
|
22
|
+
export * from './agent-context-injector.js';
|
|
23
|
+
export * from './memory-manager-agent.js';
|
|
24
|
+
export { RerankerService, RerankerConfiguration, parseRerankerConfiguration, RerankServiceResult, RerankObservabilityOptions, LLMReranker } from '@memberjunction/ai-reranker';
|
|
15
25
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wCAAwC,CAAC;AACvD,cAAc,wCAAwC,CAAC;AACvD,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AAGvC,OAAO,EACH,eAAe,EACf,qBAAqB,EACrB,0BAA0B,EAC1B,mBAAmB,EACnB,0BAA0B,EAC1B,WAAW,EACd,MAAM,6BAA6B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,36 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
__exportStar(require("./PayloadFeedbackManager"), exports);
|
|
27
|
-
__exportStar(require("./types/payload-operations"), exports);
|
|
28
|
-
__exportStar(require("./AgentDataPreloader"), exports);
|
|
29
|
-
__exportStar(require("./agent-context-injector"), exports);
|
|
30
|
-
__exportStar(require("./memory-manager-agent"), exports);
|
|
31
|
-
var ai_reranker_1 = require("@memberjunction/ai-reranker");
|
|
32
|
-
Object.defineProperty(exports, "RerankerService", { enumerable: true, get: function () { return ai_reranker_1.RerankerService; } });
|
|
33
|
-
Object.defineProperty(exports, "parseRerankerConfiguration", { enumerable: true, get: function () { return ai_reranker_1.parseRerankerConfiguration; } });
|
|
34
|
-
Object.defineProperty(exports, "LLMReranker", { enumerable: true, get: function () { return ai_reranker_1.LLMReranker; } });
|
|
35
|
-
Object.defineProperty(exports, "LoadLLMReranker", { enumerable: true, get: function () { return ai_reranker_1.LoadLLMReranker; } });
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Main export module for the MemberJunction AI Agent framework.
|
|
3
|
+
*
|
|
4
|
+
* This module exports all public APIs for the AI Agent system, including
|
|
5
|
+
* base classes, type definitions, and utility functions.
|
|
6
|
+
*
|
|
7
|
+
* @module @memberjunction/ai-agents
|
|
8
|
+
* @author MemberJunction.com
|
|
9
|
+
* @since 2.49.0
|
|
10
|
+
*/
|
|
11
|
+
export * from './agent-types/base-agent-type.js';
|
|
12
|
+
export * from './agent-types/loop-agent-response-type.js';
|
|
13
|
+
export * from './agent-types/loop-agent-prompt-params.js';
|
|
14
|
+
export * from './base-agent.js';
|
|
15
|
+
export * from './agent-types/index.js';
|
|
16
|
+
export * from './AgentRunner.js';
|
|
17
|
+
export * from './PayloadManager.js';
|
|
18
|
+
export * from './PayloadChangeAnalyzer.js';
|
|
19
|
+
export * from './PayloadFeedbackManager.js';
|
|
20
|
+
export * from './types/payload-operations.js';
|
|
21
|
+
export * from './AgentDataPreloader.js';
|
|
22
|
+
export * from './agent-context-injector.js';
|
|
23
|
+
export * from './memory-manager-agent.js';
|
|
24
|
+
// Re-export from ai-reranker for backward compatibility
|
|
25
|
+
export { RerankerService, parseRerankerConfiguration, LLMReranker } from '@memberjunction/ai-reranker';
|
|
36
26
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wCAAwC,CAAC;AACvD,cAAc,wCAAwC,CAAC;AACvD,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AAEvC,wDAAwD;AACxD,OAAO,EACH,eAAe,EAEf,0BAA0B,EAG1B,WAAW,EACd,MAAM,6BAA6B,CAAC"}
|
|
@@ -1,25 +1,77 @@
|
|
|
1
|
-
import { BaseAgent } from './base-agent';
|
|
1
|
+
import { BaseAgent } from './base-agent.js';
|
|
2
2
|
import { ExecuteAgentParams, AgentConfiguration, BaseAgentNextStep } from '@memberjunction/ai-core-plus';
|
|
3
|
+
/**
|
|
4
|
+
* Memory Cleanup Agent - archives stale notes and examples based on retention policies.
|
|
5
|
+
*
|
|
6
|
+
* This agent runs on a daily schedule and:
|
|
7
|
+
* 1. Archives notes not accessed within NoteRetentionDays (per agent config, default 90)
|
|
8
|
+
* 2. Archives examples with SuccessScore < 50 after ExampleRetentionDays (default 180)
|
|
9
|
+
* 3. Archives any items past their ExpiresAt timestamp
|
|
10
|
+
*
|
|
11
|
+
* Only processes auto-generated items (IsAutoGenerated = true) to preserve manual entries.
|
|
12
|
+
*/
|
|
3
13
|
export declare class MemoryCleanupAgent extends BaseAgent {
|
|
4
14
|
private readonly DEFAULT_NOTE_RETENTION_DAYS;
|
|
5
15
|
private readonly DEFAULT_EXAMPLE_RETENTION_DAYS;
|
|
6
16
|
private readonly LOW_SUCCESS_SCORE_THRESHOLD;
|
|
17
|
+
/**
|
|
18
|
+
* Main entry point for the cleanup agent
|
|
19
|
+
*/
|
|
7
20
|
protected executeAgentInternal<P = any>(params: ExecuteAgentParams, config: AgentConfiguration): Promise<{
|
|
8
21
|
finalStep: BaseAgentNextStep<P>;
|
|
9
22
|
stepCount: number;
|
|
10
23
|
}>;
|
|
24
|
+
/**
|
|
25
|
+
* Archive items that have passed their ExpiresAt timestamp
|
|
26
|
+
*/
|
|
11
27
|
private archiveExpiredItems;
|
|
28
|
+
/**
|
|
29
|
+
* Archive items based on per-agent retention policies
|
|
30
|
+
*/
|
|
12
31
|
private archiveStaleItems;
|
|
32
|
+
/**
|
|
33
|
+
* Query for notes past their ExpiresAt timestamp
|
|
34
|
+
*/
|
|
13
35
|
private queryExpiredNotes;
|
|
36
|
+
/**
|
|
37
|
+
* Query for examples past their ExpiresAt timestamp
|
|
38
|
+
*/
|
|
14
39
|
private queryExpiredExamples;
|
|
40
|
+
/**
|
|
41
|
+
* Query for stale auto-generated notes (not accessed within retention period)
|
|
42
|
+
*/
|
|
15
43
|
private queryStaleNotes;
|
|
44
|
+
/**
|
|
45
|
+
* Query for stale auto-generated examples with low success scores
|
|
46
|
+
*/
|
|
16
47
|
private queryStaleExamples;
|
|
48
|
+
/**
|
|
49
|
+
* Archive a note by setting its status to 'Archived'
|
|
50
|
+
*/
|
|
17
51
|
private archiveNote;
|
|
52
|
+
/**
|
|
53
|
+
* Archive an example by setting its status to 'Archived'
|
|
54
|
+
*/
|
|
18
55
|
private archiveExample;
|
|
56
|
+
/**
|
|
57
|
+
* Get note retention days for an agent (uses agent config or default)
|
|
58
|
+
*/
|
|
19
59
|
private getNoteRetentionDays;
|
|
60
|
+
/**
|
|
61
|
+
* Get example retention days for an agent (uses agent config or default)
|
|
62
|
+
*/
|
|
20
63
|
private getExampleRetentionDays;
|
|
64
|
+
/**
|
|
65
|
+
* Check if auto-archive is enabled for an agent
|
|
66
|
+
*/
|
|
21
67
|
private getAutoArchiveEnabled;
|
|
68
|
+
/**
|
|
69
|
+
* Calculate cutoff date (now - retentionDays)
|
|
70
|
+
*/
|
|
22
71
|
private getCutoffDate;
|
|
72
|
+
/**
|
|
73
|
+
* Build summary message for cleanup results
|
|
74
|
+
*/
|
|
23
75
|
private buildSummary;
|
|
24
76
|
}
|
|
25
77
|
//# sourceMappingURL=memory-cleanup-agent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-cleanup-agent.d.ts","sourceRoot":"","sources":["../src/memory-cleanup-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EAAE,kBAAkB,EAAyB,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"memory-cleanup-agent.d.ts","sourceRoot":"","sources":["../src/memory-cleanup-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EAAE,kBAAkB,EAAyB,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAchI;;;;;;;;;GASG;AACH,qBAAa,kBAAmB,SAAQ,SAAS;IAC7C,OAAO,CAAC,QAAQ,CAAC,2BAA2B,CAAM;IAClD,OAAO,CAAC,QAAQ,CAAC,8BAA8B,CAAO;IACtD,OAAO,CAAC,QAAQ,CAAC,2BAA2B,CAAM;IAElD;;OAEG;cACsB,oBAAoB,CAAC,CAAC,GAAG,GAAG,EACjD,MAAM,EAAE,kBAAkB,EAC1B,MAAM,EAAE,kBAAkB,GAC3B,OAAO,CAAC;QAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAC,CAAC;IAyChE;;OAEG;YACW,mBAAmB;IA0BjC;;OAEG;YACW,iBAAiB;IAmC/B;;OAEG;YACW,iBAAiB;IAY/B;;OAEG;YACW,oBAAoB;IAYlC;;OAEG;YACW,eAAe;IA+B7B;;OAEG;YACW,kBAAkB;IAiChC;;OAEG;YACW,WAAW;IAoBzB;;OAEG;YACW,cAAc;IAoB5B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAU5B;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAS/B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAO7B;;OAEG;IACH,OAAO,CAAC,aAAa;IAMrB;;OAEG;IACH,OAAO,CAAC,YAAY;CA0BvB"}
|
|
@@ -1,18 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { BaseAgent } from './base-agent.js';
|
|
2
|
+
import { RunView, LogError, LogStatus } from '@memberjunction/core';
|
|
3
|
+
import { AIEngine } from '@memberjunction/aiengine';
|
|
4
|
+
/**
|
|
5
|
+
* Memory Cleanup Agent - archives stale notes and examples based on retention policies.
|
|
6
|
+
*
|
|
7
|
+
* This agent runs on a daily schedule and:
|
|
8
|
+
* 1. Archives notes not accessed within NoteRetentionDays (per agent config, default 90)
|
|
9
|
+
* 2. Archives examples with SuccessScore < 50 after ExampleRetentionDays (default 180)
|
|
10
|
+
* 3. Archives any items past their ExpiresAt timestamp
|
|
11
|
+
*
|
|
12
|
+
* Only processes auto-generated items (IsAutoGenerated = true) to preserve manual entries.
|
|
13
|
+
*/
|
|
14
|
+
export class MemoryCleanupAgent extends BaseAgent {
|
|
8
15
|
constructor() {
|
|
9
16
|
super(...arguments);
|
|
10
17
|
this.DEFAULT_NOTE_RETENTION_DAYS = 90;
|
|
11
18
|
this.DEFAULT_EXAMPLE_RETENTION_DAYS = 180;
|
|
12
19
|
this.LOW_SUCCESS_SCORE_THRESHOLD = 50;
|
|
13
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Main entry point for the cleanup agent
|
|
23
|
+
*/
|
|
14
24
|
async executeAgentInternal(params, config) {
|
|
15
|
-
|
|
25
|
+
LogStatus('MemoryCleanupAgent: Starting cleanup process');
|
|
16
26
|
const contextUser = params.contextUser;
|
|
17
27
|
const result = {
|
|
18
28
|
notesArchived: 0,
|
|
@@ -22,10 +32,12 @@ class MemoryCleanupAgent extends base_agent_1.BaseAgent {
|
|
|
22
32
|
errors: []
|
|
23
33
|
};
|
|
24
34
|
try {
|
|
35
|
+
// Process expired items first (these have explicit ExpiresAt timestamps)
|
|
25
36
|
await this.archiveExpiredItems(result, contextUser);
|
|
37
|
+
// Then process stale items based on retention policies
|
|
26
38
|
await this.archiveStaleItems(result, contextUser);
|
|
27
39
|
const summary = this.buildSummary(result);
|
|
28
|
-
|
|
40
|
+
LogStatus(`MemoryCleanupAgent: Cleanup completed - ${summary}`);
|
|
29
41
|
const finalStep = {
|
|
30
42
|
terminate: true,
|
|
31
43
|
step: 'Success',
|
|
@@ -35,7 +47,7 @@ class MemoryCleanupAgent extends base_agent_1.BaseAgent {
|
|
|
35
47
|
}
|
|
36
48
|
catch (error) {
|
|
37
49
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
38
|
-
|
|
50
|
+
LogError('MemoryCleanupAgent: Cleanup failed', undefined, error);
|
|
39
51
|
const finalStep = {
|
|
40
52
|
terminate: true,
|
|
41
53
|
step: 'Failed',
|
|
@@ -44,8 +56,12 @@ class MemoryCleanupAgent extends base_agent_1.BaseAgent {
|
|
|
44
56
|
return { finalStep, stepCount: 1 };
|
|
45
57
|
}
|
|
46
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Archive items that have passed their ExpiresAt timestamp
|
|
61
|
+
*/
|
|
47
62
|
async archiveExpiredItems(result, contextUser) {
|
|
48
63
|
const now = new Date().toISOString();
|
|
64
|
+
// Archive expired notes
|
|
49
65
|
const expiredNotes = await this.queryExpiredNotes(now, contextUser);
|
|
50
66
|
for (const note of expiredNotes) {
|
|
51
67
|
const archived = await this.archiveNote(note, 'Expired', contextUser);
|
|
@@ -56,6 +72,7 @@ class MemoryCleanupAgent extends base_agent_1.BaseAgent {
|
|
|
56
72
|
result.errors.push(`Failed to archive expired note ${note.ID}`);
|
|
57
73
|
}
|
|
58
74
|
}
|
|
75
|
+
// Archive expired examples
|
|
59
76
|
const expiredExamples = await this.queryExpiredExamples(now, contextUser);
|
|
60
77
|
for (const example of expiredExamples) {
|
|
61
78
|
const archived = await this.archiveExample(example, 'Expired', contextUser);
|
|
@@ -67,12 +84,17 @@ class MemoryCleanupAgent extends base_agent_1.BaseAgent {
|
|
|
67
84
|
}
|
|
68
85
|
}
|
|
69
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Archive items based on per-agent retention policies
|
|
89
|
+
*/
|
|
70
90
|
async archiveStaleItems(result, contextUser) {
|
|
71
|
-
|
|
91
|
+
// Get all agents with auto-archive enabled
|
|
92
|
+
const agents = AIEngine.Instance.Agents.filter(a => a.Status === 'Active' &&
|
|
72
93
|
this.getAutoArchiveEnabled(a));
|
|
73
94
|
for (const agent of agents) {
|
|
74
95
|
const noteRetentionDays = this.getNoteRetentionDays(agent);
|
|
75
96
|
const exampleRetentionDays = this.getExampleRetentionDays(agent);
|
|
97
|
+
// Archive stale notes for this agent
|
|
76
98
|
const staleNotes = await this.queryStaleNotes(agent.ID, noteRetentionDays, contextUser);
|
|
77
99
|
for (const note of staleNotes) {
|
|
78
100
|
const archived = await this.archiveNote(note, `Stale (${noteRetentionDays} days)`, contextUser);
|
|
@@ -83,6 +105,7 @@ class MemoryCleanupAgent extends base_agent_1.BaseAgent {
|
|
|
83
105
|
result.errors.push(`Failed to archive stale note ${note.ID}`);
|
|
84
106
|
}
|
|
85
107
|
}
|
|
108
|
+
// Archive stale low-scoring examples for this agent
|
|
86
109
|
const staleExamples = await this.queryStaleExamples(agent.ID, exampleRetentionDays, contextUser);
|
|
87
110
|
for (const example of staleExamples) {
|
|
88
111
|
const archived = await this.archiveExample(example, `Stale low-score (${exampleRetentionDays} days)`, contextUser);
|
|
@@ -95,8 +118,11 @@ class MemoryCleanupAgent extends base_agent_1.BaseAgent {
|
|
|
95
118
|
}
|
|
96
119
|
}
|
|
97
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Query for notes past their ExpiresAt timestamp
|
|
123
|
+
*/
|
|
98
124
|
async queryExpiredNotes(now, contextUser) {
|
|
99
|
-
const rv = new
|
|
125
|
+
const rv = new RunView();
|
|
100
126
|
const result = await rv.RunView({
|
|
101
127
|
EntityName: 'AI Agent Notes',
|
|
102
128
|
ExtraFilter: `Status = 'Active' AND ExpiresAt IS NOT NULL AND ExpiresAt < '${now}'`,
|
|
@@ -105,8 +131,11 @@ class MemoryCleanupAgent extends base_agent_1.BaseAgent {
|
|
|
105
131
|
}, contextUser);
|
|
106
132
|
return result.Success ? result.Results : [];
|
|
107
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Query for examples past their ExpiresAt timestamp
|
|
136
|
+
*/
|
|
108
137
|
async queryExpiredExamples(now, contextUser) {
|
|
109
|
-
const rv = new
|
|
138
|
+
const rv = new RunView();
|
|
110
139
|
const result = await rv.RunView({
|
|
111
140
|
EntityName: 'AI Agent Examples',
|
|
112
141
|
ExtraFilter: `Status = 'Active' AND ExpiresAt IS NOT NULL AND ExpiresAt < '${now}'`,
|
|
@@ -115,9 +144,17 @@ class MemoryCleanupAgent extends base_agent_1.BaseAgent {
|
|
|
115
144
|
}, contextUser);
|
|
116
145
|
return result.Success ? result.Results : [];
|
|
117
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Query for stale auto-generated notes (not accessed within retention period)
|
|
149
|
+
*/
|
|
118
150
|
async queryStaleNotes(agentId, retentionDays, contextUser) {
|
|
119
151
|
const cutoffDate = this.getCutoffDate(retentionDays);
|
|
120
|
-
const rv = new
|
|
152
|
+
const rv = new RunView();
|
|
153
|
+
// Query notes that are:
|
|
154
|
+
// - For this agent
|
|
155
|
+
// - Auto-generated (don't archive manual notes)
|
|
156
|
+
// - Active status
|
|
157
|
+
// - Last accessed before cutoff (or never accessed and created before cutoff)
|
|
121
158
|
const result = await rv.RunView({
|
|
122
159
|
EntityName: 'AI Agent Notes',
|
|
123
160
|
ExtraFilter: `
|
|
@@ -134,9 +171,18 @@ class MemoryCleanupAgent extends base_agent_1.BaseAgent {
|
|
|
134
171
|
}, contextUser);
|
|
135
172
|
return result.Success ? result.Results : [];
|
|
136
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Query for stale auto-generated examples with low success scores
|
|
176
|
+
*/
|
|
137
177
|
async queryStaleExamples(agentId, retentionDays, contextUser) {
|
|
138
178
|
const cutoffDate = this.getCutoffDate(retentionDays);
|
|
139
|
-
const rv = new
|
|
179
|
+
const rv = new RunView();
|
|
180
|
+
// Query examples that are:
|
|
181
|
+
// - For this agent
|
|
182
|
+
// - Auto-generated
|
|
183
|
+
// - Active status
|
|
184
|
+
// - Low success score (< 50)
|
|
185
|
+
// - Last accessed before cutoff (or never accessed and created before cutoff)
|
|
140
186
|
const result = await rv.RunView({
|
|
141
187
|
EntityName: 'AI Agent Examples',
|
|
142
188
|
ExtraFilter: `
|
|
@@ -154,37 +200,47 @@ class MemoryCleanupAgent extends base_agent_1.BaseAgent {
|
|
|
154
200
|
}, contextUser);
|
|
155
201
|
return result.Success ? result.Results : [];
|
|
156
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Archive a note by setting its status to 'Archived'
|
|
205
|
+
*/
|
|
157
206
|
async archiveNote(note, reason, contextUser) {
|
|
158
207
|
try {
|
|
159
|
-
note.Status = 'Archived';
|
|
208
|
+
note.Status = 'Archived'; // TypeScript doesn't know about new status yet
|
|
160
209
|
note.Comments = `${note.Comments ? note.Comments + '\n' : ''}[Archived by Memory Cleanup Agent: ${reason} on ${new Date().toISOString()}]`;
|
|
161
210
|
const saved = await note.Save();
|
|
162
211
|
if (saved) {
|
|
163
|
-
|
|
212
|
+
LogStatus(`MemoryCleanupAgent: Archived note ${note.ID} - ${reason}`);
|
|
164
213
|
}
|
|
165
214
|
return saved;
|
|
166
215
|
}
|
|
167
216
|
catch (error) {
|
|
168
|
-
|
|
217
|
+
LogError(`MemoryCleanupAgent: Failed to archive note ${note.ID}`, undefined, error);
|
|
169
218
|
return false;
|
|
170
219
|
}
|
|
171
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Archive an example by setting its status to 'Archived'
|
|
223
|
+
*/
|
|
172
224
|
async archiveExample(example, reason, contextUser) {
|
|
173
225
|
try {
|
|
174
226
|
example.Status = 'Archived';
|
|
175
227
|
example.Comments = `${example.Comments ? example.Comments + '\n' : ''}[Archived by Memory Cleanup Agent: ${reason} on ${new Date().toISOString()}]`;
|
|
176
228
|
const saved = await example.Save();
|
|
177
229
|
if (saved) {
|
|
178
|
-
|
|
230
|
+
LogStatus(`MemoryCleanupAgent: Archived example ${example.ID} - ${reason}`);
|
|
179
231
|
}
|
|
180
232
|
return saved;
|
|
181
233
|
}
|
|
182
234
|
catch (error) {
|
|
183
|
-
|
|
235
|
+
LogError(`MemoryCleanupAgent: Failed to archive example ${example.ID}`, undefined, error);
|
|
184
236
|
return false;
|
|
185
237
|
}
|
|
186
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* Get note retention days for an agent (uses agent config or default)
|
|
241
|
+
*/
|
|
187
242
|
getNoteRetentionDays(agent) {
|
|
243
|
+
// Check if agent has NoteRetentionDays property using GetAll() for plain object access
|
|
188
244
|
const agentData = agent.GetAll();
|
|
189
245
|
const retention = agentData['NoteRetentionDays'];
|
|
190
246
|
if (typeof retention === 'number' && retention > 0) {
|
|
@@ -192,6 +248,9 @@ class MemoryCleanupAgent extends base_agent_1.BaseAgent {
|
|
|
192
248
|
}
|
|
193
249
|
return this.DEFAULT_NOTE_RETENTION_DAYS;
|
|
194
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Get example retention days for an agent (uses agent config or default)
|
|
253
|
+
*/
|
|
195
254
|
getExampleRetentionDays(agent) {
|
|
196
255
|
const agentData = agent.GetAll();
|
|
197
256
|
const retention = agentData['ExampleRetentionDays'];
|
|
@@ -200,16 +259,26 @@ class MemoryCleanupAgent extends base_agent_1.BaseAgent {
|
|
|
200
259
|
}
|
|
201
260
|
return this.DEFAULT_EXAMPLE_RETENTION_DAYS;
|
|
202
261
|
}
|
|
262
|
+
/**
|
|
263
|
+
* Check if auto-archive is enabled for an agent
|
|
264
|
+
*/
|
|
203
265
|
getAutoArchiveEnabled(agent) {
|
|
204
266
|
const agentData = agent.GetAll();
|
|
205
267
|
const enabled = agentData['AutoArchiveEnabled'];
|
|
268
|
+
// Default to true if not explicitly set to false
|
|
206
269
|
return enabled !== false;
|
|
207
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Calculate cutoff date (now - retentionDays)
|
|
273
|
+
*/
|
|
208
274
|
getCutoffDate(retentionDays) {
|
|
209
275
|
const cutoff = new Date();
|
|
210
276
|
cutoff.setDate(cutoff.getDate() - retentionDays);
|
|
211
277
|
return cutoff.toISOString();
|
|
212
278
|
}
|
|
279
|
+
/**
|
|
280
|
+
* Build summary message for cleanup results
|
|
281
|
+
*/
|
|
213
282
|
buildSummary(result) {
|
|
214
283
|
const parts = [];
|
|
215
284
|
if (result.notesArchived > 0) {
|
|
@@ -233,5 +302,4 @@ class MemoryCleanupAgent extends base_agent_1.BaseAgent {
|
|
|
233
302
|
return parts.join(', ');
|
|
234
303
|
}
|
|
235
304
|
}
|
|
236
|
-
exports.MemoryCleanupAgent = MemoryCleanupAgent;
|
|
237
305
|
//# sourceMappingURL=memory-cleanup-agent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-cleanup-agent.js","sourceRoot":"","sources":["../src/memory-cleanup-agent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"memory-cleanup-agent.js","sourceRoot":"","sources":["../src/memory-cleanup-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAsB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGxF,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAapD;;;;;;;;;GASG;AACH,MAAM,OAAO,kBAAmB,SAAQ,SAAS;IAAjD;;QACqB,gCAA2B,GAAG,EAAE,CAAC;QACjC,mCAA8B,GAAG,GAAG,CAAC;QACrC,gCAA2B,GAAG,EAAE,CAAC;IA+UtD,CAAC;IA7UG;;OAEG;IACgB,KAAK,CAAC,oBAAoB,CACzC,MAA0B,EAC1B,MAA0B;QAE1B,SAAS,CAAC,8CAA8C,CAAC,CAAC;QAE1D,MAAM,WAAW,GAAG,MAAM,CAAC,WAAY,CAAC;QACxC,MAAM,MAAM,GAAkB;YAC1B,aAAa,EAAE,CAAC;YAChB,gBAAgB,EAAE,CAAC;YACnB,YAAY,EAAE,CAAC;YACf,eAAe,EAAE,CAAC;YAClB,MAAM,EAAE,EAAE;SACb,CAAC;QAEF,IAAI,CAAC;YACD,yEAAyE;YACzE,MAAM,IAAI,CAAC,mBAAmB,CAAC,MAAM,EAAE,WAAW,C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CAAC,EAAE,CAAC;YACrB,KAAK,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;QAC5C,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC3B,KAAK,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,qBAAqB,CAAC,CAAC;QAC7D,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;CACJ"}
|
|
@@ -1,22 +1,82 @@
|
|
|
1
|
-
import { BaseAgent } from './base-agent';
|
|
1
|
+
import { BaseAgent } from './base-agent.js';
|
|
2
2
|
import { ExecuteAgentParams, AgentConfiguration, BaseAgentNextStep } from '@memberjunction/ai-core-plus';
|
|
3
|
+
/**
|
|
4
|
+
* Memory Manager Agent - automatically extracts notes and examples from conversations.
|
|
5
|
+
* This agent runs on a schedule (every 15 minutes) and analyzes high-quality conversations
|
|
6
|
+
* and agent runs to extract learnings and example interactions.
|
|
7
|
+
*/
|
|
3
8
|
export declare class MemoryManagerAgent extends BaseAgent {
|
|
9
|
+
/** Verbose logging flag from params.verbose */
|
|
4
10
|
private _verbose;
|
|
11
|
+
/** Agent run ID for creating run steps */
|
|
5
12
|
private _agentRunID;
|
|
13
|
+
/** Step counter for sequential step numbering */
|
|
6
14
|
private _stepCounter;
|
|
15
|
+
/** Context user for step operations */
|
|
7
16
|
private _contextUser;
|
|
17
|
+
/**
|
|
18
|
+
* Create an agent run step record for observability.
|
|
19
|
+
* Returns null if agentRunID is not set (defensive check).
|
|
20
|
+
*/
|
|
8
21
|
private CreateRunStep;
|
|
22
|
+
/**
|
|
23
|
+
* Finalize an agent run step with success/failure status and output data.
|
|
24
|
+
*/
|
|
9
25
|
private FinalizeRunStep;
|
|
26
|
+
/**
|
|
27
|
+
* Get the last run timestamp for this agent to determine what to process.
|
|
28
|
+
* For first run, returns null to process all history (limited by MaxRows).
|
|
29
|
+
*/
|
|
10
30
|
private GetLastRunTime;
|
|
31
|
+
/**
|
|
32
|
+
* Load agents that have note or example injection enabled.
|
|
33
|
+
* Only extract notes/examples for agents that actually use these features.
|
|
34
|
+
*/
|
|
11
35
|
private LoadAgentsUsingMemory;
|
|
36
|
+
/**
|
|
37
|
+
* Load conversations with new activity since last run, including rating data.
|
|
38
|
+
* Uses a single optimized RunQuery that replaces 4 separate database queries.
|
|
39
|
+
* Returns conversations with their details, ratings, and agent run IDs for scope inheritance.
|
|
40
|
+
*/
|
|
12
41
|
private LoadConversationsWithNewActivity;
|
|
42
|
+
/**
|
|
43
|
+
* Load agent runs with high-usage artifacts since last run.
|
|
44
|
+
* Links through: ArtifactUse -> ArtifactVersion -> ConversationDetailArtifact -> ConversationDetail -> Conversation -> AIAgentRun
|
|
45
|
+
*/
|
|
13
46
|
private LoadHighValueAgentRuns;
|
|
47
|
+
/**
|
|
48
|
+
* Extract notes from conversations with rating data using AI analysis.
|
|
49
|
+
* This is the primary method that handles rated, unrated, positive, and negative feedback.
|
|
50
|
+
* Uses LLM-based deduplication and applies sparsity controls.
|
|
51
|
+
*/
|
|
14
52
|
private ExtractNotesFromConversations;
|
|
53
|
+
/**
|
|
54
|
+
* Common extraction logic for note extraction.
|
|
55
|
+
* Applies sparsity controls and deduplication.
|
|
56
|
+
*/
|
|
15
57
|
private executeNoteExtraction;
|
|
58
|
+
/**
|
|
59
|
+
* Extract examples from conversation details with high ratings.
|
|
60
|
+
* Uses LLM-based deduplication to avoid adding redundant examples.
|
|
61
|
+
*/
|
|
16
62
|
private ExtractExamples;
|
|
63
|
+
/**
|
|
64
|
+
* Check if a string is a valid UUID format.
|
|
65
|
+
*/
|
|
17
66
|
private isValidUUID;
|
|
67
|
+
/**
|
|
68
|
+
* Create note records from extracted data.
|
|
69
|
+
* Inherits scope from source agent run and applies scopeLevel to determine scope specificity.
|
|
70
|
+
*/
|
|
18
71
|
private CreateNoteRecords;
|
|
72
|
+
/**
|
|
73
|
+
* Create example records from extracted data.
|
|
74
|
+
* Inherits scope from source agent run and applies scopeLevel to determine scope specificity.
|
|
75
|
+
*/
|
|
19
76
|
private CreateExampleRecords;
|
|
77
|
+
/**
|
|
78
|
+
* Main execution method called by scheduler
|
|
79
|
+
*/
|
|
20
80
|
protected executeAgentInternal<P = any>(params: ExecuteAgentParams, config: AgentConfiguration): Promise<{
|
|
21
81
|
finalStep: BaseAgentNextStep<P>;
|
|
22
82
|
stepCount: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-manager-agent.d.ts","sourceRoot":"","sources":["../src/memory-manager-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAYzC,OAAO,EAAkB,kBAAkB,EAAE,kBAAkB,EAAE,iBAAiB,EAAyB,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"memory-manager-agent.d.ts","sourceRoot":"","sources":["../src/memory-manager-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAYzC,OAAO,EAAkB,kBAAkB,EAAE,kBAAkB,EAAE,iBAAiB,EAAyB,MAAM,8BAA8B,CAAC;AAmHhJ;;;;GAIG;AACH,qBACa,kBAAmB,SAAQ,SAAS;IAC7C,+CAA+C;IAC/C,OAAO,CAAC,QAAQ,CAAkB;IAClC,0CAA0C;IAC1C,OAAO,CAAC,WAAW,CAAuB;IAC1C,iDAAiD;IACjD,OAAO,CAAC,YAAY,CAAa;IACjC,uCAAuC;IACvC,OAAO,CAAC,YAAY,CAAyB;IAE7C;;;OAGG;YACW,aAAa;IAyC3B;;OAEG;YACW,eAAe;IAoC7B;;;OAGG;YACW,cAAc;IAoB5B;;;OAGG;YACW,qBAAqB;IA0BnC;;;;OAIG;YACW,gCAAgC;IA8E9C;;;OAGG;YACW,sBAAsB;IAuCpC;;;;OAIG;YACW,6BAA6B;IA4C3C;;;OAGG;YACW,qBAAqB;IA6QnC;;;OAGG;YACW,eAAe;IAgJ7B;;OAEG;IACH,OAAO,CAAC,WAAW;IAKnB;;;OAGG;YACW,iBAAiB;IAkI/B;;;OAGG;YACW,oBAAoB;IAoGlC;;OAEG;cACa,oBAAoB,CAAC,CAAC,GAAG,GAAG,EACxC,MAAM,EAAE,kBAAkB,EAC1B,MAAM,EAAE,kBAAkB,GAC3B,OAAO,CAAC;QAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAC,CAAC;CAgLnE"}
|