@memberjunction/ai-agents 6.2.0-edge.5 → 6.2.0-edge.7
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 +89 -2
- package/dist/AgentDataPreloader.d.ts +4 -2
- package/dist/AgentDataPreloader.d.ts.map +1 -1
- package/dist/AgentDataPreloader.js +21 -12
- package/dist/AgentDataPreloader.js.map +1 -1
- package/dist/AgentRunner.d.ts +150 -5
- package/dist/AgentRunner.d.ts.map +1 -1
- package/dist/AgentRunner.js +588 -64
- package/dist/AgentRunner.js.map +1 -1
- package/dist/AgentWakeTriggerService.d.ts +183 -0
- package/dist/AgentWakeTriggerService.d.ts.map +1 -0
- package/dist/AgentWakeTriggerService.js +485 -0
- package/dist/AgentWakeTriggerService.js.map +1 -0
- package/dist/ArtifactToolManager.d.ts +1 -0
- package/dist/ArtifactToolManager.d.ts.map +1 -1
- package/dist/ArtifactToolManager.js +5 -0
- package/dist/ArtifactToolManager.js.map +1 -1
- package/dist/ConversationToolManager.d.ts +1 -1
- package/dist/ConversationToolManager.d.ts.map +1 -1
- package/dist/ConversationToolManager.js +10 -4
- package/dist/ConversationToolManager.js.map +1 -1
- package/dist/MJAIAgentRequestEntityServer.d.ts +15 -1
- package/dist/MJAIAgentRequestEntityServer.d.ts.map +1 -1
- package/dist/MJAIAgentRequestEntityServer.js +63 -3
- package/dist/MJAIAgentRequestEntityServer.js.map +1 -1
- package/dist/agent-context-injector.d.ts +21 -4
- package/dist/agent-context-injector.d.ts.map +1 -1
- package/dist/agent-context-injector.js +49 -13
- package/dist/agent-context-injector.js.map +1 -1
- package/dist/agent-memory-context-builder.js +2 -2
- package/dist/agent-memory-context-builder.js.map +1 -1
- package/dist/agent-pre-execution-rag.d.ts.map +1 -1
- package/dist/agent-pre-execution-rag.js +6 -8
- package/dist/agent-pre-execution-rag.js.map +1 -1
- package/dist/agent-run-watchdog.d.ts +71 -18
- package/dist/agent-run-watchdog.d.ts.map +1 -1
- package/dist/agent-run-watchdog.js +223 -90
- package/dist/agent-run-watchdog.js.map +1 -1
- package/dist/agent-types/flow-agent-type.d.ts +13 -0
- package/dist/agent-types/flow-agent-type.d.ts.map +1 -1
- package/dist/agent-types/flow-agent-type.js +165 -27
- package/dist/agent-types/flow-agent-type.js.map +1 -1
- package/dist/agent-types/loop-agent-prompt-params.d.ts +32 -5
- package/dist/agent-types/loop-agent-prompt-params.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-prompt-params.js +5 -3
- package/dist/agent-types/loop-agent-prompt-params.js.map +1 -1
- package/dist/agent-types/loop-agent-response-type.d.ts +35 -4
- package/dist/agent-types/loop-agent-response-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-response-type.js +1 -1
- package/dist/agent-types/loop-agent-response-type.js.map +1 -1
- package/dist/agent-types/loop-agent-type.d.ts +103 -9
- package/dist/agent-types/loop-agent-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-type.js +351 -68
- package/dist/agent-types/loop-agent-type.js.map +1 -1
- package/dist/base-agent.d.ts +551 -44
- package/dist/base-agent.d.ts.map +1 -1
- package/dist/base-agent.js +2742 -549
- package/dist/base-agent.js.map +1 -1
- package/dist/bound-action-params.d.ts +57 -0
- package/dist/bound-action-params.d.ts.map +1 -0
- package/dist/bound-action-params.js +91 -0
- package/dist/bound-action-params.js.map +1 -0
- package/dist/catalog-narrowing.d.ts.map +1 -1
- package/dist/catalog-narrowing.js +6 -3
- package/dist/catalog-narrowing.js.map +1 -1
- package/dist/handoff-target.d.ts +80 -0
- package/dist/handoff-target.d.ts.map +1 -0
- package/dist/handoff-target.js +158 -0
- package/dist/handoff-target.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/memory-cleanup-agent.d.ts.map +1 -1
- package/dist/memory-cleanup-agent.js +3 -0
- package/dist/memory-cleanup-agent.js.map +1 -1
- package/dist/memory-manager-agent.d.ts.map +1 -1
- package/dist/memory-manager-agent.js +8 -1
- package/dist/memory-manager-agent.js.map +1 -1
- package/dist/native-tools/action-tool-builder.d.ts +6 -0
- package/dist/native-tools/action-tool-builder.d.ts.map +1 -1
- package/dist/native-tools/action-tool-builder.js +21 -5
- package/dist/native-tools/action-tool-builder.js.map +1 -1
- package/dist/native-tools/agent-tools.d.ts +64 -0
- package/dist/native-tools/agent-tools.d.ts.map +1 -0
- package/dist/native-tools/agent-tools.js +23 -0
- package/dist/native-tools/agent-tools.js.map +1 -0
- package/dist/native-tools/control-tools.d.ts +40 -7
- package/dist/native-tools/control-tools.d.ts.map +1 -1
- package/dist/native-tools/control-tools.js +139 -50
- package/dist/native-tools/control-tools.js.map +1 -1
- package/dist/native-tools/framework-tools.d.ts +47 -0
- package/dist/native-tools/framework-tools.d.ts.map +1 -0
- package/dist/native-tools/framework-tools.js +187 -0
- package/dist/native-tools/framework-tools.js.map +1 -0
- package/dist/native-tools/native-control-config.d.ts +93 -0
- package/dist/native-tools/native-control-config.d.ts.map +1 -0
- package/dist/native-tools/native-control-config.js +104 -0
- package/dist/native-tools/native-control-config.js.map +1 -0
- package/dist/native-tools/tool-result-turns.d.ts +41 -8
- package/dist/native-tools/tool-result-turns.d.ts.map +1 -1
- package/dist/native-tools/tool-result-turns.js +76 -2
- package/dist/native-tools/tool-result-turns.js.map +1 -1
- package/dist/native-tools/turn-mode.d.ts +8 -0
- package/dist/native-tools/turn-mode.d.ts.map +1 -0
- package/dist/native-tools/turn-mode.js +14 -0
- package/dist/native-tools/turn-mode.js.map +1 -0
- package/dist/pipeline/pipeline-registry.d.ts +5 -12
- package/dist/pipeline/pipeline-registry.d.ts.map +1 -1
- package/dist/pipeline/pipeline-registry.js +28 -2
- package/dist/pipeline/pipeline-registry.js.map +1 -1
- package/dist/pipeline/providers/serialize.d.ts +7 -3
- package/dist/pipeline/providers/serialize.d.ts.map +1 -1
- package/dist/pipeline/providers/serialize.js +9 -5
- package/dist/pipeline/providers/serialize.js.map +1 -1
- package/dist/query-builder-agent.d.ts +20 -1
- package/dist/query-builder-agent.d.ts.map +1 -1
- package/dist/query-builder-agent.js +35 -3
- package/dist/query-builder-agent.js.map +1 -1
- package/dist/realtime/bridge-room-transcript-sink.js +3 -0
- package/dist/realtime/bridge-room-transcript-sink.js.map +1 -1
- package/dist/realtime/bridge-session-transcript-sink.js +1 -0
- package/dist/realtime/bridge-session-transcript-sink.js.map +1 -1
- package/dist/realtime/realtime-client-session-service.d.ts +22 -2
- package/dist/realtime/realtime-client-session-service.d.ts.map +1 -1
- package/dist/realtime/realtime-client-session-service.js +70 -10
- package/dist/realtime/realtime-client-session-service.js.map +1 -1
- package/dist/realtime/realtime-coagent-config.d.ts.map +1 -1
- package/dist/realtime/realtime-coagent-config.js +2 -28
- package/dist/realtime/realtime-coagent-config.js.map +1 -1
- package/dist/realtime/realtime-recording-capture.d.ts +1 -0
- package/dist/realtime/realtime-recording-capture.d.ts.map +1 -1
- package/dist/realtime/realtime-recording-capture.js +17 -3
- package/dist/realtime/realtime-recording-capture.js.map +1 -1
- package/dist/realtime/realtime-recording-ledger.d.ts +20 -0
- package/dist/realtime/realtime-recording-ledger.d.ts.map +1 -1
- package/dist/realtime/realtime-recording-ledger.js +16 -0
- package/dist/realtime/realtime-recording-ledger.js.map +1 -1
- package/dist/realtime/realtime-recording-opus-assembly.d.ts.map +1 -1
- package/dist/realtime/realtime-recording-opus-assembly.js +9 -4
- package/dist/realtime/realtime-recording-opus-assembly.js.map +1 -1
- package/dist/realtime/realtime-recording-store.d.ts +6 -5
- package/dist/realtime/realtime-recording-store.d.ts.map +1 -1
- package/dist/realtime/realtime-recording-store.js +47 -21
- package/dist/realtime/realtime-recording-store.js.map +1 -1
- package/dist/realtime/realtime-session-runner.d.ts.map +1 -1
- package/dist/realtime/realtime-session-runner.js +5 -7
- package/dist/realtime/realtime-session-runner.js.map +1 -1
- package/dist/realtime/realtime-turn-moderator.d.ts.map +1 -1
- package/dist/realtime/realtime-turn-moderator.js +1 -0
- package/dist/realtime/realtime-turn-moderator.js.map +1 -1
- package/dist/rubric-evaluation-agent-runner.js +1 -0
- package/dist/rubric-evaluation-agent-runner.js.map +1 -1
- package/dist/runtime-state-fragment.d.ts.map +1 -1
- package/dist/runtime-state-fragment.js +3 -0
- package/dist/runtime-state-fragment.js.map +1 -1
- package/dist/sub-agent-consult.d.ts +75 -0
- package/dist/sub-agent-consult.d.ts.map +1 -0
- package/dist/sub-agent-consult.js +193 -0
- package/dist/sub-agent-consult.js.map +1 -0
- package/dist/volatile-child-prompt.d.ts +7 -0
- package/dist/volatile-child-prompt.d.ts.map +1 -1
- package/dist/volatile-child-prompt.js +8 -0
- package/dist/volatile-child-prompt.js.map +1 -1
- package/package.json +20 -20
|
@@ -15,11 +15,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
15
15
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
16
16
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
17
17
|
};
|
|
18
|
-
import { CHAT_FINISH_REASON_MALFORMED_TOOL_CALL } from '@memberjunction/ai';
|
|
18
|
+
import { CHAT_FINISH_REASON_MALFORMED_TOOL_CALL, CHAT_FINISH_REASON_UNEXPECTED_TOOL_CALL } from '@memberjunction/ai';
|
|
19
19
|
import { RegisterClass, SafeExpressionEvaluator } from '@memberjunction/global';
|
|
20
20
|
import { BaseAgentType } from './base-agent-type.js';
|
|
21
|
+
import { COMPLETE_TASK_TOOL, PAYLOAD_CHANGE_TOOL } from '../native-tools/control-tools.js';
|
|
21
22
|
import { CoerceActionArguments } from '../native-tools/action-tool-builder.js';
|
|
22
23
|
import { DecodeJSONArgument } from '../native-tools/json-argument.js';
|
|
24
|
+
import { ResolveNativeControlConfig } from '../native-tools/native-control-config.js';
|
|
25
|
+
import { TurnToolCallingMode } from '../native-tools/turn-mode.js';
|
|
26
|
+
import { FRAMEWORK_TOOL_NAMES } from '../native-tools/framework-tools.js';
|
|
23
27
|
import { GetToolCallingDecision } from '@memberjunction/ai-prompts';
|
|
24
28
|
import { FormatValidationErrors, ValidateTaskGraphSpec, ConfigOf } from '@memberjunction/ai-core-plus';
|
|
25
29
|
import { LogError, LogStatusEx } from '@memberjunction/core';
|
|
@@ -135,10 +139,13 @@ let LoopAgentType = class LoopAgentType extends BaseAgentType {
|
|
|
135
139
|
/**
|
|
136
140
|
* Resolves whether this agent may emit durable task graphs.
|
|
137
141
|
*
|
|
138
|
-
* Read from
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
+
* Read from `params.data.__agentTypePromptParams`, which `BaseAgent.determineNextStep`
|
|
143
|
+
* populates on a shallow copy of `params` from `this._agentTypePromptParams` (the merged
|
|
144
|
+
* three-level params bag: schema defaults → agent config → runtime override, with
|
|
145
|
+
* `withoutTaskGraphs` applied when the run withholds them), or which a direct unit caller
|
|
146
|
+
* supplies in `params.data`. Absent means NO: this is the one Loop flag whose default is
|
|
147
|
+
* off, because the capability creates durable rows that outlive the run rather than merely
|
|
148
|
+
* adding prompt text (D3).
|
|
142
149
|
*/
|
|
143
150
|
taskGraphsEnabled(params) {
|
|
144
151
|
const promptParams = params?.data?.__agentTypePromptParams;
|
|
@@ -200,11 +207,16 @@ let LoopAgentType = class LoopAgentType extends BaseAgentType {
|
|
|
200
207
|
// describeFold() has already established this is an Agent node — folding is only offered
|
|
201
208
|
// for one. The `?? ''` is unreachable and exists so this cannot become a silent `undefined`
|
|
202
209
|
// if that precondition is ever loosened.
|
|
210
|
+
const agentCfg = ConfigOf(node, 'Agent');
|
|
211
|
+
const presetName = typeof agentCfg?.presetName === 'string' && agentCfg.presetName.trim().length > 0
|
|
212
|
+
? agentCfg.presetName.trim()
|
|
213
|
+
: undefined;
|
|
203
214
|
retVal.step = 'Sub-Agent';
|
|
204
215
|
retVal.subAgent = {
|
|
205
|
-
name:
|
|
216
|
+
name: agentCfg?.agentName ?? '',
|
|
206
217
|
message: node.description,
|
|
207
218
|
terminateAfter: false,
|
|
219
|
+
...(presetName ? { presetName } : {}),
|
|
208
220
|
templateParameters: {},
|
|
209
221
|
};
|
|
210
222
|
// Recorded, never silent: the TaskGraph run step is written for folded graphs too, so
|
|
@@ -247,6 +259,12 @@ let LoopAgentType = class LoopAgentType extends BaseAgentType {
|
|
|
247
259
|
* The reason is carried onto the run step rather than discarded: a user who edits a two-node
|
|
248
260
|
* graph down to one changes its durability and observability, and should be able to read that
|
|
249
261
|
* off the run record instead of inferring it.
|
|
262
|
+
*
|
|
263
|
+
* Note: `LoopAgentType` only checks structural eligibility here because it has no view of the
|
|
264
|
+
* run's effective sub-agent set (`ParentID` children, active relationships, and runtime skill /
|
|
265
|
+
* `subAgentChanges` grants). If the folded target is not resolvable via
|
|
266
|
+
* `BaseAgent.resolveSubAgentByName`, `BaseAgent.validateNextStep` unfolds the step back to
|
|
267
|
+
* `'Tasks'` (`folded: false`) so it submits durably instead of failing sub-agent validation.
|
|
250
268
|
*/
|
|
251
269
|
describeFold(spec) {
|
|
252
270
|
if (spec.tasks.length !== 1)
|
|
@@ -265,6 +283,56 @@ let LoopAgentType = class LoopAgentType extends BaseAgentType {
|
|
|
265
283
|
}
|
|
266
284
|
return { folded: true, reason: 'single agent node, no dependencies, foldable continuation' };
|
|
267
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* Resolves whether this agent may emit a conversation handoff (`nextStep.type === 'Handoff'`).
|
|
288
|
+
*
|
|
289
|
+
* Read from `params.data.__agentTypePromptParams`, which `BaseAgent.determineNextStep`
|
|
290
|
+
* populates on a shallow copy of `params` from `this._agentTypePromptParams` (with
|
|
291
|
+
* `withoutHandoff` applied when the run withholds handoff), or which a direct unit caller
|
|
292
|
+
* supplies in `params.data`. Absent means NO (D14).
|
|
293
|
+
*/
|
|
294
|
+
handoffEnabled(params) {
|
|
295
|
+
const promptParams = params?.data?.__agentTypePromptParams;
|
|
296
|
+
return promptParams?.enableHandoff === true;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Applies a `'Handoff'` emission to the next step: capability gate and shape validation.
|
|
300
|
+
* Never folds into a Sub-Agent step — a handoff transfers ownership of the conversation turn.
|
|
301
|
+
*/
|
|
302
|
+
applyHandoffStep(retVal, handoff, topLevelMessage, params) {
|
|
303
|
+
retVal.terminate = false;
|
|
304
|
+
if (!this.handoffEnabled(params)) {
|
|
305
|
+
retVal.step = 'Retry';
|
|
306
|
+
retVal.message =
|
|
307
|
+
'Handoff is not available here, so nextStep.type must never be "Handoff". ' +
|
|
308
|
+
'Answer directly, or use nextStep.type "Sub-Agent" or "Actions" instead.';
|
|
309
|
+
retVal.errorMessage = 'Handoff is not enabled for this agent';
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
const agentName = typeof handoff?.agentName === 'string' ? handoff.agentName.trim() : '';
|
|
313
|
+
const brief = typeof handoff?.brief === 'string' ? handoff.brief.trim() : '';
|
|
314
|
+
if (!handoff || agentName.length === 0 || brief.length === 0) {
|
|
315
|
+
retVal.step = 'Retry';
|
|
316
|
+
retVal.message =
|
|
317
|
+
'When nextStep.type == "Handoff", nextStep.handoff must specify non-empty "agentName" and "brief" strings';
|
|
318
|
+
retVal.errorMessage = !handoff
|
|
319
|
+
? 'Handoff details not specified for Handoff type'
|
|
320
|
+
: agentName.length === 0
|
|
321
|
+
? 'Handoff agentName not specified for Handoff type'
|
|
322
|
+
: 'Handoff brief not specified for Handoff type';
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
const reason = typeof handoff.reason === 'string' ? handoff.reason.trim() : '';
|
|
326
|
+
retVal.step = 'Handoff';
|
|
327
|
+
retVal.handoff = {
|
|
328
|
+
agentName,
|
|
329
|
+
brief,
|
|
330
|
+
reason,
|
|
331
|
+
};
|
|
332
|
+
if (topLevelMessage !== undefined) {
|
|
333
|
+
retVal.message = topLevelMessage;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
268
336
|
async InitializeAgentTypeState(params) {
|
|
269
337
|
// Loop agents do not require agent-type specific state initialization
|
|
270
338
|
// but can be extended in the future if needed
|
|
@@ -294,7 +362,7 @@ let LoopAgentType = class LoopAgentType extends BaseAgentType {
|
|
|
294
362
|
* documented to do this, measured at roughly one forced call in six, so the loop
|
|
295
363
|
* has to be able to say "that tool does not exist" rather than appear to hang.
|
|
296
364
|
*/
|
|
297
|
-
nextStepFromNativeToolCalls(promptResult, bindings) {
|
|
365
|
+
nextStepFromNativeToolCalls(promptResult, bindings, relaxedTurnShapes = false) {
|
|
298
366
|
const calls = promptResult.chatResult?.data?.choices?.[0]?.message?.toolCalls;
|
|
299
367
|
if (!calls?.length) {
|
|
300
368
|
return null;
|
|
@@ -307,21 +375,41 @@ let LoopAgentType = class LoopAgentType extends BaseAgentType {
|
|
|
307
375
|
// Control tools are dispatchable ONLY on a turn the runner recorded as NativeImplicit
|
|
308
376
|
// under the hybrid they are stripped from the request, so a call to one
|
|
309
377
|
// is a call to an undeclared tool, whatever the binding map says.
|
|
310
|
-
const implicit = promptResult
|
|
378
|
+
const implicit = TurnToolCallingMode(promptResult) === 'NativeImplicit';
|
|
311
379
|
// The model's own turn travels on the step so the loop can replay it into history and
|
|
312
380
|
// answer each call natively when the runner's decision says so.
|
|
313
381
|
const message = promptResult.chatResult?.data?.choices?.[0]?.message;
|
|
314
382
|
const nativeTurn = {
|
|
315
383
|
text: typeof message?.content === 'string' ? message.content : '',
|
|
316
384
|
toolCalls: calls,
|
|
317
|
-
sendResultsNatively: GetToolCallingDecision(promptResult.chatResult)?.toolResults === true
|
|
385
|
+
sendResultsNatively: GetToolCallingDecision(promptResult.chatResult)?.toolResults === true,
|
|
386
|
+
...(message?.reasoning?.length ? { reasoning: message.reasoning } : {})
|
|
318
387
|
};
|
|
319
388
|
const { resolved, unknown } = this.resolveNativeCalls(calls, bindings, implicit);
|
|
320
389
|
if (unknown.length > 0) {
|
|
321
390
|
return this.createRetryStep(`You called ${unknown.map((c) => `'${c.name}'`).join(', ')}, which ${unknown.length === 1 ? 'is not a tool' : 'are not tools'} `
|
|
322
|
-
+ `available to you.
|
|
391
|
+
+ `available to you. ${this.unknownToolAdvice(implicit, bindings)}`, { nativeTurn });
|
|
323
392
|
}
|
|
324
|
-
|
|
393
|
+
const completeTaskDeclared = bindings.has(COMPLETE_TASK_TOOL);
|
|
394
|
+
const step = relaxedTurnShapes ? this.routeRelaxed(resolved, completeTaskDeclared) : this.routeStrict(resolved, completeTaskDeclared);
|
|
395
|
+
return { ...step, nativeTurn };
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Whether a binding runs on a hybrid turn. Actions and the agent's own tools run in every native
|
|
399
|
+
* mode; control tools — and the framework tools, which are declared as control tools — are
|
|
400
|
+
* stripped from a hybrid request, so a call to one there is a call to an undeclared tool.
|
|
401
|
+
*/
|
|
402
|
+
dispatchableOnHybrid(binding) {
|
|
403
|
+
return binding.kind === 'action' || (binding.kind === 'agentTool' && !FRAMEWORK_TOOL_NAMES.includes(binding.toolName));
|
|
404
|
+
}
|
|
405
|
+
/** What to do instead, after a call to a tool that does not exist on this turn. */
|
|
406
|
+
unknownToolAdvice(implicit, bindings) {
|
|
407
|
+
if (!implicit) {
|
|
408
|
+
return 'Call one of the declared tools, or respond with the JSON envelope if no tool applies.';
|
|
409
|
+
}
|
|
410
|
+
return bindings.has(COMPLETE_TASK_TOOL)
|
|
411
|
+
? 'Call one of the declared tools, or call complete_task when the task is done.'
|
|
412
|
+
: 'Call one of the declared tools, or reply in plain text when the task is done.';
|
|
325
413
|
}
|
|
326
414
|
/** Pairs each call with its binding; a control-tool binding counts only under implicit control flow. */
|
|
327
415
|
resolveNativeCalls(calls, bindings, implicit) {
|
|
@@ -329,7 +417,7 @@ let LoopAgentType = class LoopAgentType extends BaseAgentType {
|
|
|
329
417
|
const unknown = [];
|
|
330
418
|
for (const call of calls) {
|
|
331
419
|
const binding = bindings.get(call.name);
|
|
332
|
-
if (binding && (
|
|
420
|
+
if (binding && (implicit || this.dispatchableOnHybrid(binding))) {
|
|
333
421
|
resolved.push({ call, binding });
|
|
334
422
|
}
|
|
335
423
|
else {
|
|
@@ -338,44 +426,167 @@ let LoopAgentType = class LoopAgentType extends BaseAgentType {
|
|
|
338
426
|
}
|
|
339
427
|
return { resolved, unknown };
|
|
340
428
|
}
|
|
341
|
-
/**
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
429
|
+
/**
|
|
430
|
+
* The turn-reading table of spec §2.1, with each control call alone on its turn — the default.
|
|
431
|
+
*
|
|
432
|
+
* `ask_user` and `complete_task` must be the only call on their turn, at most one
|
|
433
|
+
* `payload_change_request` is allowed, and acting and delegating cannot share a turn; each of
|
|
434
|
+
* these is a Retry that runs nothing. The agent's own tools ride along with Actions or a
|
|
435
|
+
* delegation, and alone are a turn of their own.
|
|
436
|
+
*
|
|
437
|
+
* @param completeTaskDeclared Whether the agent declares `complete_task`; a text-terminal agent
|
|
438
|
+
* does not, and is told to finish in plain text instead.
|
|
439
|
+
*/
|
|
440
|
+
routeStrict(resolved, completeTaskDeclared) {
|
|
441
|
+
const calls = this.groupResolvedCalls(resolved);
|
|
442
|
+
if (calls.askUser.length > 0) {
|
|
443
|
+
return resolved.length > 1
|
|
444
|
+
? this.createRetryStep('ask_user must be the only call on its turn: either ask the user, or do the work — not both at once.')
|
|
445
|
+
: this.askUserStep(calls.askUser[0]);
|
|
350
446
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
447
|
+
if (calls.complete.length > 0) {
|
|
448
|
+
return resolved.length > 1
|
|
449
|
+
? this.createRetryStep('complete_task must be the only call on its turn. Finish any other tool calls first, then call complete_task on its own.')
|
|
450
|
+
: this.completeTaskStep(calls.complete[0]);
|
|
354
451
|
}
|
|
355
|
-
if (payloads.length > 1) {
|
|
452
|
+
if (calls.payloads.length > 1) {
|
|
356
453
|
return this.createRetryStep('Call payload_change_request at most once per turn; combine your changes into one call.');
|
|
357
454
|
}
|
|
358
|
-
|
|
359
|
-
// The payload call's id has to travel with every step that carries the change, not just the
|
|
360
|
-
// payload-only one: whichever branch applies it also has to answer that call, or the model
|
|
361
|
-
// is left with a tool_use nothing responded to.
|
|
362
|
-
const payloadToolCallId = payloads[0]?.call.id;
|
|
363
|
-
if (subAgents.length > 0 && actions.length > 0) {
|
|
455
|
+
if (calls.subAgents.length > 0 && calls.actions.length > 0) {
|
|
364
456
|
return this.createRetryStep('Delegate or act — not both in one turn. Call the sub-agent tool(s) on their own, or the action tool(s) on their own.');
|
|
365
457
|
}
|
|
366
|
-
|
|
367
|
-
|
|
458
|
+
return this.workStep(calls, false, completeTaskDeclared) ?? this.payloadOnlyStep(undefined, undefined, completeTaskDeclared);
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* The turn-reading table with relaxed turn shapes (`NativeControl.RelaxedTurnShapes`): every
|
|
462
|
+
* call on the turn is honoured where the loop can do so without skipping a check.
|
|
463
|
+
* - Writes — the agent's own tools and `payload_change_request` — run inline, in call order,
|
|
464
|
+
* and are answered one by one. A single payload change keeps the step's own payload channel.
|
|
465
|
+
* - `ask_user` or `complete_task` after writes: the writes run, then the turn asks or completes
|
|
466
|
+
* through the normal Chat or Success validation. A failed write declines it (see BaseAgent).
|
|
467
|
+
* - Actions with a delegation, `ask_user` or `complete_task`: the Actions run, and the other
|
|
468
|
+
* calls are answered as not run — they were made before the Actions' results existed, and
|
|
469
|
+
* running them afterwards would skip the validation a turn's own decision gets.
|
|
470
|
+
*
|
|
471
|
+
* @param completeTaskDeclared Whether the agent declares `complete_task`; a text-terminal agent
|
|
472
|
+
* does not, and is told to finish in plain text instead.
|
|
473
|
+
*/
|
|
474
|
+
routeRelaxed(resolved, completeTaskDeclared) {
|
|
475
|
+
const calls = this.groupResolvedCalls(resolved);
|
|
476
|
+
if (calls.askUser.length > 1 || calls.complete.length > 1) {
|
|
477
|
+
return this.createRetryStep('Call ask_user or complete_task at most once per turn.');
|
|
368
478
|
}
|
|
369
|
-
|
|
370
|
-
|
|
479
|
+
const terminal = calls.askUser.length > 0 || calls.complete.length > 0;
|
|
480
|
+
const work = this.workStep(calls, terminal, completeTaskDeclared);
|
|
481
|
+
if (calls.askUser.length > 0) {
|
|
482
|
+
return this.withAskUser(calls.askUser[0], work);
|
|
371
483
|
}
|
|
372
|
-
|
|
484
|
+
if (calls.complete.length > 0) {
|
|
485
|
+
return this.withCompleteTask(calls.complete[0], work);
|
|
486
|
+
}
|
|
487
|
+
// A resolved turn always holds at least one call, so a non-terminal turn always has work.
|
|
488
|
+
return work ?? this.payloadOnlyStep(undefined, undefined, completeTaskDeclared);
|
|
373
489
|
}
|
|
374
|
-
/**
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
490
|
+
/** The turn's calls by kind; `writes` holds agent-tool and payload calls in the order the model made them. */
|
|
491
|
+
groupResolvedCalls(resolved) {
|
|
492
|
+
const ofKind = (kind) => resolved.filter((r) => r.binding.kind === kind);
|
|
493
|
+
return {
|
|
494
|
+
askUser: ofKind('askUser'),
|
|
495
|
+
complete: ofKind('complete'),
|
|
496
|
+
subAgents: ofKind('subAgent'),
|
|
497
|
+
actions: ofKind('action'),
|
|
498
|
+
payloads: ofKind('payloadChange'),
|
|
499
|
+
writes: resolved.filter((r) => r.binding.kind === 'agentTool' || r.binding.kind === 'payloadChange')
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* The step for every non-terminal call on the turn, or undefined when there are none.
|
|
504
|
+
*
|
|
505
|
+
* One `payload_change_request` on a turn with no terminal call rides on the step's own payload
|
|
506
|
+
* channel, as it always has. Several — or one beside `ask_user` / `complete_task`, whose step
|
|
507
|
+
* cannot answer it — run with the agent's tools as ordered writes, each answered by its result.
|
|
508
|
+
*/
|
|
509
|
+
workStep(calls, terminal, completeTaskDeclared) {
|
|
510
|
+
const ordered = calls.payloads.length > 1 || terminal;
|
|
511
|
+
const payloadChangeRequest = ordered ? undefined : calls.payloads[0]?.call.arguments;
|
|
512
|
+
// Whichever branch applies the change also answers its call, so the id travels with the step.
|
|
513
|
+
const payloadToolCallId = ordered ? undefined : calls.payloads[0]?.call.id;
|
|
514
|
+
const writes = this.agentToolCallRequests(ordered ? calls.writes : calls.writes.filter((w) => w.binding.kind === 'agentTool'));
|
|
515
|
+
if (calls.actions.length > 0) {
|
|
516
|
+
// Strict routing never reaches here with both; relaxed routing runs the Actions and
|
|
517
|
+
// declines the delegations, which are made again once the Actions' results are read.
|
|
518
|
+
const declined = calls.subAgents.map(({ call }) => ({
|
|
519
|
+
toolCallId: call.id, toolName: call.name,
|
|
520
|
+
reason: 'Delegations are not run on a turn that also calls Actions. The Actions ran; read their results, then delegate on a turn of its own.'
|
|
521
|
+
}));
|
|
522
|
+
return { ...this.actionsStep(calls.actions, payloadChangeRequest, payloadToolCallId), ...writes, ...(declined.length ? { declinedToolCalls: declined } : {}) };
|
|
523
|
+
}
|
|
524
|
+
if (calls.subAgents.length > 0) {
|
|
525
|
+
return { ...this.subAgentStep(calls.subAgents, payloadChangeRequest, payloadToolCallId), ...writes };
|
|
526
|
+
}
|
|
527
|
+
if (writes.agentToolCalls) {
|
|
528
|
+
return this.agentToolsStep(writes.agentToolCalls, payloadChangeRequest, payloadToolCallId);
|
|
529
|
+
}
|
|
530
|
+
return payloadChangeRequest ? this.payloadOnlyStep(payloadChangeRequest, payloadToolCallId, completeTaskDeclared) : undefined;
|
|
531
|
+
}
|
|
532
|
+
/** Whether a step only writes — runs inline in the prompt step, with nothing executed after it. */
|
|
533
|
+
isWritesOnly(step) {
|
|
534
|
+
return step.step === 'Retry' && !step.actions?.length && !step.subAgent && !step.subAgents?.length;
|
|
535
|
+
}
|
|
536
|
+
/** `ask_user` with the turn's other calls: after writes it asks; beside Actions or delegations it is declined. */
|
|
537
|
+
withAskUser(ask, work) {
|
|
538
|
+
const chat = this.askUserStep(ask);
|
|
539
|
+
if (!work || chat.step !== 'Chat') {
|
|
540
|
+
return chat;
|
|
541
|
+
}
|
|
542
|
+
if (this.isWritesOnly(work)) {
|
|
543
|
+
return { ...chat, agentToolCalls: work.agentToolCalls };
|
|
378
544
|
}
|
|
545
|
+
const reason = 'ask_user was called with other tools on the same turn. They ran first; read their results, then ask on a turn of its own if you still need to.';
|
|
546
|
+
return this.withDeclined(work, { toolCallId: ask.call.id, toolName: ask.call.name, reason });
|
|
547
|
+
}
|
|
548
|
+
/** Adds one declined call to a step's list. */
|
|
549
|
+
withDeclined(step, declined) {
|
|
550
|
+
return { ...step, declinedToolCalls: [...(step.declinedToolCalls ?? []), declined] };
|
|
551
|
+
}
|
|
552
|
+
/** `complete_task` with the turn's other calls — see {@link routeRelaxed} for when it runs. */
|
|
553
|
+
withCompleteTask(complete, work) {
|
|
554
|
+
const success = this.completeTaskStep(complete);
|
|
555
|
+
if (!work || success.step !== 'Success') {
|
|
556
|
+
return success;
|
|
557
|
+
}
|
|
558
|
+
// Its own payload change would land ahead of writes the model made before it, so it waits.
|
|
559
|
+
if (this.isWritesOnly(work) && !success.payloadChangeRequest) {
|
|
560
|
+
return { ...success, agentToolCalls: work.agentToolCalls };
|
|
561
|
+
}
|
|
562
|
+
const reason = this.isWritesOnly(work)
|
|
563
|
+
? 'complete_task was called with other writes on the same turn. They ran; call complete_task again, on its own, with its final payload change.'
|
|
564
|
+
: 'complete_task was called with other tools on the same turn. They ran first; read their results, then call complete_task on its own if the task is done.';
|
|
565
|
+
return this.withDeclined(work, { toolCallId: complete.call.id, toolName: complete.call.name, reason });
|
|
566
|
+
}
|
|
567
|
+
/** The turn's write calls, in call order, as the step carries them — or nothing when there are none. */
|
|
568
|
+
agentToolCallRequests(calls) {
|
|
569
|
+
if (calls.length === 0) {
|
|
570
|
+
return {};
|
|
571
|
+
}
|
|
572
|
+
return { agentToolCalls: calls.map(({ call }) => ({ toolCallId: call.id, toolName: call.name, arguments: call.arguments ?? {} })) };
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Agent-tool calls with no Action or delegation: the loop runs them, answers each call with its
|
|
576
|
+
* result, and goes again. A Retry with no instructions, so nothing but the results is added —
|
|
577
|
+
* the same non-terminal "go again" the payload-only turn uses.
|
|
578
|
+
*/
|
|
579
|
+
agentToolsStep(agentToolCalls, payloadChangeRequest, payloadToolCallId) {
|
|
580
|
+
return this.createNextStep('Retry', {
|
|
581
|
+
terminate: false,
|
|
582
|
+
agentToolCalls,
|
|
583
|
+
payloadChangeRequest,
|
|
584
|
+
payloadToolCallId,
|
|
585
|
+
retryReason: 'Agent tools ran'
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
/** `ask_user` ends the run as Chat / AwaitingFeedback; it must carry a message. */
|
|
589
|
+
askUserStep(ask) {
|
|
379
590
|
const message = typeof ask.call.arguments?.message === 'string' ? ask.call.arguments.message.trim() : '';
|
|
380
591
|
if (!message) {
|
|
381
592
|
return this.createRetryStep('ask_user requires a message — the question or request for the user.');
|
|
@@ -399,10 +610,7 @@ let LoopAgentType = class LoopAgentType extends BaseAgentType {
|
|
|
399
610
|
* the loop answers this call with the validation feedback, exactly as it answers a
|
|
400
611
|
* payload-only turn.
|
|
401
612
|
*/
|
|
402
|
-
completeTaskStep(complete
|
|
403
|
-
if (totalCalls > 1) {
|
|
404
|
-
return this.createRetryStep('complete_task must be the only call on its turn. Finish any other tool calls first, then call complete_task on its own.');
|
|
405
|
-
}
|
|
613
|
+
completeTaskStep(complete) {
|
|
406
614
|
const message = typeof complete.call.arguments?.message === 'string' ? complete.call.arguments.message.trim() : '';
|
|
407
615
|
const decoded = this.decodePayloadChangeArgument(complete.call.arguments?.payloadChangeRequest);
|
|
408
616
|
if ('error' in decoded) {
|
|
@@ -455,12 +663,24 @@ let LoopAgentType = class LoopAgentType extends BaseAgentType {
|
|
|
455
663
|
}
|
|
456
664
|
/** One sub-agent tool → `subAgent`; several → the parallel `subAgents[]` form. */
|
|
457
665
|
subAgentStep(subAgents, payloadChangeRequest, payloadToolCallId) {
|
|
458
|
-
const requests = subAgents.map(({ call, binding }) =>
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
666
|
+
const requests = subAgents.map(({ call, binding }) => {
|
|
667
|
+
const rawResumeRunId = call.arguments?.resumeRunId;
|
|
668
|
+
const resumeRunId = typeof rawResumeRunId === 'string' && rawResumeRunId.trim().length > 0
|
|
669
|
+
? rawResumeRunId.trim()
|
|
670
|
+
: undefined;
|
|
671
|
+
const rawPresetName = call.arguments?.presetName;
|
|
672
|
+
const presetName = typeof rawPresetName === 'string' && rawPresetName.trim().length > 0
|
|
673
|
+
? rawPresetName.trim()
|
|
674
|
+
: undefined;
|
|
675
|
+
return {
|
|
676
|
+
name: binding.agent.Name,
|
|
677
|
+
message: typeof call.arguments?.message === 'string' ? call.arguments.message : '',
|
|
678
|
+
terminateAfter: call.arguments?.terminateAfter === true,
|
|
679
|
+
...(resumeRunId ? { resumeRunId } : {}),
|
|
680
|
+
...(presetName ? { presetName } : {}),
|
|
681
|
+
toolCallId: call.id
|
|
682
|
+
};
|
|
683
|
+
});
|
|
464
684
|
return this.createNextStep('Sub-Agent', {
|
|
465
685
|
terminate: false,
|
|
466
686
|
...(requests.length === 1 ? { subAgent: requests[0] } : { subAgents: requests }),
|
|
@@ -490,25 +710,62 @@ let LoopAgentType = class LoopAgentType extends BaseAgentType {
|
|
|
490
710
|
* `payload_change_request` alone: apply and continue. Retry is the non-terminal "go again" step
|
|
491
711
|
* (Pipeline uses it the same way); the instructions are what the loop shows the model.
|
|
492
712
|
*/
|
|
493
|
-
payloadOnlyStep(payloadChangeRequest, payloadToolCallId) {
|
|
713
|
+
payloadOnlyStep(payloadChangeRequest, payloadToolCallId, completeTaskDeclared) {
|
|
714
|
+
const finish = completeTaskDeclared ? 'call complete_task' : 'reply in plain text';
|
|
494
715
|
return this.createNextStep('Retry', {
|
|
495
716
|
terminate: false,
|
|
496
717
|
payloadChangeRequest,
|
|
497
718
|
payloadToolCallId,
|
|
498
719
|
retryReason: 'Payload change applied',
|
|
499
|
-
retryInstructions:
|
|
720
|
+
retryInstructions: `Your payload change was applied. Continue: call another tool if there is more to do, or ${finish} when the task is complete.`
|
|
500
721
|
});
|
|
501
722
|
}
|
|
723
|
+
/**
|
|
724
|
+
* What the model is told after a tool call the provider rejected — one it could not read, or one
|
|
725
|
+
* to a tool this turn did not offer — with the provider's description of the call, when it gave
|
|
726
|
+
* one, so the model can see what it sent.
|
|
727
|
+
*/
|
|
728
|
+
rejectedToolCallInstructions(reason, finishMessage, bindings, implicit) {
|
|
729
|
+
const sent = finishMessage ? ` What the provider received: ${finishMessage.length > 400 ? `${finishMessage.slice(0, 400)}…` : finishMessage}` : '';
|
|
730
|
+
if (reason === CHAT_FINISH_REASON_UNEXPECTED_TOOL_CALL) {
|
|
731
|
+
// Only the tools this turn's request carried: a hybrid request has the control and
|
|
732
|
+
// framework tools stripped, and naming one would send the model straight back to it.
|
|
733
|
+
const declared = bindings ? [...bindings.values()].filter((b) => implicit || this.dispatchableOnHybrid(b)).map((b) => b.toolName) : [];
|
|
734
|
+
const offered = declared.length ? ` The tools available on this turn are: ${declared.join(', ')}.` : ' No tools are available on this turn.';
|
|
735
|
+
const otherwise = implicit ? 'reply in plain text' : 'respond with the JSON envelope';
|
|
736
|
+
return `You called a tool that was not available on this turn.${offered} Call one of those, or ${otherwise}.${sent}`;
|
|
737
|
+
}
|
|
738
|
+
// An agent with no payload tool writes through its own tools, so the advice names no tool.
|
|
739
|
+
const split = bindings?.has(PAYLOAD_CHANGE_TOOL) === false
|
|
740
|
+
? 'split a large result into several smaller tool calls rather than one enormous call.'
|
|
741
|
+
: 'write a large result to the payload in pieces across several payload_change_request calls rather than one enormous call.';
|
|
742
|
+
return 'Your tool call could not be read by the provider (malformed function call). Call the tool again '
|
|
743
|
+
+ `with valid JSON arguments, and keep them compact — ${split}${sent}`;
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* What a model on implicit control flow is told after writing JSON that could not be read. It
|
|
747
|
+
* names `complete_task` only when the agent declares it, and the envelope's step types only
|
|
748
|
+
* when the agent still has an envelope.
|
|
749
|
+
*/
|
|
750
|
+
envelopeAttemptInstructions(completeTaskDeclared, nativeOnly) {
|
|
751
|
+
const finish = completeTaskDeclared
|
|
752
|
+
? 'To finish, call complete_task with your answer in message and any payload writes in payloadChangeRequest.'
|
|
753
|
+
: 'To finish, reply with your answer in plain text, with no JSON around it.';
|
|
754
|
+
const json = nativeOnly
|
|
755
|
+
? 'Act only through your tools; do not write JSON.'
|
|
756
|
+
: 'Write JSON only for the nextStep types listed in the response format.';
|
|
757
|
+
return `Your reply looks like a JSON response, but it could not be read and plain text ends the task. ${finish} ${json}`;
|
|
758
|
+
}
|
|
502
759
|
async DetermineNextStep(promptResult, params, payload, agentTypeState, nativeToolBindings) {
|
|
503
760
|
try {
|
|
504
761
|
// A tool call the provider could not read (Gemini's MALFORMED_FUNCTION_CALL — usually an oversized
|
|
505
762
|
// or broken argument object) comes back with NO toolCalls and only the narration that preceded
|
|
506
763
|
// the call. Left alone, under implicit control flow that narration reads as a completion and
|
|
507
764
|
// under the envelope as unparseable JSON; neither tells the model what went wrong. Say so.
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
765
|
+
const choice = promptResult?.chatResult?.data?.choices?.[0];
|
|
766
|
+
if (choice?.finish_reason === CHAT_FINISH_REASON_MALFORMED_TOOL_CALL || choice?.finish_reason === CHAT_FINISH_REASON_UNEXPECTED_TOOL_CALL) {
|
|
767
|
+
const implicit = TurnToolCallingMode(promptResult) === 'NativeImplicit';
|
|
768
|
+
return this.createRetryStep(this.rejectedToolCallInstructions(choice.finish_reason, choice.finishMessage, nativeToolBindings, implicit));
|
|
512
769
|
}
|
|
513
770
|
// Ensure we have a successful result
|
|
514
771
|
if (!promptResult.success || !promptResult.result) {
|
|
@@ -522,7 +779,8 @@ let LoopAgentType = class LoopAgentType extends BaseAgentType {
|
|
|
522
779
|
// it reaches zero — the model answers through whichever channel it was given. So the
|
|
523
780
|
// loop adopts the industry convention: a tool call means "continue", and anything else
|
|
524
781
|
// means the model owes us an envelope.
|
|
525
|
-
const
|
|
782
|
+
const control = ResolveNativeControlConfig(params.agent?.TypeConfiguration).Config;
|
|
783
|
+
const nativeStep = this.nextStepFromNativeToolCalls(promptResult, nativeToolBindings, control.RelaxedTurnShapes);
|
|
526
784
|
if (nativeStep) {
|
|
527
785
|
return nativeStep;
|
|
528
786
|
}
|
|
@@ -532,16 +790,14 @@ let LoopAgentType = class LoopAgentType extends BaseAgentType {
|
|
|
532
790
|
// Implicit control flow: plain text with no tool call IS the terminal
|
|
533
791
|
// form. Only a turn the runner recorded as NativeImplicit reads this way — under the
|
|
534
792
|
// hybrid and the envelope, prose is still the JSON-only Retry below.
|
|
535
|
-
if (promptResult
|
|
793
|
+
if (TurnToolCallingMode(promptResult) === 'NativeImplicit') {
|
|
536
794
|
const text = typeof promptResult.result === 'string' ? promptResult.result.trim()
|
|
537
795
|
: typeof promptResult.rawResult === 'string' ? promptResult.rawResult.trim() : '';
|
|
538
796
|
if (this.looksLikeEnvelopeAttempt(text)) {
|
|
539
797
|
// JSON the envelope parser could not read is an attempted structured answer, not
|
|
540
798
|
// prose. Accepting it as the final answer would end the run with any payload it
|
|
541
799
|
// carried silently dropped.
|
|
542
|
-
return this.createRetryStep(
|
|
543
|
-
'To finish, call complete_task with your answer in message and any payload writes in payloadChangeRequest. ' +
|
|
544
|
-
'Write JSON only for the nextStep types listed in the response format.');
|
|
800
|
+
return this.createRetryStep(this.envelopeAttemptInstructions(nativeToolBindings?.has(COMPLETE_TASK_TOOL) === true, control.NativeOnly));
|
|
545
801
|
}
|
|
546
802
|
if (text.length > 0) {
|
|
547
803
|
LogStatusEx({ message: '✅ Loop Agent (implicit): plain-text completion. ' + text.slice(0, 120), verboseOnly: true });
|
|
@@ -632,7 +888,7 @@ let LoopAgentType = class LoopAgentType extends BaseAgentType {
|
|
|
632
888
|
// Similarly, if a valid finishIf completion gate is attached to an Actions or
|
|
633
889
|
// Sub-Agent step, let the step execute and evaluate the gate instead of
|
|
634
890
|
// short-circuiting to immediate success.
|
|
635
|
-
if (response.taskComplete && !hasClientTools && !hasFinishIfStep) {
|
|
891
|
+
if (response.taskComplete && !hasClientTools && !hasFinishIfStep && response.nextStep?.type !== 'Handoff') {
|
|
636
892
|
LogStatusEx({
|
|
637
893
|
message: '✅ Loop Agent: Task completed successfully. Message: ' + response.message,
|
|
638
894
|
verboseOnly: true
|
|
@@ -681,18 +937,38 @@ let LoopAgentType = class LoopAgentType extends BaseAgentType {
|
|
|
681
937
|
else {
|
|
682
938
|
retVal.step = 'Sub-Agent';
|
|
683
939
|
if (response.nextStep.subAgents && response.nextStep.subAgents.length > 0) {
|
|
684
|
-
retVal.subAgents = response.nextStep.subAgents.map(sa =>
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
940
|
+
retVal.subAgents = response.nextStep.subAgents.map(sa => {
|
|
941
|
+
const resumeRunId = typeof sa.resumeRunId === 'string' && sa.resumeRunId.trim().length > 0
|
|
942
|
+
? sa.resumeRunId.trim()
|
|
943
|
+
: undefined;
|
|
944
|
+
const presetName = typeof sa.presetName === 'string' && sa.presetName.trim().length > 0
|
|
945
|
+
? sa.presetName.trim()
|
|
946
|
+
: undefined;
|
|
947
|
+
return {
|
|
948
|
+
name: sa.name,
|
|
949
|
+
message: sa.message,
|
|
950
|
+
terminateAfter: sa.terminateAfter,
|
|
951
|
+
...(resumeRunId ? { resumeRunId } : {}),
|
|
952
|
+
...(presetName ? { presetName } : {}),
|
|
953
|
+
templateParameters: sa.templateParameters || {}
|
|
954
|
+
};
|
|
955
|
+
});
|
|
690
956
|
}
|
|
691
957
|
else if (response.nextStep.subAgent) {
|
|
958
|
+
const rawResumeRunId = response.nextStep.subAgent.resumeRunId;
|
|
959
|
+
const resumeRunId = typeof rawResumeRunId === 'string' && rawResumeRunId.trim().length > 0
|
|
960
|
+
? rawResumeRunId.trim()
|
|
961
|
+
: undefined;
|
|
962
|
+
const rawPresetName = response.nextStep.subAgent.presetName;
|
|
963
|
+
const presetName = typeof rawPresetName === 'string' && rawPresetName.trim().length > 0
|
|
964
|
+
? rawPresetName.trim()
|
|
965
|
+
: undefined;
|
|
692
966
|
retVal.subAgent = {
|
|
693
967
|
name: response.nextStep.subAgent.name,
|
|
694
968
|
message: response.nextStep.subAgent.message,
|
|
695
969
|
terminateAfter: response.nextStep.subAgent.terminateAfter,
|
|
970
|
+
...(resumeRunId ? { resumeRunId } : {}),
|
|
971
|
+
...(presetName ? { presetName } : {}),
|
|
696
972
|
templateParameters: response.nextStep.subAgent.templateParameters || {}
|
|
697
973
|
};
|
|
698
974
|
}
|
|
@@ -793,6 +1069,9 @@ let LoopAgentType = class LoopAgentType extends BaseAgentType {
|
|
|
793
1069
|
case 'Tasks':
|
|
794
1070
|
this.applyTasksStep(retVal, response.nextStep.tasks, params);
|
|
795
1071
|
break;
|
|
1072
|
+
case 'Handoff':
|
|
1073
|
+
this.applyHandoffStep(retVal, response.nextStep.handoff, response.message, params);
|
|
1074
|
+
break;
|
|
796
1075
|
default:
|
|
797
1076
|
retVal.step = 'Retry';
|
|
798
1077
|
retVal.errorMessage = `Unknown next step type: ${response.nextStep.type}`;
|
|
@@ -939,6 +1218,10 @@ let LoopAgentType = class LoopAgentType extends BaseAgentType {
|
|
|
939
1218
|
response.nextStep.type = 'Tasks'; // update the data structure to have the correct type
|
|
940
1219
|
lcaseType = 'tasks';
|
|
941
1220
|
}
|
|
1221
|
+
else if (!lcaseType && response.nextStep.handoff) {
|
|
1222
|
+
response.nextStep.type = 'Handoff'; // update the data structure to have the correct type
|
|
1223
|
+
lcaseType = 'handoff';
|
|
1224
|
+
}
|
|
942
1225
|
if (!validStepTypes.includes(lcaseType)) {
|
|
943
1226
|
const message = `LoopAgentResponse has invalid nextStep.type: ${response.nextStep.type}`;
|
|
944
1227
|
LogError(message);
|