@memberjunction/ai-agents 5.21.0 → 5.23.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.
@@ -0,0 +1,107 @@
1
+ /**
2
+ * @fileoverview Server-side singleton that manages pending client tool requests.
3
+ *
4
+ * BaseAgent publishes a request via PubSub and awaits the returned Promise.
5
+ * The GraphQL resolver receives the client's response and resolves that Promise.
6
+ *
7
+ * @module @memberjunction/ai-agents
8
+ */
9
+ import { BaseSingleton } from '@memberjunction/global';
10
+ import { LogStatus, LogError } from '@memberjunction/core';
11
+ /** The PubSub topic used for client tool requests */
12
+ export const CLIENT_TOOL_REQUEST_TOPIC = 'CLIENT_TOOL_REQUEST';
13
+ /**
14
+ * Singleton that manages pending client tool requests.
15
+ * BaseAgent publishes a request and awaits the Promise.
16
+ * The GraphQL resolver receives the response and resolves the Promise.
17
+ */
18
+ export class ClientToolRequestManager extends BaseSingleton {
19
+ constructor() {
20
+ super();
21
+ this.pendingRequests = new Map();
22
+ /** Enriched tool definitions per session (from client decoration) */
23
+ this.sessionTools = new Map();
24
+ /** Optional PubSub publish function — injected by the server at startup */
25
+ this.publishFn = null;
26
+ }
27
+ static get Instance() {
28
+ return super.getInstance();
29
+ }
30
+ /**
31
+ * Set the publish function used to send tool requests to clients.
32
+ * Called once at server startup after PubSubManager is configured.
33
+ */
34
+ SetPublishFunction(fn) {
35
+ this.publishFn = fn;
36
+ }
37
+ /**
38
+ * Called by BaseAgent to send a request and await the response.
39
+ * Publishes via PubSub and returns a Promise that resolves when
40
+ * the client responds or times out.
41
+ */
42
+ async RequestClientTool(requestID, toolName, params, sessionID, agentRunID, timeoutMs, description) {
43
+ if (!this.publishFn) {
44
+ return {
45
+ RequestID: requestID,
46
+ Success: false,
47
+ ErrorMessage: 'PubSub not configured — cannot send client tool requests'
48
+ };
49
+ }
50
+ return new Promise((resolve) => {
51
+ const timer = setTimeout(() => {
52
+ this.pendingRequests.delete(requestID);
53
+ LogError(`Client tool "${toolName}" timed out after ${timeoutMs}ms (request ${requestID})`);
54
+ resolve({
55
+ RequestID: requestID,
56
+ Success: false,
57
+ ErrorMessage: `Client tool "${toolName}" timed out after ${timeoutMs}ms`
58
+ });
59
+ }, timeoutMs);
60
+ this.pendingRequests.set(requestID, { Resolve: resolve, Timer: timer });
61
+ const notification = {
62
+ AgentRunID: agentRunID,
63
+ SessionID: sessionID,
64
+ RequestID: requestID,
65
+ ToolName: toolName,
66
+ Params: JSON.stringify(params),
67
+ TimeoutMs: timeoutMs,
68
+ Description: description ?? ''
69
+ };
70
+ this.publishFn(CLIENT_TOOL_REQUEST_TOPIC, notification);
71
+ LogStatus(`ClientToolRequestManager: published "${toolName}" request (${requestID}) for session ${sessionID}`);
72
+ });
73
+ }
74
+ /**
75
+ * Called by the RespondToClientToolRequest GraphQL mutation.
76
+ * Resolves the pending Promise so the agent loop continues.
77
+ */
78
+ ReceiveResponse(response) {
79
+ const pending = this.pendingRequests.get(response.RequestID);
80
+ if (!pending) {
81
+ LogError(`ClientToolRequestManager: no pending request for ${response.RequestID}`);
82
+ return false;
83
+ }
84
+ clearTimeout(pending.Timer);
85
+ this.pendingRequests.delete(response.RequestID);
86
+ pending.Resolve(response);
87
+ LogStatus(`ClientToolRequestManager: received response for ${response.RequestID} (success=${response.Success})`);
88
+ return true;
89
+ }
90
+ /** Store enriched tool definitions for a session */
91
+ SetSessionTools(sessionID, tools) {
92
+ this.sessionTools.set(sessionID, tools);
93
+ }
94
+ /** Get enriched tool definitions for prompt injection */
95
+ GetSessionTools(sessionID) {
96
+ return this.sessionTools.get(sessionID) ?? [];
97
+ }
98
+ /** Clean up when session ends */
99
+ ClearSession(sessionID) {
100
+ this.sessionTools.delete(sessionID);
101
+ }
102
+ /** Get the number of pending requests (useful for testing/monitoring) */
103
+ get PendingRequestCount() {
104
+ return this.pendingRequests.size;
105
+ }
106
+ }
107
+ //# sourceMappingURL=ClientToolRequestManager.js.map
@@ -0,0 +1 @@
1
+ {"version":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AAS,aAAa,QAAQ,CAAC,OAAO,GAAG,CAAC,CAAC;QACjH,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,oDAAoD;IAC7C,eAAe,CAAC,SAAiB,EAAE,KAA2B;QACjE,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC;IAED,yDAAyD;IAClD,eAAe,CAAC,SAAiB;QACpC,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;IAClD,CAAC;IAED,iCAAiC;IAC1B,YAAY,CAAC,SAAiB;QACjC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;IAED,yEAAyE;IACzE,IAAW,mBAAmB;QAC1B,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC;IACrC,CAAC;CACJ"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * @fileoverview Knowledge Agent — a sub-agent for Sage that provides
3
+ * Knowledge Hub capabilities: search, vectorization, duplicate detection,
4
+ * and client-side navigation.
5
+ *
6
+ * Server tools execute on the server (search, vectorize, dedup).
7
+ * Client tools send instructions to the Angular client (navigate, filter).
8
+ *
9
+ * @module @memberjunction/ai-agents
10
+ */
11
+ import { UserInfo } from '@memberjunction/core';
12
+ /**
13
+ * Describes a tool available to the Knowledge Agent.
14
+ */
15
+ export interface KnowledgeAgentTool {
16
+ /** Unique tool name */
17
+ Name: string;
18
+ /** Human-readable description */
19
+ Description: string;
20
+ /** Where the tool executes */
21
+ ExecutionSide: 'server' | 'client';
22
+ /** JSON schema for tool parameters */
23
+ ParameterSchema: Record<string, unknown>;
24
+ }
25
+ /**
26
+ * Request to invoke a client-side tool from the server.
27
+ */
28
+ export interface ClientToolRequest {
29
+ /** Unique request ID for correlation */
30
+ RequestID: string;
31
+ /** The tool name to invoke */
32
+ ToolName: string;
33
+ /** Parameters for the tool */
34
+ Parameters: Record<string, unknown>;
35
+ /** Timestamp of the request */
36
+ RequestedAt: Date;
37
+ }
38
+ /**
39
+ * Response from a client-side tool invocation.
40
+ */
41
+ export interface ClientToolResponse {
42
+ /** Correlates to the original RequestID */
43
+ RequestID: string;
44
+ /** Whether the client tool executed successfully */
45
+ Success: boolean;
46
+ /** Result data from the tool */
47
+ Data?: Record<string, unknown>;
48
+ /** Error message if not successful */
49
+ ErrorMessage?: string;
50
+ /** Timestamp of the response */
51
+ RespondedAt: Date;
52
+ }
53
+ /**
54
+ * Knowledge Agent provides Knowledge Hub capabilities as a sub-agent.
55
+ *
56
+ * ## Server Tools
57
+ * - `search_knowledge` — Execute a unified search across vector + full-text indexes
58
+ * - `create_entity_document` — Create a new entity document template for vectorization
59
+ * - `run_vectorization` — Trigger vectorization for an entity
60
+ * - `run_duplicate_detection` — Run duplicate detection on an entity
61
+ *
62
+ * ## Client Tools (sent to browser)
63
+ * - `navigate_to_tab` — Switch the Knowledge Hub to a specific tab
64
+ * - `open_suggest_panel` — Open the document suggestion panel
65
+ * - `apply_search_filter` — Apply filters to the search UI
66
+ */
67
+ export declare class KnowledgeAgent {
68
+ /** All tools this agent can invoke */
69
+ static readonly Tools: KnowledgeAgentTool[];
70
+ /**
71
+ * Execute a server-side tool by name.
72
+ */
73
+ ExecuteServerTool(toolName: string, parameters: Record<string, unknown>, contextUser: UserInfo): Promise<{
74
+ Success: boolean;
75
+ Data?: Record<string, unknown>;
76
+ ErrorMessage?: string;
77
+ }>;
78
+ /**
79
+ * Build a client tool request for the Angular frontend.
80
+ */
81
+ BuildClientToolRequest(toolName: string, parameters: Record<string, unknown>): ClientToolRequest;
82
+ /**
83
+ * Get the tool definitions formatted for LLM function calling.
84
+ */
85
+ GetToolDefinitions(): Array<{
86
+ name: string;
87
+ description: string;
88
+ parameters: Record<string, unknown>;
89
+ }>;
90
+ /**
91
+ * Execute search via the SearchKnowledge GraphQL mutation.
92
+ * This uses the same UnifiedSearchService (vector + FTS + RRF fusion) that
93
+ * the Angular search component uses, ensuring consistent results.
94
+ */
95
+ private executeSearchKnowledge;
96
+ private executeCreateEntityDocument;
97
+ private executeRunVectorization;
98
+ private executeRunDuplicateDetection;
99
+ private buildDuplicateRequest;
100
+ private generateRequestID;
101
+ }
102
+ //# sourceMappingURL=KnowledgeAgent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KnowledgeAgent.d.ts","sourceRoot":"","sources":["../src/KnowledgeAgent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAiC,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAG/E;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,iCAAiC;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,8BAA8B;IAC9B,aAAa,EAAE,QAAQ,GAAG,QAAQ,CAAC;IACnC,sCAAsC;IACtC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC5C;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC9B,wCAAwC;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,8BAA8B;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,+BAA+B;IAC/B,WAAW,EAAE,IAAI,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B,2CAA2C;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,OAAO,EAAE,OAAO,CAAC;IACjB,gCAAgC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,sCAAsC;IACtC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gCAAgC;IAChC,WAAW,EAAE,IAAI,CAAC;CACrB;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,cAAc;IACvB,sCAAsC;IACtC,gBAAuB,KAAK,EAAE,kBAAkB,EAAE,CAkGhD;IAEF;;OAEG;IACU,iBAAiB,CAC1B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,WAAW,EAAE,QAAQ,GACtB,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAiBvF;;OAEG;IACI,sBAAsB,CACzB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACpC,iBAAiB;IASpB;;OAEG;IACI,kBAAkB,IAAI,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC;IAY9G;;;;OAIG;YACW,sBAAsB;YAwEtB,2BAA2B;YA0C3B,uBAAuB;YAkCvB,4BAA4B;IAmC1C,OAAO,CAAC,qBAAqB;IAc7B,OAAO,CAAC,iBAAiB;CAG5B"}
@@ -0,0 +1,338 @@
1
+ /**
2
+ * @fileoverview Knowledge Agent — a sub-agent for Sage that provides
3
+ * Knowledge Hub capabilities: search, vectorization, duplicate detection,
4
+ * and client-side navigation.
5
+ *
6
+ * Server tools execute on the server (search, vectorize, dedup).
7
+ * Client tools send instructions to the Angular client (navigate, filter).
8
+ *
9
+ * @module @memberjunction/ai-agents
10
+ */
11
+ import { LogStatus, LogError, Metadata } from '@memberjunction/core';
12
+ import { DuplicateRecordDetector } from '@memberjunction/ai-vector-dupe';
13
+ /**
14
+ * Knowledge Agent provides Knowledge Hub capabilities as a sub-agent.
15
+ *
16
+ * ## Server Tools
17
+ * - `search_knowledge` — Execute a unified search across vector + full-text indexes
18
+ * - `create_entity_document` — Create a new entity document template for vectorization
19
+ * - `run_vectorization` — Trigger vectorization for an entity
20
+ * - `run_duplicate_detection` — Run duplicate detection on an entity
21
+ *
22
+ * ## Client Tools (sent to browser)
23
+ * - `navigate_to_tab` — Switch the Knowledge Hub to a specific tab
24
+ * - `open_suggest_panel` — Open the document suggestion panel
25
+ * - `apply_search_filter` — Apply filters to the search UI
26
+ */
27
+ export class KnowledgeAgent {
28
+ /** All tools this agent can invoke */
29
+ static { this.Tools = [
30
+ // Server tools
31
+ {
32
+ Name: 'search_knowledge',
33
+ Description: 'Search across all knowledge using unified vector + full-text search with RRF fusion',
34
+ ExecutionSide: 'server',
35
+ ParameterSchema: {
36
+ type: 'object',
37
+ properties: {
38
+ query: { type: 'string', description: 'The search query text' },
39
+ maxResults: { type: 'number', description: 'Maximum results to return (default: 20)' },
40
+ entityNames: { type: 'array', items: { type: 'string' }, description: 'Filter to specific entity names' },
41
+ },
42
+ required: ['query'],
43
+ },
44
+ },
45
+ {
46
+ Name: 'create_entity_document',
47
+ Description: 'Create a new entity document template for vectorization using AI suggestions',
48
+ ExecutionSide: 'server',
49
+ ParameterSchema: {
50
+ type: 'object',
51
+ properties: {
52
+ entityName: { type: 'string', description: 'The entity to create a document template for' },
53
+ useCase: { type: 'string', enum: ['duplicate detection', 'search', 'classification'], description: 'The intended use case' },
54
+ },
55
+ required: ['entityName'],
56
+ },
57
+ },
58
+ {
59
+ Name: 'run_vectorization',
60
+ Description: 'Trigger vectorization for an entity using its configured document template',
61
+ ExecutionSide: 'server',
62
+ ParameterSchema: {
63
+ type: 'object',
64
+ properties: {
65
+ entityID: { type: 'string', description: 'The Entity ID to vectorize' },
66
+ entityDocumentID: { type: 'string', description: 'Optional Entity Document ID (if omitted, uses default for the entity)' },
67
+ listID: { type: 'string', description: 'Optional List ID to restrict vectorization to a specific list' },
68
+ listBatchCount: { type: 'number', description: 'Number of records to fetch at a time (default: 50)' },
69
+ },
70
+ required: ['entityID'],
71
+ },
72
+ },
73
+ {
74
+ Name: 'run_duplicate_detection',
75
+ Description: 'Run duplicate detection on an entity using vector similarity',
76
+ ExecutionSide: 'server',
77
+ ParameterSchema: {
78
+ type: 'object',
79
+ properties: {
80
+ entityID: { type: 'string', description: 'The Entity ID to check for duplicates' },
81
+ listID: { type: 'string', description: 'The List ID containing records to check' },
82
+ entityDocumentID: { type: 'string', description: 'The Entity Document ID defining the vectorization template' },
83
+ probabilityScore: { type: 'number', description: 'Minimum score threshold for potential duplicates (0-1)' },
84
+ },
85
+ required: ['entityID', 'listID'],
86
+ },
87
+ },
88
+ // Client tools
89
+ {
90
+ Name: 'navigate_to_tab',
91
+ Description: 'Navigate the Knowledge Hub UI to a specific tab (search, config, vectors, duplicates)',
92
+ ExecutionSide: 'client',
93
+ ParameterSchema: {
94
+ type: 'object',
95
+ properties: {
96
+ tab: { type: 'string', enum: ['search', 'config', 'vectors', 'duplicates'], description: 'Tab to navigate to' },
97
+ },
98
+ required: ['tab'],
99
+ },
100
+ },
101
+ {
102
+ Name: 'open_suggest_panel',
103
+ Description: 'Open the entity document suggestion panel in the UI',
104
+ ExecutionSide: 'client',
105
+ ParameterSchema: {
106
+ type: 'object',
107
+ properties: {
108
+ entityName: { type: 'string', description: 'Pre-select this entity in the suggestion panel' },
109
+ },
110
+ required: [],
111
+ },
112
+ },
113
+ {
114
+ Name: 'apply_search_filter',
115
+ Description: 'Apply search filters to the Knowledge Hub search UI',
116
+ ExecutionSide: 'client',
117
+ ParameterSchema: {
118
+ type: 'object',
119
+ properties: {
120
+ entityNames: { type: 'array', items: { type: 'string' }, description: 'Filter to these entity names' },
121
+ sourceTypes: { type: 'array', items: { type: 'string' }, description: 'Filter to these source types' },
122
+ tags: { type: 'array', items: { type: 'string' }, description: 'Filter to these tags' },
123
+ },
124
+ required: [],
125
+ },
126
+ },
127
+ ]; }
128
+ /**
129
+ * Execute a server-side tool by name.
130
+ */
131
+ async ExecuteServerTool(toolName, parameters, contextUser) {
132
+ LogStatus(`KnowledgeAgent: Executing server tool "${toolName}"`);
133
+ switch (toolName) {
134
+ case 'search_knowledge':
135
+ return this.executeSearchKnowledge(parameters, contextUser);
136
+ case 'create_entity_document':
137
+ return this.executeCreateEntityDocument(parameters, contextUser);
138
+ case 'run_vectorization':
139
+ return this.executeRunVectorization(parameters, contextUser);
140
+ case 'run_duplicate_detection':
141
+ return this.executeRunDuplicateDetection(parameters, contextUser);
142
+ default:
143
+ return { Success: false, ErrorMessage: `Unknown server tool: ${toolName}` };
144
+ }
145
+ }
146
+ /**
147
+ * Build a client tool request for the Angular frontend.
148
+ */
149
+ BuildClientToolRequest(toolName, parameters) {
150
+ return {
151
+ RequestID: this.generateRequestID(),
152
+ ToolName: toolName,
153
+ Parameters: parameters,
154
+ RequestedAt: new Date(),
155
+ };
156
+ }
157
+ /**
158
+ * Get the tool definitions formatted for LLM function calling.
159
+ */
160
+ GetToolDefinitions() {
161
+ return KnowledgeAgent.Tools.map(tool => ({
162
+ name: tool.Name,
163
+ description: tool.Description,
164
+ parameters: tool.ParameterSchema,
165
+ }));
166
+ }
167
+ // ================================================================
168
+ // Private Tool Implementations
169
+ // ================================================================
170
+ /**
171
+ * Execute search via the SearchKnowledge GraphQL mutation.
172
+ * This uses the same UnifiedSearchService (vector + FTS + RRF fusion) that
173
+ * the Angular search component uses, ensuring consistent results.
174
+ */
175
+ async executeSearchKnowledge(parameters, _contextUser) {
176
+ try {
177
+ const query = String(parameters['query'] || '');
178
+ if (!query.trim()) {
179
+ return { Success: false, ErrorMessage: 'Query cannot be empty' };
180
+ }
181
+ const maxResults = Number(parameters['maxResults']) || 20;
182
+ const entityFilter = parameters['entityNames'];
183
+ const provider = Metadata.Provider;
184
+ if (!provider?.ExecuteGQL) {
185
+ return { Success: false, ErrorMessage: 'GraphQL provider not available for search' };
186
+ }
187
+ const mutation = `
188
+ mutation SearchKnowledge($query: String!, $maxResults: Float, $filters: SearchFiltersInput) {
189
+ SearchKnowledge(query: $query, maxResults: $maxResults, filters: $filters) {
190
+ Success
191
+ TotalCount
192
+ ElapsedMs
193
+ ErrorMessage
194
+ Results {
195
+ ID
196
+ EntityName
197
+ RecordID
198
+ SourceType
199
+ Title
200
+ Snippet
201
+ Score
202
+ Tags
203
+ }
204
+ }
205
+ }
206
+ `;
207
+ const filters = entityFilter?.length
208
+ ? { EntityNames: entityFilter }
209
+ : undefined;
210
+ const gqlResult = await provider.ExecuteGQL(mutation, {
211
+ query,
212
+ maxResults,
213
+ filters
214
+ });
215
+ const data = gqlResult['SearchKnowledge'];
216
+ if (!data?.['Success']) {
217
+ return {
218
+ Success: false,
219
+ ErrorMessage: String(data?.['ErrorMessage'] ?? 'Search failed')
220
+ };
221
+ }
222
+ return {
223
+ Success: true,
224
+ Data: {
225
+ Results: data['Results'],
226
+ TotalCount: data['TotalCount'],
227
+ ElapsedMs: data['ElapsedMs'],
228
+ },
229
+ };
230
+ }
231
+ catch (error) {
232
+ const msg = error instanceof Error ? error.message : String(error);
233
+ LogError(`KnowledgeAgent.search_knowledge failed: ${msg}`);
234
+ return { Success: false, ErrorMessage: msg };
235
+ }
236
+ }
237
+ async executeCreateEntityDocument(parameters, contextUser) {
238
+ try {
239
+ const entityName = String(parameters['entityName'] || '');
240
+ const useCase = String(parameters['useCase'] || 'search');
241
+ if (!entityName) {
242
+ return { Success: false, ErrorMessage: 'entityName is required' };
243
+ }
244
+ // Dynamic import to avoid circular dependencies
245
+ const { EntityDocumentSuggester } = await import('@memberjunction/ai-vector-sync');
246
+ const suggester = new EntityDocumentSuggester();
247
+ const response = await suggester.SuggestDocument(entityName, useCase, contextUser);
248
+ if (!response.Success || !response.Suggestion) {
249
+ return { Success: false, ErrorMessage: response.ErrorMessage || 'Suggestion failed' };
250
+ }
251
+ return {
252
+ Success: true,
253
+ Data: {
254
+ Template: response.Suggestion.template,
255
+ SelectedFields: response.Suggestion.selectedFields,
256
+ Reasoning: response.Suggestion.reasoning,
257
+ PotentialMatchThreshold: response.Suggestion.potentialMatchThreshold,
258
+ AbsoluteMatchThreshold: response.Suggestion.absoluteMatchThreshold,
259
+ },
260
+ };
261
+ }
262
+ catch (error) {
263
+ const msg = error instanceof Error ? error.message : String(error);
264
+ LogError(`KnowledgeAgent.create_entity_document failed: ${msg}`);
265
+ return { Success: false, ErrorMessage: msg };
266
+ }
267
+ }
268
+ async executeRunVectorization(parameters, contextUser) {
269
+ try {
270
+ const entityID = String(parameters['entityID'] || '');
271
+ if (!entityID) {
272
+ return { Success: false, ErrorMessage: 'entityID is required' };
273
+ }
274
+ // Dynamic import to avoid circular dependencies
275
+ const { EntityVectorSyncer } = await import('@memberjunction/ai-vector-sync');
276
+ const syncer = new EntityVectorSyncer();
277
+ await syncer.Config(false, contextUser);
278
+ const result = await syncer.VectorizeEntity({
279
+ entityID,
280
+ entityDocumentID: parameters['entityDocumentID'] ? String(parameters['entityDocumentID']) : undefined,
281
+ listID: parameters['listID'] ? String(parameters['listID']) : undefined,
282
+ listBatchCount: Number(parameters['listBatchCount']) || 50,
283
+ }, contextUser);
284
+ return {
285
+ Success: result.success,
286
+ Data: { Status: result.status },
287
+ ErrorMessage: result.errorMessage || undefined,
288
+ };
289
+ }
290
+ catch (error) {
291
+ const msg = error instanceof Error ? error.message : String(error);
292
+ LogError(`KnowledgeAgent.run_vectorization failed: ${msg}`);
293
+ return { Success: false, ErrorMessage: msg };
294
+ }
295
+ }
296
+ async executeRunDuplicateDetection(parameters, contextUser) {
297
+ try {
298
+ const entityID = String(parameters['entityID'] || '');
299
+ const listID = String(parameters['listID'] || '');
300
+ if (!entityID) {
301
+ return { Success: false, ErrorMessage: 'entityID is required' };
302
+ }
303
+ if (!listID) {
304
+ return { Success: false, ErrorMessage: 'listID is required' };
305
+ }
306
+ const detector = new DuplicateRecordDetector();
307
+ detector.CurrentUser = contextUser;
308
+ const request = this.buildDuplicateRequest(entityID, listID, parameters);
309
+ const result = await detector.GetDuplicateRecords(request, contextUser);
310
+ return {
311
+ Success: result.Status === 'Success',
312
+ Data: {
313
+ Status: result.Status,
314
+ DuplicateCount: result.PotentialDuplicateResult?.length || 0,
315
+ },
316
+ ErrorMessage: result.ErrorMessage || undefined,
317
+ };
318
+ }
319
+ catch (error) {
320
+ const msg = error instanceof Error ? error.message : String(error);
321
+ LogError(`KnowledgeAgent.run_duplicate_detection failed: ${msg}`);
322
+ return { Success: false, ErrorMessage: msg };
323
+ }
324
+ }
325
+ buildDuplicateRequest(entityID, listID, parameters) {
326
+ return {
327
+ EntityID: entityID,
328
+ ListID: listID,
329
+ RecordIDs: [],
330
+ EntityDocumentID: parameters['entityDocumentID'] ? String(parameters['entityDocumentID']) : undefined,
331
+ ProbabilityScore: parameters['probabilityScore'] != null ? Number(parameters['probabilityScore']) : undefined,
332
+ };
333
+ }
334
+ generateRequestID() {
335
+ return `ctr-${Date.now()}-${Math.random().toString(36).substring(2, 8)}`;
336
+ }
337
+ }
338
+ //# sourceMappingURL=KnowledgeAgent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KnowledgeAgent.js","sourceRoot":"","sources":["../src/KnowledgeAgent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAY,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AA8CzE;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,cAAc;IACvB,sCAAsC;aACf,UAAK,GAAyB;QACjD,eAAe;QACf;YACI,IAAI,EAAE,kBAAkB;YACxB,WAAW,EAAE,qFAAqF;YAClG,aAAa,EAAE,QAAQ;YACvB,eAAe,EAAE;gBACb,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACR,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,uBAAuB,EAAE;oBAC/D,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,yCAAyC,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,KAAK,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC;QACjD,CAAC;IACL,CAAC;IAEO,qBAAqB,CACzB,QAAgB,EAChB,MAAc,EACd,UAAmC;QAEnC,OAAO;YACH,QAAQ,EAAE,QAAQ;YAClB,MAAM,EAAE,MAAM;YACd,SAAS,EAAE,EAAE;YACb,gBAAgB,EAAE,UAAU,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;YACrG,gBAAgB,EAAE,UAAU,CAAC,kBAAkB,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;SAChH,CAAC;IACN,CAAC;IAEO,iBAAiB;QACrB,OAAO,OAAO,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IAC7E,CAAC"}
@@ -1,10 +1,19 @@
1
1
  /**
2
- * @fileoverview Type definitions for Loop Agent Type prompt parameters.
2
+ * @fileoverview Type definitions for Loop Agent Type parameters.
3
3
  *
4
- * This module contains the interface definition for parameters that control
5
- * which sections are included in the Loop Agent Type's system prompt.
6
- * These parameters enable significant token savings for agents that don't
7
- * need all capabilities documented in the full system prompt.
4
+ * This module defines the per-agent configuration interface for Loop-type agents.
5
+ * These parameters are stored in the `AgentTypePromptParams` JSON field on the
6
+ * `MJ: AI Agents` entity and control:
7
+ *
8
+ * - **Prompt inclusion**: Which sections are included in the system prompt
9
+ * (enables token savings by excluding unused documentation)
10
+ * - **Client tools**: Browser-side tools the agent can invoke (navigation, UI actions)
11
+ * - **Content limits**: Max sub-agents/actions to include in prompts
12
+ *
13
+ * Parameters are merged with three-level precedence:
14
+ * 1. Schema defaults (from AIAgentType.PromptParamsSchema) — lowest priority
15
+ * 2. Agent config (from AIAgent.AgentTypePromptParams) — medium priority
16
+ * 3. Runtime override (from ExecuteAgentParams.data.__agentTypePromptParams) — highest priority
8
17
  *
9
18
  * @module @memberjunction/ai-agents
10
19
  * @author MemberJunction.com
@@ -71,11 +80,13 @@ export interface ResponseTypeInclusionRules {
71
80
  */
72
81
  export declare const DEFAULT_RESPONSE_TYPE_INCLUSION_RULES: Required<ResponseTypeInclusionRules>;
73
82
  /**
74
- * Prompt parameters for Loop Agent Type.
75
- * Controls which sections are included in the system prompt to optimize token usage.
83
+ * Configuration parameters for Loop Agent Type.
84
+ *
85
+ * Controls prompt content (which sections are included), client tool availability,
86
+ * and content limits. Stored in `AIAgent.AgentTypePromptParams` as JSON.
76
87
  *
77
- * All boolean properties default to true (include section) when not specified.
78
- * Set to false to exclude a section from the prompt.
88
+ * All boolean prompt-inclusion properties default to true (include section).
89
+ * Set to false to exclude a section from the prompt and save tokens.
79
90
  *
80
91
  * These parameters are configured at three levels with merge precedence:
81
92
  * 1. Schema defaults (from AIAgentType.PromptParamsSchema) - lowest priority
@@ -191,6 +202,14 @@ export interface LoopAgentTypePromptParams {
191
202
  * @default true
192
203
  */
193
204
  includePayloadInPrompt?: boolean;
205
+ /**
206
+ * Include current date, time, and day of week in the prompt.
207
+ * Provides the LLM with accurate temporal context so it doesn't hallucinate
208
+ * dates or claim it doesn't know the current time.
209
+ * Disable for agents where temporal context is irrelevant.
210
+ * @default true
211
+ */
212
+ includeDateTimeInPrompt?: boolean;
194
213
  /**
195
214
  * Include scratchpad documentation and current scratchpad state in the prompt.
196
215
  * The scratchpad is private working memory for notes and task tracking.
@@ -225,7 +244,7 @@ export interface LoopAgentTypePromptParams {
225
244
  }
226
245
  /**
227
246
  * Default values for LoopAgentTypePromptParams.
228
- * All section flags default to true (include), and limits default to -1 (include all).
247
+ * All section flags default to true (include), limits default to -1 (include all).
229
248
  */
230
249
  export declare const DEFAULT_LOOP_AGENT_PROMPT_PARAMS: Required<LoopAgentTypePromptParams>;
231
250
  //# sourceMappingURL=loop-agent-prompt-params.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"loop-agent-prompt-params.d.ts","sourceRoot":"","sources":["../../src/agent-types/loop-agent-prompt-params.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,0BAA0B;IACvC;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,eAAO,MAAM,qCAAqC,EAAE,QAAQ,CAAC,0BAA0B,CAOtF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,MAAM,WAAW,yBAAyB;IAGtC;;;;;;;;;OASG;IACH,6BAA6B,CAAC,EAAE,0BAA0B,CAAC;IAE3D;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;;;;;OAMG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAElC;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;;;;;;OAOG;IACH,2BAA2B,CAAC,EAAE,OAAO,CAAC;IAEtC;;;;;OAKG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAElC;;;;;;OAMG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAEjC;;;;;OAKG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAI5B;;;;;;;OAOG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;GAGG;AACH,eAAO,MAAM,gCAAgC,EAAE,QAAQ,CAAC,yBAAyB,CAahF,CAAC"}
1
+ {"version":3,"file":"loop-agent-prompt-params.d.ts","sourceRoot":"","sources":["../../src/agent-types/loop-agent-prompt-params.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,0BAA0B;IACvC;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,eAAO,MAAM,qCAAqC,EAAE,QAAQ,CAAC,0BAA0B,CAOtF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,MAAM,WAAW,yBAAyB;IAGtC;;;;;;;;;OASG;IACH,6BAA6B,CAAC,EAAE,0BAA0B,CAAC;IAE3D;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;;;;;OAMG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAElC;;;;;;OAMG;IACH,kBAAkB,CAAC,E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