@memberjunction/aiengine 2.50.0 → 2.52.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/README.md CHANGED
@@ -9,9 +9,21 @@ The MemberJunction AI Engine package provides a comprehensive framework for AI-p
9
9
  - **📊 Performance Monitoring**: Basic tracking and analytics for AI operations
10
10
  - **🔗 Entity Integration**: Seamless integration with MemberJunction entity system
11
11
  - **⚡ Simple Prompt Execution**: Basic prompt execution for quick AI tasks
12
+ - **🏗️ Agent Type System**: Defines agent types and their behavioral characteristics
12
13
 
13
14
  > **📝 Advanced Prompt Management**: For sophisticated stored prompt management, template rendering, and parallel execution capabilities, see the [@memberjunction/ai-prompts](../Prompts/README.md) package.
14
15
 
16
+ ### Type Organization Update (2025)
17
+
18
+ As part of improving code organization:
19
+ - **This package** now contains:
20
+ - Extended entity classes for AI operations
21
+ - Agent type definitions and factory interfaces
22
+ - The new `agent-types.ts` file with agent type classes
23
+ - **Base AI types** are imported from `@memberjunction/ai` (Core)
24
+ - **Agent execution types** are imported from `@memberjunction/ai-agents`
25
+ - **Prompt types** are imported from `@memberjunction/ai-prompts`
26
+
15
27
  ## Installation
16
28
 
17
29
  ```bash
@@ -22,6 +34,7 @@ npm install @memberjunction/aiengine
22
34
 
23
35
  - Node.js 16+
24
36
  - MemberJunction Core libraries
37
+ - [@memberjunction/ai](../Core/README.md) for base AI types
25
38
  - At least one AI model provider (e.g., `@memberjunction/ai-openai`)
26
39
 
27
40
  ## Core Architecture
@@ -190,6 +203,63 @@ class AIPromptCategoryEntityExtended extends AIPromptCategoryEntity {
190
203
 
191
204
  The AI Engine automatically extends AI Model entities with additional capabilities from the AI provider system. These extended models include all driver-specific functionality and API integration.
192
205
 
206
+ ### Agent Type System
207
+
208
+ The Engine now includes specialized agent type classes in `agent-types.ts`:
209
+
210
+ ```typescript
211
+ // Base agent type - foundation for all agent types
212
+ import { BaseAgentType } from '@memberjunction/aiengine';
213
+
214
+ // Specialized agent types
215
+ import { LoopAgentType } from '@memberjunction/aiengine';
216
+
217
+ // Agent types define behavioral characteristics:
218
+ // - System prompts for consistent behavior
219
+ // - Decision-making patterns
220
+ // - Execution flow control
221
+ ```
222
+
223
+ ### Type-Safe Sub-Agent Requests (New in v2.51.0)
224
+
225
+ The AI Engine now provides type-safe context propagation for sub-agent requests. Context is optional in the request definition and is provided at execution time by the framework:
226
+
227
+ ```typescript
228
+ import { AgentSubAgentRequest, BaseAgentNextStep } from '@memberjunction/aiengine';
229
+
230
+ // Define your context type
231
+ interface MyContext {
232
+ apiEndpoint: string;
233
+ apiKey: string;
234
+ environment: 'dev' | 'staging' | 'prod';
235
+ }
236
+
237
+ // Create a typed sub-agent request - context is optional here
238
+ const subAgentRequest: AgentSubAgentRequest<MyContext> = {
239
+ id: 'sub-agent-uuid',
240
+ name: 'DataProcessorAgent',
241
+ message: 'Process the uploaded data',
242
+ terminateAfter: false
243
+ // context is NOT set by AI agents - it's provided by the framework at execution time
244
+ };
245
+
246
+ // Use in agent next step decisions
247
+ const nextStep: BaseAgentNextStep<MyContext> = {
248
+ step: 'sub-agent',
249
+ subAgent: subAgentRequest
250
+ };
251
+
252
+ // At execution time, the framework provides the context:
253
+ // The parent agent's context is automatically passed to sub-agents
254
+ // This ensures consistent runtime configuration across the agent hierarchy
255
+ ```
256
+
257
+ This pattern ensures:
258
+ - Type safety when defining sub-agent requests
259
+ - Context is consistently provided by the execution framework
260
+ - AI agents focus on decision logic without managing runtime configuration
261
+ - Runtime contexts (API keys, endpoints, etc.) flow through the agent hierarchy automatically
262
+
193
263
 
194
264
  ## Advanced Features
195
265
 
@@ -267,12 +337,35 @@ const response = await AIEngine.Instance.SimpleLLMCompletion(
267
337
 
268
338
  For sophisticated parallel execution, template rendering, and stored prompt management, see the [@memberjunction/ai-prompts](../Prompts/README.md) package.
269
339
 
340
+ ## Import Examples
341
+
342
+ ```typescript
343
+ // Import main AI Engine class
344
+ import { AIEngine } from '@memberjunction/aiengine';
345
+
346
+ // Import extended entity types
347
+ import {
348
+ AIAgentEntityExtended,
349
+ AIPromptCategoryEntityExtended,
350
+ AIModelEntityExtended
351
+ } from '@memberjunction/aiengine';
352
+
353
+ // Import agent type classes
354
+ import { BaseAgentType, LoopAgentType } from '@memberjunction/aiengine';
355
+
356
+ // Import base AI types from Core
357
+ import { BaseLLM, ChatParams, ChatResult } from '@memberjunction/ai';
358
+
359
+ // When working with agents, import execution types
360
+ import { AgentExecutionParams, AgentExecutionResult } from '@memberjunction/ai-agents';
361
+ ```
362
+
270
363
  ## Dependencies
271
364
 
272
365
  - `@memberjunction/core`: MemberJunction core library
273
366
  - `@memberjunction/global`: MemberJunction global utilities
274
367
  - `@memberjunction/core-entities`: MemberJunction entity definitions
275
- - `@memberjunction/ai`: AI abstractions and interfaces
368
+ - `@memberjunction/ai`: Base AI types and interfaces (imported for core types)
276
369
  - `@memberjunction/templates`: Template engine integration
277
370
  - `@memberjunction/templates-base-types`: Template base type definitions
278
371
  - `rxjs`: Reactive programming support
@@ -0,0 +1,127 @@
1
+ import { AIPromptRunResult } from '@memberjunction/ai';
2
+ import { AIAgentRunEntity, AIAgentRunStepEntity } from '@memberjunction/core-entities';
3
+ import { ActionResult, ActionResultSimple } from '@memberjunction/actions-base';
4
+ export type AgentAction = {
5
+ id: string;
6
+ name: string;
7
+ params: Record<string, unknown>;
8
+ };
9
+ export type AgentSubAgentRequest<TContext = any> = {
10
+ id: string;
11
+ name: string;
12
+ message: string;
13
+ terminateAfter: boolean;
14
+ context?: TContext;
15
+ };
16
+ export type BaseAgentNextStep<TContext = any> = {
17
+ step: 'success' | 'failed' | 'retry' | 'sub-agent' | 'actions' | 'chat';
18
+ returnValue?: any;
19
+ errorMessage?: string;
20
+ retryReason?: string;
21
+ retryInstructions?: string;
22
+ subAgent?: AgentSubAgentRequest<TContext>;
23
+ actions?: AgentAction[];
24
+ userMessage?: string;
25
+ };
26
+ export type ExecuteAgentResult = {
27
+ success: boolean;
28
+ finalStep: BaseAgentNextStep['step'];
29
+ returnValue?: any;
30
+ errorMessage?: string;
31
+ cancelled?: boolean;
32
+ cancellationReason?: 'user_requested' | 'timeout' | 'system';
33
+ agentRun: AIAgentRunEntity;
34
+ executionTree: ExecutionNode[];
35
+ };
36
+ export type ExecutionChainStep = {
37
+ stepEntity: AIAgentRunStepEntity;
38
+ executionType: 'prompt' | 'action' | 'sub-agent' | 'decision' | 'chat' | 'validation';
39
+ executionResult: StepExecutionResult;
40
+ nextStepDecision: NextStepDecision;
41
+ startTime: Date;
42
+ endTime?: Date;
43
+ durationMs?: number;
44
+ };
45
+ export type StepExecutionResult = PromptExecutionResult | ActionExecutionResult | SubAgentExecutionResult | DecisionExecutionResult | ChatExecutionResult | ValidationExecutionResult;
46
+ export type ExecutionNode = {
47
+ step: AIAgentRunStepEntity;
48
+ inputData: any;
49
+ outputData: any;
50
+ executionType: 'prompt' | 'action' | 'sub-agent' | 'decision' | 'chat' | 'validation';
51
+ startTime: Date;
52
+ endTime?: Date;
53
+ durationMs?: number;
54
+ nextStepDecision?: NextStepDecision;
55
+ children?: ExecutionNode[];
56
+ depth: number;
57
+ parentStepId?: string;
58
+ agentHierarchy: string[];
59
+ };
60
+ export type PromptExecutionResult = {
61
+ type: 'prompt';
62
+ promptId: string;
63
+ promptName: string;
64
+ result: AIPromptRunResult;
65
+ };
66
+ export type ActionExecutionResult = {
67
+ type: 'action';
68
+ actionId: string;
69
+ actionName: string;
70
+ result: ActionResult | ActionResultSimple;
71
+ };
72
+ export type SubAgentExecutionResult = {
73
+ type: 'sub-agent';
74
+ subAgentId: string;
75
+ subAgentName: string;
76
+ result: ExecuteAgentResult;
77
+ };
78
+ export type DecisionExecutionResult = {
79
+ type: 'decision';
80
+ decisionLogic: string;
81
+ inputContext: any;
82
+ result: BaseAgentNextStep;
83
+ };
84
+ export type ChatExecutionResult = {
85
+ type: 'chat';
86
+ userMessage: string;
87
+ userResponse?: string;
88
+ result: {
89
+ success: boolean;
90
+ continueExecution: boolean;
91
+ };
92
+ };
93
+ export type ValidationExecutionResult = {
94
+ type: 'validation';
95
+ validationTarget: string;
96
+ result: {
97
+ valid: boolean;
98
+ errors?: string[];
99
+ };
100
+ };
101
+ export type NextStepDecision = {
102
+ decision: BaseAgentNextStep['step'];
103
+ reasoning?: string;
104
+ nextStepDetails?: NextStepDetails;
105
+ };
106
+ export type NextStepDetails = {
107
+ type: 'prompt';
108
+ promptId: string;
109
+ promptName: string;
110
+ } | {
111
+ type: 'action';
112
+ actions: AgentAction[];
113
+ } | {
114
+ type: 'sub-agent';
115
+ subAgent: AgentSubAgentRequest;
116
+ } | {
117
+ type: 'retry';
118
+ retryReason: string;
119
+ retryInstructions: string;
120
+ } | {
121
+ type: 'chat';
122
+ message: string;
123
+ } | {
124
+ type: 'complete';
125
+ returnValue?: any;
126
+ };
127
+ //# sourceMappingURL=agent-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-types.d.ts","sourceRoot":"","sources":["../src/agent-types.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACvF,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAUhF,MAAM,MAAM,WAAW,GAAG;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC,CAAA;AAwCD,MAAM,MAAM,oBAAoB,CAAC,QAAQ,GAAG,GAAG,IAAI;IAC/C,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,OAAO,CAAC;IACxB,OAAO,CAAC,EAAE,QAAQ,CAAC;CACtB,CAAA;AAgCD,MAAM,MAAM,iBAAiB,CAA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ceMappingURL=agent-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-types.js","sourceRoot":"","sources":["../src/agent-types.ts"],"names":[],"mappings":""}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './AIEngine';
2
+ export * from './agent-types';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC"}
package/dist/index.js CHANGED
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./AIEngine"), exports);
18
+ __exportStar(require("./agent-types"), exports);
18
19
  //# 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":";;;;;;;;;;;;;;;;AAAA,6CAA2B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,gDAA8B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberjunction/aiengine",
3
- "version": "2.50.0",
3
+ "version": "2.52.0",
4
4
  "description": "MemberJunction: AI Engine Package - handles automatic execution of Entity AI Actions using AI Models",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,11 +15,11 @@
15
15
  "author": "MemberJunction.com",
16
16
  "license": "ISC",
17
17
  "dependencies": {
18
- "@memberjunction/core": "2.50.0",
19
- "@memberjunction/global": "2.50.0",
20
- "@memberjunction/core-entities": "2.50.0",
21
- "@memberjunction/ai": "2.50.0",
22
- "@memberjunction/ai-engine-base": "2.50.0",
18
+ "@memberjunction/core": "2.52.0",
19
+ "@memberjunction/global": "2.52.0",
20
+ "@memberjunction/core-entities": "2.52.0",
21
+ "@memberjunction/ai": "2.52.0",
22
+ "@memberjunction/ai-engine-base": "2.52.0",
23
23
  "dotenv": "^16.4.1",
24
24
  "rxjs": "^7.8.1"
25
25
  },