@memberjunction/ai-agents 2.117.0 → 2.119.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 +409 -3
- package/dist/AgentRunner.d.ts +31 -0
- package/dist/AgentRunner.d.ts.map +1 -1
- package/dist/AgentRunner.js +358 -0
- package/dist/AgentRunner.js.map +1 -1
- package/dist/agent-types/flow-agent-type.d.ts +5 -0
- package/dist/agent-types/flow-agent-type.d.ts.map +1 -1
- package/dist/agent-types/flow-agent-type.js +57 -22
- package/dist/agent-types/flow-agent-type.js.map +1 -1
- package/dist/agent-types/loop-agent-response-type.d.ts +4 -2
- package/dist/agent-types/loop-agent-response-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-type.d.ts +3 -1
- package/dist/agent-types/loop-agent-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-type.js +39 -3
- package/dist/agent-types/loop-agent-type.js.map +1 -1
- package/dist/base-agent.d.ts +7 -2
- package/dist/base-agent.d.ts.map +1 -1
- package/dist/base-agent.js +127 -40
- package/dist/base-agent.js.map +1 -1
- package/dist/utils/ConversationMessageResolver.d.ts +9 -0
- package/dist/utils/ConversationMessageResolver.d.ts.map +1 -0
- package/dist/utils/ConversationMessageResolver.js +112 -0
- package/dist/utils/ConversationMessageResolver.js.map +1 -0
- package/package.json +10 -10
package/dist/base-agent.js
CHANGED
|
@@ -36,6 +36,7 @@ const ai_core_plus_1 = require("@memberjunction/ai-core-plus");
|
|
|
36
36
|
const AgentRunner_1 = require("./AgentRunner");
|
|
37
37
|
const PayloadManager_1 = require("./PayloadManager");
|
|
38
38
|
const AgentDataPreloader_1 = require("./AgentDataPreloader");
|
|
39
|
+
const ConversationMessageResolver_1 = require("./utils/ConversationMessageResolver");
|
|
39
40
|
const _ = __importStar(require("lodash"));
|
|
40
41
|
class BaseAgent {
|
|
41
42
|
constructor() {
|
|
@@ -48,6 +49,7 @@ class BaseAgent {
|
|
|
48
49
|
this._agentHierarchy = [];
|
|
49
50
|
this._iterationContext = null;
|
|
50
51
|
this._depth = 0;
|
|
52
|
+
this._parentStepCounts = [];
|
|
51
53
|
this._allProgressSteps = [];
|
|
52
54
|
this._subAgentRuns = [];
|
|
53
55
|
this._payloadManager = new PayloadManager_1.PayloadManager();
|
|
@@ -66,6 +68,18 @@ class BaseAgent {
|
|
|
66
68
|
get AgentRun() {
|
|
67
69
|
return this._agentRun;
|
|
68
70
|
}
|
|
71
|
+
GetConfigurationPresets(agentId) {
|
|
72
|
+
if (!agentId) {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
return aiengine_1.AIEngine.Instance.GetAgentConfigurationPresets(agentId);
|
|
76
|
+
}
|
|
77
|
+
GetDefaultConfigurationPreset(agentId) {
|
|
78
|
+
if (!agentId) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
return aiengine_1.AIEngine.Instance.GetDefaultAgentConfigurationPreset(agentId);
|
|
82
|
+
}
|
|
69
83
|
get ValidationRetryCount() {
|
|
70
84
|
return this._validationRetryCount;
|
|
71
85
|
}
|
|
@@ -107,18 +121,22 @@ class BaseAgent {
|
|
|
107
121
|
if (!originalCallback)
|
|
108
122
|
return undefined;
|
|
109
123
|
return (progress) => {
|
|
124
|
+
const hierarchicalStep = progress.metadata?.hierarchicalStep
|
|
125
|
+
?? this.buildHierarchicalStep(progress.metadata?.stepCount, this._parentStepCounts);
|
|
110
126
|
this._allProgressSteps.push({
|
|
111
127
|
...progress,
|
|
112
128
|
timestamp: new Date(),
|
|
113
129
|
agentHierarchy: this._agentHierarchy || [],
|
|
114
|
-
depth: this._depth || 0
|
|
130
|
+
depth: this._depth || 0,
|
|
131
|
+
hierarchicalStep
|
|
115
132
|
});
|
|
116
133
|
try {
|
|
117
134
|
const enhancedProgress = {
|
|
118
135
|
...progress,
|
|
119
136
|
metadata: {
|
|
120
137
|
...progress.metadata,
|
|
121
|
-
agentRun: this._agentRun
|
|
138
|
+
agentRun: this._agentRun,
|
|
139
|
+
hierarchicalStep
|
|
122
140
|
}
|
|
123
141
|
};
|
|
124
142
|
originalCallback(enhancedProgress);
|
|
@@ -199,6 +217,9 @@ class BaseAgent {
|
|
|
199
217
|
...params,
|
|
200
218
|
onProgress: this.wrapProgressCallback(params.onProgress)
|
|
201
219
|
};
|
|
220
|
+
if (params.convertUIMarkupToPlainText !== false) {
|
|
221
|
+
this.convertUIMarkupInMessages(wrappedParams.conversationMessages);
|
|
222
|
+
}
|
|
202
223
|
await this.initializeStartingPayload(wrappedParams);
|
|
203
224
|
if (params.cancellationToken?.aborted) {
|
|
204
225
|
this.logStatus(`⚠️ Agent '${params.agent.Name}' execution cancelled before start`, true, params);
|
|
@@ -206,8 +227,11 @@ class BaseAgent {
|
|
|
206
227
|
}
|
|
207
228
|
wrappedParams.onProgress?.({
|
|
208
229
|
step: 'initialization',
|
|
209
|
-
|
|
210
|
-
|
|
230
|
+
message: this.formatHierarchicalMessage(`Initializing ${params.agent.Name} agent and preparing execution environment`),
|
|
231
|
+
metadata: {
|
|
232
|
+
stepCount: 0,
|
|
233
|
+
hierarchicalStep: this.buildHierarchicalStep(0, this._parentStepCounts)
|
|
234
|
+
}
|
|
211
235
|
});
|
|
212
236
|
await this.initializeAgentRun(wrappedParams);
|
|
213
237
|
this._validationRetryCount = 0;
|
|
@@ -224,8 +248,11 @@ class BaseAgent {
|
|
|
224
248
|
}
|
|
225
249
|
wrappedParams.onProgress?.({
|
|
226
250
|
step: 'validation',
|
|
227
|
-
|
|
228
|
-
|
|
251
|
+
message: this.formatHierarchicalMessage('Validating agent configuration and loading prompts'),
|
|
252
|
+
metadata: {
|
|
253
|
+
stepCount: 0,
|
|
254
|
+
hierarchicalStep: this.buildHierarchicalStep(0, this._parentStepCounts)
|
|
255
|
+
}
|
|
229
256
|
});
|
|
230
257
|
const validationResult = await this.validateAgentWithTracking(params.agent, params.contextUser);
|
|
231
258
|
if (validationResult)
|
|
@@ -252,8 +279,11 @@ class BaseAgent {
|
|
|
252
279
|
const executionResult = await this.executeAgentInternal(wrappedParams, config);
|
|
253
280
|
wrappedParams.onProgress?.({
|
|
254
281
|
step: 'finalization',
|
|
255
|
-
|
|
256
|
-
|
|
282
|
+
metadata: {
|
|
283
|
+
result: executionResult,
|
|
284
|
+
stepCount: executionResult.stepCount,
|
|
285
|
+
hierarchicalStep: this.buildHierarchicalStep(executionResult.stepCount, this._parentStepCounts)
|
|
286
|
+
},
|
|
257
287
|
message: this.formatHierarchicalMessage('Finalizing agent execution')
|
|
258
288
|
});
|
|
259
289
|
this.logStatus(`✅ Finalizing execution for agent '${params.agent.Name}'`, true, params);
|
|
@@ -285,7 +315,7 @@ class BaseAgent {
|
|
|
285
315
|
}
|
|
286
316
|
await this.pruneAndCompactExpiredMessages(params, stepCount);
|
|
287
317
|
this.logStatus(`🔄 Executing step ${stepCount + 1} for agent '${params.agent.Name}'`, true, params);
|
|
288
|
-
const nextStep = await this.executeNextStep(params, config, currentNextStep);
|
|
318
|
+
const nextStep = await this.executeNextStep(params, config, currentNextStep, stepCount);
|
|
289
319
|
stepCount++;
|
|
290
320
|
if (nextStep.terminate) {
|
|
291
321
|
continueExecution = false;
|
|
@@ -353,6 +383,26 @@ class BaseAgent {
|
|
|
353
383
|
this._injectedMemory = { notes, examples };
|
|
354
384
|
return { notes, examples };
|
|
355
385
|
}
|
|
386
|
+
convertUIMarkupInMessages(messages) {
|
|
387
|
+
if (!messages || messages.length === 0) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
for (const message of messages) {
|
|
391
|
+
if (message.role !== 'user') {
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
if (typeof message.content === 'string') {
|
|
395
|
+
message.content = ai_core_plus_1.ConversationUtility.ToPlainText(message.content);
|
|
396
|
+
}
|
|
397
|
+
else if (Array.isArray(message.content)) {
|
|
398
|
+
for (const block of message.content) {
|
|
399
|
+
if (block.type === 'text' && typeof block.content === 'string') {
|
|
400
|
+
block.content = ai_core_plus_1.ConversationUtility.ToPlainText(block.content);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
356
406
|
async validateRunChain(lastRunId, contextUser) {
|
|
357
407
|
const visitedRunIds = new Set();
|
|
358
408
|
visitedRunIds.add(this._agentRun.ID);
|
|
@@ -1672,7 +1722,7 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
1672
1722
|
}
|
|
1673
1723
|
return messages;
|
|
1674
1724
|
}
|
|
1675
|
-
async ExecuteSubAgent(params, subAgentRequest, subAgent, stepEntity, payload, contextMessage) {
|
|
1725
|
+
async ExecuteSubAgent(params, subAgentRequest, subAgent, stepEntity, payload, contextMessage, stepCount = 0) {
|
|
1676
1726
|
try {
|
|
1677
1727
|
this.logStatus(`🤖 Executing sub-agent '${subAgentRequest.name}'`, true, params);
|
|
1678
1728
|
const runner = new AgentRunner_1.AgentRunner();
|
|
@@ -1684,6 +1734,7 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
1684
1734
|
if (params.effortLevel !== undefined && params.effortLevel !== null) {
|
|
1685
1735
|
this.logStatus(`🎯 Propagating effort level ${params.effortLevel} to sub-agent '${subAgentRequest.name}'`, true, params);
|
|
1686
1736
|
}
|
|
1737
|
+
const parentStepCountsToPass = [...this._parentStepCounts, stepCount + 1];
|
|
1687
1738
|
const result = await runner.RunAgent({
|
|
1688
1739
|
agent: subAgent,
|
|
1689
1740
|
conversationMessages: subAgentMessages,
|
|
@@ -1693,6 +1744,7 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
1693
1744
|
onStreaming: params.onStreaming,
|
|
1694
1745
|
parentAgentHierarchy: this._agentHierarchy,
|
|
1695
1746
|
parentDepth: this._depth,
|
|
1747
|
+
parentStepCounts: parentStepCountsToPass,
|
|
1696
1748
|
parentRun: this._agentRun,
|
|
1697
1749
|
payload: payload,
|
|
1698
1750
|
configurationId: params.configurationId,
|
|
@@ -1889,6 +1941,9 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
1889
1941
|
this._agentRun.Data = JSON.stringify(params.data);
|
|
1890
1942
|
}
|
|
1891
1943
|
this._agentRun.Verbose = params.verbose || false;
|
|
1944
|
+
if (params.testRunId) {
|
|
1945
|
+
this._agentRun.TestRunID = params.testRunId;
|
|
1946
|
+
}
|
|
1892
1947
|
if (!await this._agentRun.Save()) {
|
|
1893
1948
|
const errorMessage = JSON.stringify((0, global_1.CopyScalarsAndArrays)(this._agentRun.LatestResult));
|
|
1894
1949
|
throw new Error(`Failed to create agent run record: Details: ${errorMessage}`);
|
|
@@ -1905,6 +1960,7 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
1905
1960
|
? [...params.parentAgentHierarchy, params.agent.Name || 'Unknown Agent']
|
|
1906
1961
|
: [params.agent.Name || 'Unknown Agent'];
|
|
1907
1962
|
this._depth = params.parentDepth !== undefined ? params.parentDepth + 1 : 0;
|
|
1963
|
+
this._parentStepCounts = params.parentStepCounts || [];
|
|
1908
1964
|
this._allProgressSteps = [];
|
|
1909
1965
|
if (modifiedParams !== params && modifiedParams.payload !== undefined) {
|
|
1910
1966
|
params.payload = modifiedParams.payload;
|
|
@@ -2052,6 +2108,14 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
2052
2108
|
}
|
|
2053
2109
|
return baseMessage;
|
|
2054
2110
|
}
|
|
2111
|
+
buildHierarchicalStep(currentStep, parentSteps) {
|
|
2112
|
+
if (currentStep == null)
|
|
2113
|
+
return undefined;
|
|
2114
|
+
if (parentSteps.length === 0) {
|
|
2115
|
+
return currentStep.toString();
|
|
2116
|
+
}
|
|
2117
|
+
return [...parentSteps, currentStep].join('.');
|
|
2118
|
+
}
|
|
2055
2119
|
getNextStepReasoning(nextStep) {
|
|
2056
2120
|
switch (nextStep.step) {
|
|
2057
2121
|
case 'Failed':
|
|
@@ -2062,13 +2126,13 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
2062
2126
|
return nextStep.reasoning || 'Continuing to next step';
|
|
2063
2127
|
}
|
|
2064
2128
|
}
|
|
2065
|
-
async executeNextStep(params, config, previousDecision) {
|
|
2129
|
+
async executeNextStep(params, config, previousDecision, stepCount = 0) {
|
|
2066
2130
|
if (!previousDecision) {
|
|
2067
2131
|
const initialStep = await this.AgentTypeInstance.DetermineInitialStep(params, params.payload, this.AgentTypeState);
|
|
2068
2132
|
if (initialStep) {
|
|
2069
2133
|
return initialStep;
|
|
2070
2134
|
}
|
|
2071
|
-
return await this.executePromptStep(params, config);
|
|
2135
|
+
return await this.executePromptStep(params, config, undefined, stepCount);
|
|
2072
2136
|
}
|
|
2073
2137
|
const customNextStep = await this.AgentTypeInstance.PreProcessNextStep(params, previousDecision, previousDecision.newPayload || previousDecision.previousPayload, this.AgentTypeState);
|
|
2074
2138
|
if (customNextStep) {
|
|
@@ -2080,11 +2144,11 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
2080
2144
|
const currentStepCount = this._agentRun?.Steps?.length || 0;
|
|
2081
2145
|
this.executeExpandMessageStep(previousDecision, params, currentStepCount);
|
|
2082
2146
|
}
|
|
2083
|
-
return await this.executePromptStep(params, config, previousDecision);
|
|
2147
|
+
return await this.executePromptStep(params, config, previousDecision, stepCount);
|
|
2084
2148
|
case 'Sub-Agent':
|
|
2085
|
-
return await this.processSubAgentStep(params, previousDecision);
|
|
2149
|
+
return await this.processSubAgentStep(params, previousDecision, undefined, undefined, stepCount);
|
|
2086
2150
|
case 'Actions':
|
|
2087
|
-
return await this.executeActionsStep(params, previousDecision, undefined);
|
|
2151
|
+
return await this.executeActionsStep(params, previousDecision, undefined, true, stepCount);
|
|
2088
2152
|
case 'Chat':
|
|
2089
2153
|
return await this.executeChatStep(params, previousDecision);
|
|
2090
2154
|
case 'Success':
|
|
@@ -2117,7 +2181,7 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
2117
2181
|
return fallbackStep;
|
|
2118
2182
|
}
|
|
2119
2183
|
else {
|
|
2120
|
-
return await this.executePromptStep(params, config, previousDecision);
|
|
2184
|
+
return await this.executePromptStep(params, config, previousDecision, stepCount);
|
|
2121
2185
|
}
|
|
2122
2186
|
}
|
|
2123
2187
|
case 'Failed':
|
|
@@ -2163,7 +2227,7 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
2163
2227
|
return fallbackStep;
|
|
2164
2228
|
}
|
|
2165
2229
|
else {
|
|
2166
|
-
return await this.executePromptStep(params, config, previousDecision);
|
|
2230
|
+
return await this.executePromptStep(params, config, previousDecision, stepCount);
|
|
2167
2231
|
}
|
|
2168
2232
|
}
|
|
2169
2233
|
case 'ForEach':
|
|
@@ -2177,7 +2241,7 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
2177
2241
|
getDefaultPayloadSelfWritePaths() {
|
|
2178
2242
|
return undefined;
|
|
2179
2243
|
}
|
|
2180
|
-
async executePromptStep(params, config, previousDecision) {
|
|
2244
|
+
async executePromptStep(params, config, previousDecision, stepCount = 0) {
|
|
2181
2245
|
const promptToUse = await this.AgentTypeInstance.GetPromptForStep(params, config, previousDecision?.newPayload || previousDecision?.previousPayload, this.AgentTypeState, previousDecision);
|
|
2182
2246
|
const promptId = promptToUse?.ID;
|
|
2183
2247
|
const promptName = promptToUse?.Name;
|
|
@@ -2198,14 +2262,16 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
2198
2262
|
const promptMessage = isRetry
|
|
2199
2263
|
? `Running ${params.agent.Name} with context from ${previousDecision.retryReason || 'previous actions'}`
|
|
2200
2264
|
: `Running ${params.agent.Name}'s initial prompt...`;
|
|
2265
|
+
const hierarchicalStepToEmit = this.buildHierarchicalStep(stepCount + 1, this._parentStepCounts);
|
|
2201
2266
|
params.onProgress?.({
|
|
2202
2267
|
step: 'prompt_execution',
|
|
2203
|
-
percentage: 30,
|
|
2204
2268
|
message: this.formatHierarchicalMessage(promptMessage),
|
|
2205
2269
|
metadata: {
|
|
2206
2270
|
promptId: promptId,
|
|
2207
2271
|
isRetry,
|
|
2208
|
-
promptName: promptName
|
|
2272
|
+
promptName: promptName,
|
|
2273
|
+
stepCount: stepCount + 1,
|
|
2274
|
+
hierarchicalStep: hierarchicalStepToEmit
|
|
2209
2275
|
},
|
|
2210
2276
|
displayMode: 'live'
|
|
2211
2277
|
});
|
|
@@ -2279,8 +2345,11 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
2279
2345
|
}
|
|
2280
2346
|
params.onProgress?.({
|
|
2281
2347
|
step: 'decision_processing',
|
|
2282
|
-
percentage: 70,
|
|
2283
2348
|
message: this.formatHierarchicalMessage('Analyzing response and determining next steps'),
|
|
2349
|
+
metadata: {
|
|
2350
|
+
stepCount: stepCount + 1,
|
|
2351
|
+
hierarchicalStep: this.buildHierarchicalStep(stepCount + 1, this._parentStepCounts)
|
|
2352
|
+
},
|
|
2284
2353
|
displayMode: 'both'
|
|
2285
2354
|
});
|
|
2286
2355
|
const initialNextStep = await this.determineNextStep(params, config.agentType, promptResult, payload);
|
|
@@ -2438,19 +2507,20 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
2438
2507
|
}
|
|
2439
2508
|
return scopedPayload;
|
|
2440
2509
|
}
|
|
2441
|
-
async executeChildSubAgentStep(params, previousDecision, parentStepId, subAgentPayloadOverride) {
|
|
2510
|
+
async executeChildSubAgentStep(params, previousDecision, parentStepId, subAgentPayloadOverride, stepCount = 0) {
|
|
2442
2511
|
const subAgentRequest = previousDecision.subAgent;
|
|
2443
2512
|
if (params.cancellationToken?.aborted) {
|
|
2444
2513
|
throw new Error('Cancelled before sub-agent execution');
|
|
2445
2514
|
}
|
|
2446
2515
|
params.onProgress?.({
|
|
2447
2516
|
step: 'subagent_execution',
|
|
2448
|
-
percentage: 60,
|
|
2449
2517
|
message: this.formatHierarchicalMessage(`Delegating to ${subAgentRequest.name} agent`),
|
|
2450
2518
|
metadata: {
|
|
2451
2519
|
agentName: params.agent.Name,
|
|
2452
2520
|
subAgentName: subAgentRequest.name,
|
|
2453
|
-
reason: subAgentRequest.message
|
|
2521
|
+
reason: subAgentRequest.message,
|
|
2522
|
+
stepCount: stepCount + 1,
|
|
2523
|
+
hierarchicalStep: this.buildHierarchicalStep(stepCount + 1, this._parentStepCounts)
|
|
2454
2524
|
}
|
|
2455
2525
|
});
|
|
2456
2526
|
params.conversationMessages.push({
|
|
@@ -2482,7 +2552,7 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
2482
2552
|
scopedPayload = subAgentPayloadOverride;
|
|
2483
2553
|
}
|
|
2484
2554
|
stepEntity.PayloadAtStart = JSON.stringify(previousDecision.newPayload);
|
|
2485
|
-
const subAgentResult = await this.ExecuteSubAgent(params, subAgentRequest, subAgentEntity, stepEntity, scopedPayload, undefined);
|
|
2555
|
+
const subAgentResult = await this.ExecuteSubAgent(params, subAgentRequest, subAgentEntity, stepEntity, scopedPayload, undefined, stepCount);
|
|
2486
2556
|
let mergedPayload = previousDecision.newPayload;
|
|
2487
2557
|
let currentStepPayloadChangeResult = undefined;
|
|
2488
2558
|
if (subAgentResult.success) {
|
|
@@ -2629,7 +2699,7 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
2629
2699
|
};
|
|
2630
2700
|
}
|
|
2631
2701
|
}
|
|
2632
|
-
async processSubAgentStep(params, previousDecision, parentStepId, subAgentPayloadOverride) {
|
|
2702
|
+
async processSubAgentStep(params, previousDecision, parentStepId, subAgentPayloadOverride, stepCount = 0) {
|
|
2633
2703
|
const subAgentRequest = previousDecision.subAgent;
|
|
2634
2704
|
const name = subAgentRequest?.name;
|
|
2635
2705
|
if (!name) {
|
|
@@ -2645,7 +2715,7 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
2645
2715
|
a.Status === 'Active');
|
|
2646
2716
|
const childAgent = childAgents.find(a => a.Name.trim().toLowerCase() === name.trim().toLowerCase());
|
|
2647
2717
|
if (childAgent) {
|
|
2648
|
-
return await this.executeChildSubAgentStep(params, previousDecision, parentStepId, subAgentPayloadOverride);
|
|
2718
|
+
return await this.executeChildSubAgentStep(params, previousDecision, parentStepId, subAgentPayloadOverride, stepCount);
|
|
2649
2719
|
}
|
|
2650
2720
|
const activeRelationships = aiengine_1.AIEngine.Instance.AgentRelationships.filter(ar => ar.AgentID === params.agent.ID &&
|
|
2651
2721
|
ar.Status === 'Active');
|
|
@@ -2653,7 +2723,7 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
2653
2723
|
const relatedAgent = aiengine_1.AIEngine.Instance.Agents.find(a => a.ID === relationship.SubAgentID &&
|
|
2654
2724
|
a.Status === 'Active');
|
|
2655
2725
|
if (relatedAgent && relatedAgent.Name.trim().toLowerCase() === name.trim().toLowerCase()) {
|
|
2656
|
-
return await this.executeRelatedSubAgentStep(params, previousDecision, relatedAgent, relationship, parentStepId, subAgentPayloadOverride);
|
|
2726
|
+
return await this.executeRelatedSubAgentStep(params, previousDecision, relatedAgent, relationship, parentStepId, subAgentPayloadOverride, stepCount);
|
|
2657
2727
|
}
|
|
2658
2728
|
}
|
|
2659
2729
|
this.logError(`Sub-agent '${name}' not found or not active for agent '${params.agent.Name}'`, {
|
|
@@ -2668,7 +2738,7 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
2668
2738
|
newPayload: previousDecision?.newPayload
|
|
2669
2739
|
};
|
|
2670
2740
|
}
|
|
2671
|
-
async executeRelatedSubAgentStep(params, previousDecision, subAgentEntity, relationship, parentStepId, subAgentPayloadOverride) {
|
|
2741
|
+
async executeRelatedSubAgentStep(params, previousDecision, subAgentEntity, relationship, parentStepId, subAgentPayloadOverride, stepCount = 0) {
|
|
2672
2742
|
const subAgentRequest = previousDecision.subAgent;
|
|
2673
2743
|
if (params.cancellationToken?.aborted) {
|
|
2674
2744
|
throw new Error('Cancelled before related sub-agent execution');
|
|
@@ -2681,7 +2751,9 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
2681
2751
|
agentName: params.agent.Name,
|
|
2682
2752
|
subAgentName: subAgentRequest.name,
|
|
2683
2753
|
reason: subAgentRequest.message,
|
|
2684
|
-
relationshipType: 'related'
|
|
2754
|
+
relationshipType: 'related',
|
|
2755
|
+
stepCount: stepCount + 1,
|
|
2756
|
+
hierarchicalStep: this.buildHierarchicalStep(stepCount + 1, this._parentStepCounts)
|
|
2685
2757
|
}
|
|
2686
2758
|
});
|
|
2687
2759
|
params.conversationMessages.push({
|
|
@@ -2728,11 +2800,11 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
2728
2800
|
(0, core_1.LogError)(`Failed to parse SubAgentContextPaths for sub-agent ${subAgentRequest.name}: ${parseError.message}`);
|
|
2729
2801
|
}
|
|
2730
2802
|
}
|
|
2731
|
-
const contextMessage = this.prepareRelatedSubAgentContextMessage(previousDecision.newPayload, contextPaths);
|
|
2803
|
+
const contextMessage = this.prepareRelatedSubAgentContextMessage(previousDecision.newPayload, contextPaths, params);
|
|
2732
2804
|
if (contextMessage && (params.verbose === true || (0, core_1.IsVerboseLoggingEnabled)())) {
|
|
2733
2805
|
(0, core_1.LogStatus)(`Related sub-agent '${subAgentRequest.name}' receiving context from paths: ${contextPaths.join(', ')}`);
|
|
2734
2806
|
}
|
|
2735
|
-
const subAgentResult = await this.ExecuteSubAgent(params, subAgentRequest, subAgentEntity, stepEntity, initialSubAgentPayload, contextMessage);
|
|
2807
|
+
const subAgentResult = await this.ExecuteSubAgent(params, subAgentRequest, subAgentEntity, stepEntity, initialSubAgentPayload, contextMessage, stepCount);
|
|
2736
2808
|
let mergedPayload = previousDecision.newPayload;
|
|
2737
2809
|
let currentStepPayloadChangeResult = undefined;
|
|
2738
2810
|
if (subAgentResult.success && relationship.SubAgentOutputMapping) {
|
|
@@ -2907,7 +2979,7 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
2907
2979
|
return null;
|
|
2908
2980
|
}
|
|
2909
2981
|
}
|
|
2910
|
-
prepareRelatedSubAgentContextMessage(parentPayload, contextPaths) {
|
|
2982
|
+
prepareRelatedSubAgentContextMessage(parentPayload, contextPaths, params) {
|
|
2911
2983
|
if (!contextPaths || contextPaths.length === 0) {
|
|
2912
2984
|
return null;
|
|
2913
2985
|
}
|
|
@@ -2919,7 +2991,13 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
2919
2991
|
}
|
|
2920
2992
|
const contextData = {};
|
|
2921
2993
|
for (const path of contextPaths) {
|
|
2922
|
-
|
|
2994
|
+
let value;
|
|
2995
|
+
if (ConversationMessageResolver_1.ConversationMessageResolver.isConversationReference(path) && params?.conversationMessages) {
|
|
2996
|
+
value = ConversationMessageResolver_1.ConversationMessageResolver.resolve(path, params.conversationMessages);
|
|
2997
|
+
}
|
|
2998
|
+
else {
|
|
2999
|
+
value = this.getValueFromPath(parentPayload, path);
|
|
3000
|
+
}
|
|
2923
3001
|
if (value !== undefined) {
|
|
2924
3002
|
contextData[path] = value;
|
|
2925
3003
|
}
|
|
@@ -2938,7 +3016,7 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
2938
3016
|
content: `Parent Agent Context:\n\n${contextLines.join('\n\n')}`
|
|
2939
3017
|
};
|
|
2940
3018
|
}
|
|
2941
|
-
async executeActionsStep(params, previousDecision, parentStepId, addConversationMessage = true) {
|
|
3019
|
+
async executeActionsStep(params, previousDecision, parentStepId, addConversationMessage = true, stepCount = 0) {
|
|
2942
3020
|
try {
|
|
2943
3021
|
const currentPayload = previousDecision?.newPayload || previousDecision?.previousPayload || params.payload;
|
|
2944
3022
|
const actions = previousDecision.actions || [];
|
|
@@ -2979,11 +3057,12 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
2979
3057
|
}
|
|
2980
3058
|
params.onProgress?.({
|
|
2981
3059
|
step: 'action_execution',
|
|
2982
|
-
percentage: 50,
|
|
2983
3060
|
message: this.formatHierarchicalMessage(progressMessage),
|
|
2984
3061
|
metadata: {
|
|
2985
3062
|
actionCount: actions.length,
|
|
2986
|
-
actionNames: actions.map(a => a.name)
|
|
3063
|
+
actionNames: actions.map(a => a.name),
|
|
3064
|
+
stepCount: stepCount + 1,
|
|
3065
|
+
hierarchicalStep: this.buildHierarchicalStep(stepCount + 1, this._parentStepCounts)
|
|
2987
3066
|
},
|
|
2988
3067
|
displayMode: 'live'
|
|
2989
3068
|
});
|
|
@@ -3194,7 +3273,9 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
3194
3273
|
confidence: previousDecision.confidence,
|
|
3195
3274
|
previousPayload: previousDecision.previousPayload,
|
|
3196
3275
|
newPayload: previousDecision.newPayload || previousDecision.previousPayload,
|
|
3197
|
-
|
|
3276
|
+
responseForm: previousDecision.responseForm,
|
|
3277
|
+
actionableCommands: previousDecision.actionableCommands,
|
|
3278
|
+
automaticCommands: previousDecision.automaticCommands
|
|
3198
3279
|
};
|
|
3199
3280
|
}
|
|
3200
3281
|
async executeForEachLoop(params, config, previousDecision) {
|
|
@@ -3653,7 +3734,9 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
3653
3734
|
success: finalStep.step === 'Success' || finalStep.step === 'Chat',
|
|
3654
3735
|
payload,
|
|
3655
3736
|
agentRun: this._agentRun,
|
|
3656
|
-
|
|
3737
|
+
responseForm: finalStep.responseForm,
|
|
3738
|
+
actionableCommands: finalStep.actionableCommands,
|
|
3739
|
+
automaticCommands: finalStep.automaticCommands,
|
|
3657
3740
|
memoryContext: this._injectedMemory.notes.length > 0 || this._injectedMemory.examples.length > 0
|
|
3658
3741
|
? this._injectedMemory
|
|
3659
3742
|
: undefined
|
|
@@ -4025,7 +4108,11 @@ The context is now within limits. Please retry your request with the recovered c
|
|
|
4025
4108
|
value = trimmedValue.substring(2, trimmedValue.length - 2).trim();
|
|
4026
4109
|
}
|
|
4027
4110
|
const ivToLower = itemVariable?.trim().toLowerCase();
|
|
4028
|
-
|
|
4111
|
+
const valueLower = value?.toLowerCase();
|
|
4112
|
+
if (valueLower === ivToLower) {
|
|
4113
|
+
return context.item;
|
|
4114
|
+
}
|
|
4115
|
+
if (valueLower?.startsWith(`${ivToLower}.`)) {
|
|
4029
4116
|
const path = value.substring(ivToLower.length + 1);
|
|
4030
4117
|
return this.getValueFromPath(context.item, path);
|
|
4031
4118
|
}
|