@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
|
@@ -1,38 +1,150 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Base agent type abstraction for the MemberJunction AI Agent framework.
|
|
3
|
+
*
|
|
4
|
+
* This module defines the abstract BaseAgentType class that serves as the foundation
|
|
5
|
+
* for different agent execution patterns. Agent types encapsulate reusable behavior
|
|
6
|
+
* patterns (like loops, decision trees, or linear flows) that can be applied to
|
|
7
|
+
* multiple agents through configuration rather than code duplication.
|
|
8
|
+
*
|
|
9
|
+
* @module @memberjunction/ai-agents
|
|
10
|
+
* @author MemberJunction.com
|
|
11
|
+
* @since 2.49.0
|
|
12
|
+
*/
|
|
13
|
+
import { MJGlobal, JSONValidator } from '@memberjunction/global';
|
|
14
|
+
import { LogError, IsVerboseLoggingEnabled } from '@memberjunction/core';
|
|
15
|
+
/**
|
|
16
|
+
* Abstract base class for agent type implementations.
|
|
17
|
+
*
|
|
18
|
+
* Agent types define reusable execution patterns that control how agents behave.
|
|
19
|
+
* Each agent type is associated with a system prompt that guides the LLM's output
|
|
20
|
+
* format and decision-making process. Common agent type patterns include:
|
|
21
|
+
*
|
|
22
|
+
* - **Loop**: Continues executing until a goal is achieved
|
|
23
|
+
* - **SinglePass**: Executes once and returns a result
|
|
24
|
+
* - **DecisionTree**: Makes branching decisions based on conditions
|
|
25
|
+
* - **Pipeline**: Executes a series of steps in sequence
|
|
26
|
+
*
|
|
27
|
+
* The agent type's system prompt should be designed to produce output that can
|
|
28
|
+
* be parsed by the DetermineNextStep method to decide what happens next in the
|
|
29
|
+
* agent's execution flow.
|
|
30
|
+
*
|
|
31
|
+
* @abstract
|
|
32
|
+
* @class BaseAgentType
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* export class LoopAgentType extends BaseAgentType {
|
|
37
|
+
* public async DetermineNextStep(): Promise<BaseAgentNextStep> {
|
|
38
|
+
* // Parse LLM output to determine if goal is achieved
|
|
39
|
+
* const goalAchieved = // ... parsing logic
|
|
40
|
+
*
|
|
41
|
+
* return {
|
|
42
|
+
* step: goalAchieved ? 'success' : 'action',
|
|
43
|
+
* payload: result
|
|
44
|
+
* };
|
|
45
|
+
* }
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export class BaseAgentType {
|
|
7
50
|
constructor() {
|
|
8
|
-
|
|
51
|
+
/**
|
|
52
|
+
* JSON validator instance for cleaning and validating responses
|
|
53
|
+
* @protected
|
|
54
|
+
*/
|
|
55
|
+
this._jsonValidator = new JSONValidator();
|
|
9
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Common placeholder for current payload injection
|
|
59
|
+
* @static
|
|
60
|
+
*/
|
|
61
|
+
static { this.CURRENT_PAYLOAD_PLACEHOLDER = '_CURRENT_PAYLOAD'; }
|
|
62
|
+
/**
|
|
63
|
+
* Helper method that retrieves an instance of the agent type based on the provided agent type entity.
|
|
64
|
+
*
|
|
65
|
+
* This method uses the ClassFactory to create an instance of the agent type class
|
|
66
|
+
* specified in the DriverClass field of the agent type entity. If the DriverClass is not
|
|
67
|
+
* specified, it throws an error.
|
|
68
|
+
*
|
|
69
|
+
* @async
|
|
70
|
+
* @static
|
|
71
|
+
* @method GetAgentTypeInstance
|
|
72
|
+
* @param {AIAgentTypeEntity} agentType - The agent type entity to instantiate
|
|
73
|
+
*
|
|
74
|
+
* @returns {Promise<BaseAgentType>} An instance of the agent type class
|
|
75
|
+
*
|
|
76
|
+
* @throws {Error} If the agent type does not have a DriverClass specified or if instantiation fails
|
|
77
|
+
* @param agentType
|
|
78
|
+
* @returns
|
|
79
|
+
*/
|
|
10
80
|
static async GetAgentTypeInstance(agentType) {
|
|
11
81
|
try {
|
|
12
82
|
const agentTypeInstance = await this.getAgentTypeInstance(agentType);
|
|
13
83
|
return agentTypeInstance;
|
|
14
84
|
}
|
|
15
85
|
catch (error) {
|
|
16
|
-
|
|
86
|
+
LogError(error);
|
|
17
87
|
throw new Error(`Failed to get agent type instance for ${agentType.Name}: ${error.message}`);
|
|
18
88
|
}
|
|
19
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Instantiates the appropriate agent type class based on the agent type entity.
|
|
92
|
+
*
|
|
93
|
+
* This method uses the MemberJunction class factory to dynamically instantiate
|
|
94
|
+
* agent type classes. It uses the DriverClass field. If DriverClass is not specified
|
|
95
|
+
* it throws an error.
|
|
96
|
+
*
|
|
97
|
+
* @param {AIAgentTypeEntity} agentType - The agent type entity to instantiate
|
|
98
|
+
*
|
|
99
|
+
* @returns {Promise<BaseAgentType | null>} Instance of the agent type class
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* // For an agent type with DriverClass "LoopAgentType"
|
|
103
|
+
* const agentTypeInstance = await this.getAgentTypeInstance(loopAgentType);
|
|
104
|
+
*
|
|
105
|
+
* @protected
|
|
106
|
+
*/
|
|
20
107
|
static async getAgentTypeInstance(agentType) {
|
|
108
|
+
// Use DriverClass
|
|
21
109
|
if (!agentType.DriverClass) {
|
|
22
110
|
throw new Error(`Agent type '${agentType.Name}' does not have a DriverClass specified. Please ensure the agent type is properly configured.`);
|
|
23
111
|
}
|
|
112
|
+
// Create an instance of the agent type using the DriverClass
|
|
24
113
|
return this.getAgentInstanceWithDriverClass(agentType.DriverClass);
|
|
25
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Instantiates an agent type class using a specific driver class name.
|
|
117
|
+
*
|
|
118
|
+
* This method is used when an individual agent has its own DriverClass override,
|
|
119
|
+
* allowing for specialized implementations per agent instance.
|
|
120
|
+
*
|
|
121
|
+
* @param {string} driverClass - The driver class name to instantiate
|
|
122
|
+
*
|
|
123
|
+
* @returns {Promise<BaseAgentType | null>} Instance of the agent type class
|
|
124
|
+
*
|
|
125
|
+
* @protected
|
|
126
|
+
*/
|
|
26
127
|
static async getAgentInstanceWithDriverClass(driverClass) {
|
|
27
|
-
const instance =
|
|
128
|
+
const instance = MJGlobal.Instance.ClassFactory.CreateInstance(BaseAgentType, driverClass);
|
|
28
129
|
if (!instance) {
|
|
29
130
|
throw new Error(`No implementation found for agent with DriverClass '${driverClass}'. Please ensure the class is registered with the ClassFactory.`);
|
|
30
131
|
}
|
|
132
|
+
// now check to make sure that the instance is NOT the base class BaseAgentType as that is not valid
|
|
31
133
|
if (instance.constructor === BaseAgentType) {
|
|
32
134
|
throw new Error(`The DriverClass '${driverClass}' is not a valid agent type implementation. It must extend BaseAgentType.`);
|
|
33
135
|
}
|
|
34
136
|
return instance;
|
|
35
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Parses JSON response from prompt execution with automatic validation syntax cleaning
|
|
140
|
+
*
|
|
141
|
+
* @template T The expected response type
|
|
142
|
+
* @param {AIPromptRunResult} promptResult - The prompt execution result
|
|
143
|
+
*
|
|
144
|
+
* @returns {T | null} Parsed response or null if parsing fails
|
|
145
|
+
*
|
|
146
|
+
* @protected
|
|
147
|
+
*/
|
|
36
148
|
parseJSONResponse(promptResult) {
|
|
37
149
|
if (!promptResult.success || !promptResult.result) {
|
|
38
150
|
return null;
|
|
@@ -45,17 +157,29 @@ class BaseAgentType {
|
|
|
45
157
|
else {
|
|
46
158
|
response = promptResult.result;
|
|
47
159
|
}
|
|
160
|
+
// Clean validation syntax from the response
|
|
48
161
|
response = this._jsonValidator.cleanValidationSyntax(response);
|
|
49
|
-
if (
|
|
162
|
+
if (IsVerboseLoggingEnabled()) {
|
|
50
163
|
console.log(`${this.constructor.name}: Cleaned response from validation syntax`, response);
|
|
51
164
|
}
|
|
52
165
|
return response;
|
|
53
166
|
}
|
|
54
167
|
catch (error) {
|
|
55
|
-
|
|
168
|
+
LogError(`Failed to parse JSON response in ${this.constructor.name}: ${error.message}`);
|
|
56
169
|
return null;
|
|
57
170
|
}
|
|
58
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Creates a standardized next step object with common defaults
|
|
174
|
+
*
|
|
175
|
+
* @template P The payload type
|
|
176
|
+
* @param {BaseAgentNextStep['step']} step - The step type
|
|
177
|
+
* @param {Partial<BaseAgentNextStep<P>>} options - Additional options to merge
|
|
178
|
+
*
|
|
179
|
+
* @returns {BaseAgentNextStep<P>} The next step object
|
|
180
|
+
*
|
|
181
|
+
* @protected
|
|
182
|
+
*/
|
|
59
183
|
createNextStep(step, options = {}) {
|
|
60
184
|
return {
|
|
61
185
|
step,
|
|
@@ -63,6 +187,17 @@ class BaseAgentType {
|
|
|
63
187
|
...options
|
|
64
188
|
};
|
|
65
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Creates a retry step with a standardized error message
|
|
192
|
+
*
|
|
193
|
+
* @template P The payload type
|
|
194
|
+
* @param {string} errorMessage - The error message
|
|
195
|
+
* @param {Partial<BaseAgentNextStep<P>>} options - Additional options
|
|
196
|
+
*
|
|
197
|
+
* @returns {BaseAgentNextStep<P>} Retry step
|
|
198
|
+
*
|
|
199
|
+
* @protected
|
|
200
|
+
*/
|
|
66
201
|
createRetryStep(errorMessage, options = {}) {
|
|
67
202
|
return this.createNextStep('Retry', {
|
|
68
203
|
errorMessage,
|
|
@@ -70,40 +205,176 @@ class BaseAgentType {
|
|
|
70
205
|
...options
|
|
71
206
|
});
|
|
72
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* Creates a success step with optional payload changes
|
|
210
|
+
*
|
|
211
|
+
* @template P The payload type
|
|
212
|
+
* @param {Partial<BaseAgentNextStep<P>>} options - Success options
|
|
213
|
+
*
|
|
214
|
+
* @returns {BaseAgentNextStep<P>} Success step
|
|
215
|
+
*
|
|
216
|
+
* @protected
|
|
217
|
+
*/
|
|
73
218
|
createSuccessStep(options = {}) {
|
|
74
219
|
return this.createNextStep('Success', {
|
|
75
220
|
terminate: true,
|
|
76
221
|
...options
|
|
77
222
|
});
|
|
78
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* Pre-processes an action step before execution.
|
|
226
|
+
*
|
|
227
|
+
* This method is called by BaseAgent before action(s) are executed.
|
|
228
|
+
* Agent types can override this method to perform custom pre-processing,
|
|
229
|
+
* such as mapping payload values to action input parameters or modifying action configurations.
|
|
230
|
+
*
|
|
231
|
+
* @param {AgentAction[]} actions - The actions that will be executed (can be modified)
|
|
232
|
+
* @param {P} currentPayload - The current payload
|
|
233
|
+
* @param {BaseAgentNextStep<P>} currentStep - The current step being executed
|
|
234
|
+
*
|
|
235
|
+
* @returns {Promise<void>} Actions are modified in place
|
|
236
|
+
*
|
|
237
|
+
* @since 2.76.0
|
|
238
|
+
*/
|
|
79
239
|
async PreProcessActionStep(actions, currentPayload, agentTypeState, currentStep, params) {
|
|
240
|
+
// Default implementation does nothing
|
|
241
|
+
// Subclasses can override to implement custom logic
|
|
80
242
|
}
|
|
243
|
+
/**
|
|
244
|
+
* Post-processes the result of action execution.
|
|
245
|
+
*
|
|
246
|
+
* This method is called by BaseAgent after action(s) have been executed.
|
|
247
|
+
* Agent types can override this method to perform custom processing of action results,
|
|
248
|
+
* such as mapping output parameters to the payload or storing results in agent-specific context.
|
|
249
|
+
*
|
|
250
|
+
* @param {ActionResult[]} actionResults - The results from action execution
|
|
251
|
+
* @param {AgentAction[]} actions - The actions that were executed
|
|
252
|
+
* @param {P} currentPayload - The current payload
|
|
253
|
+
* @param {BaseAgentNextStep<P>} currentStep - The current step being executed
|
|
254
|
+
*
|
|
255
|
+
* @returns {Promise<AgentPayloadChangeRequest<P> | null>} Optional payload change request
|
|
256
|
+
*
|
|
257
|
+
* @since 2.76.0
|
|
258
|
+
*/
|
|
81
259
|
async PostProcessActionStep(actionResults, actions, currentPayload, agentTypeState, currentStep) {
|
|
260
|
+
// Default implementation does nothing
|
|
261
|
+
// Subclasses can override to implement custom logic
|
|
82
262
|
return null;
|
|
83
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* Post-processes the result of sub-agent execution.
|
|
266
|
+
*
|
|
267
|
+
* This method is called by BaseAgent after a sub-agent has been executed.
|
|
268
|
+
* Agent types can override this method to perform custom processing of sub-agent results,
|
|
269
|
+
* such as extracting specific data from the sub-agent's payload or updating context.
|
|
270
|
+
*
|
|
271
|
+
* @param {any} subAgentResult - The result from sub-agent execution
|
|
272
|
+
* @param {AgentSubAgentRequest} subAgentRequest - The sub-agent request that was executed
|
|
273
|
+
* @param {P} currentPayload - The current payload
|
|
274
|
+
* @param {BaseAgentNextStep<P>} currentStep - The current step being executed
|
|
275
|
+
*
|
|
276
|
+
* @returns {Promise<AgentPayloadChangeRequest<P> | null>} Optional payload change request
|
|
277
|
+
*
|
|
278
|
+
* @since 2.76.0
|
|
279
|
+
*/
|
|
84
280
|
async PostProcessSubAgentStep(subAgentResult, subAgentRequest, currentPayload, agentTypeState, currentStep) {
|
|
281
|
+
// Default implementation does nothing
|
|
282
|
+
// Subclasses can override to implement custom logic
|
|
85
283
|
return null;
|
|
86
284
|
}
|
|
285
|
+
/**
|
|
286
|
+
* Indicates whether this agent type requires agent-level prompts (AI Agent Prompts relationship).
|
|
287
|
+
*
|
|
288
|
+
* Some agent types (like Flow) use step-level prompts exclusively and don't need agent-level prompts.
|
|
289
|
+
* Other agent types (like Loop) require agent-level prompts for their main reasoning loop.
|
|
290
|
+
*
|
|
291
|
+
* Default: true (most agent types require agent-level prompts)
|
|
292
|
+
*
|
|
293
|
+
* @returns {boolean} True if agent-level prompts are required, false if optional
|
|
294
|
+
* @since 2.113.0
|
|
295
|
+
*/
|
|
87
296
|
get RequiresAgentLevelPrompts() {
|
|
88
|
-
return true;
|
|
297
|
+
return true; // Default: agent-level prompts are required
|
|
89
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* Provides agent-type-specific guidance for configuration errors related to missing prompts.
|
|
301
|
+
* This allows each agent type to give contextual help based on its architecture.
|
|
302
|
+
*
|
|
303
|
+
* Default implementation provides generic guidance. Agent types should override to provide
|
|
304
|
+
* specific instructions relevant to their configuration requirements.
|
|
305
|
+
*
|
|
306
|
+
* @returns {string} Configuration guidance specific to this agent type
|
|
307
|
+
* @since 2.113.0
|
|
308
|
+
*/
|
|
90
309
|
GetPromptConfigurationGuidance() {
|
|
91
310
|
return ` - Ensure agent has AI Agent Prompts relationship configured\n` +
|
|
92
311
|
` - Verify that prompt exists in AI Prompts table and is active`;
|
|
93
312
|
}
|
|
313
|
+
/**
|
|
314
|
+
* Determines how to handle Success or Failed steps when no explicit termination is requested.
|
|
315
|
+
*
|
|
316
|
+
* This allows agent types to control their own fallback behavior:
|
|
317
|
+
* - Loop agents use default behavior (return null) to process results with their main prompt
|
|
318
|
+
* - Flow agents should terminate instead of falling back to prompts (return terminate step)
|
|
319
|
+
* - Pipeline agents might want to move to the next stage
|
|
320
|
+
*
|
|
321
|
+
* Default implementation returns null, which causes base-agent to fall back to prompt execution
|
|
322
|
+
* if prompts are configured. Agent types can override this to provide custom behavior.
|
|
323
|
+
*
|
|
324
|
+
* @param {BaseAgentNextStep<P>} step - The Success or Failed step that needs fallback handling
|
|
325
|
+
* @param {AgentConfiguration} config - The loaded agent configuration
|
|
326
|
+
* @param {ExecuteAgentParams} params - The execution parameters
|
|
327
|
+
* @param {P} payload - The current payload
|
|
328
|
+
* @param {ATS} agentTypeState - Agent type's state
|
|
329
|
+
* @returns {Promise<BaseAgentNextStep<P> | null>} Custom step to execute, or null for default behavior
|
|
330
|
+
*
|
|
331
|
+
* @since 2.113.0
|
|
332
|
+
*/
|
|
94
333
|
async HandleStepFallback(step, config, params, payload, agentTypeState) {
|
|
334
|
+
// Default implementation: return null to use base-agent's default behavior
|
|
335
|
+
// (fall back to prompt execution if prompts are configured)
|
|
95
336
|
return null;
|
|
96
337
|
}
|
|
338
|
+
/**
|
|
339
|
+
* Determines if loop results should be injected as a temporary user message
|
|
340
|
+
* before the next prompt execution (for LLM reasoning).
|
|
341
|
+
*
|
|
342
|
+
* Default: true (most agent types benefit from seeing loop results)
|
|
343
|
+
* Flow agents override to false (deterministic path navigation, no LLM)
|
|
344
|
+
*
|
|
345
|
+
* @returns true to inject results as message, false to skip
|
|
346
|
+
* @since 2.112.0
|
|
347
|
+
*/
|
|
97
348
|
get InjectLoopResultsAsMessage() {
|
|
98
|
-
return true;
|
|
349
|
+
return true; // Default: Inject results for LLM reasoning
|
|
99
350
|
}
|
|
351
|
+
/**
|
|
352
|
+
* Called before each loop iteration to prepare parameters and payload.
|
|
353
|
+
*
|
|
354
|
+
* Loop agents use this to resolve template variables ("item.email").
|
|
355
|
+
* Flow agents typically don't need this (params already resolved).
|
|
356
|
+
*
|
|
357
|
+
* @param context - Current iteration context
|
|
358
|
+
* @param agentTypeState - Agent type's state
|
|
359
|
+
* @returns Modified context or null for default behavior
|
|
360
|
+
* @since 2.112.0
|
|
361
|
+
*/
|
|
100
362
|
BeforeLoopIteration(context) {
|
|
101
|
-
return null;
|
|
363
|
+
return null; // Default: No transformation
|
|
102
364
|
}
|
|
365
|
+
/**
|
|
366
|
+
* Called after each loop iteration completes to process results.
|
|
367
|
+
*
|
|
368
|
+
* Flow agents use this to apply ActionOutputMapping and update payload.
|
|
369
|
+
* Loop agents typically don't need this (just collect results).
|
|
370
|
+
*
|
|
371
|
+
* @param iterationResult - Results from this iteration
|
|
372
|
+
* @param agentTypeState - Agent type's state
|
|
373
|
+
* @returns Modified payload or null for default behavior (just collect result)
|
|
374
|
+
* @since 2.112.0
|
|
375
|
+
*/
|
|
103
376
|
AfterLoopIteration(iterationResult) {
|
|
104
|
-
return null;
|
|
377
|
+
return null; // Default: No transformation
|
|
105
378
|
}
|
|
106
379
|
}
|
|
107
|
-
exports.BaseAgentType = BaseAgentType;
|
|
108
|
-
BaseAgentType.CURRENT_PAYLOAD_PLACEHOLDER = '_CURRENT_PAYLOAD';
|
|
109
380
|
//# sourceMappingURL=base-agent-type.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-agent-type.js","sourceRoot":"","sources":["../../src/agent-types/base-agent-type.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base-agent-type.js","sourceRoot":"","sources":["../../src/agent-types/base-agent-type.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAGzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,OAAgB,aAAa;IAAnC;QACI;;;WAGG;QACO,mBAAc,GAAkB,IAAI,aAAa,EAAE,CAAC;IAohBlE,CAAC;IAlhBG;;;OAGG;aACoB,gCAA2B,GAAG,kBAAkB,AAArB,CAAsB;IAoIxE;;;;;;;;;;;;;;;;;OAiBG;IACI,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,SAA4B;QACjE,IAAI,CAAC;YACD,MAAM,iBAAiB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