@memberjunction/ai-agents 6.2.0-edge.2 → 6.2.0-edge.4

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.
Files changed (148) hide show
  1. package/README.md +6 -0
  2. package/dist/AgentDecisionService.d.ts +8 -1
  3. package/dist/AgentDecisionService.d.ts.map +1 -1
  4. package/dist/AgentDecisionService.js +4 -0
  5. package/dist/AgentDecisionService.js.map +1 -1
  6. package/dist/AgentRunner.d.ts +51 -2
  7. package/dist/AgentRunner.d.ts.map +1 -1
  8. package/dist/AgentRunner.js +121 -23
  9. package/dist/AgentRunner.js.map +1 -1
  10. package/dist/ConversationCompactionManager.d.ts +9 -1
  11. package/dist/ConversationCompactionManager.d.ts.map +1 -1
  12. package/dist/ConversationCompactionManager.js +6 -3
  13. package/dist/ConversationCompactionManager.js.map +1 -1
  14. package/dist/ConversationToolManager.d.ts +13 -2
  15. package/dist/ConversationToolManager.d.ts.map +1 -1
  16. package/dist/ConversationToolManager.js +19 -3
  17. package/dist/ConversationToolManager.js.map +1 -1
  18. package/dist/KnowledgeAgent.d.ts.map +1 -1
  19. package/dist/KnowledgeAgent.js +6 -1
  20. package/dist/KnowledgeAgent.js.map +1 -1
  21. package/dist/MJAIAgentRequestEntityServer.d.ts +6 -0
  22. package/dist/MJAIAgentRequestEntityServer.d.ts.map +1 -1
  23. package/dist/MJAIAgentRequestEntityServer.js +26 -1
  24. package/dist/MJAIAgentRequestEntityServer.js.map +1 -1
  25. package/dist/PayloadFeedbackManager.d.ts +3 -0
  26. package/dist/PayloadFeedbackManager.d.ts.map +1 -1
  27. package/dist/PayloadFeedbackManager.js +2 -1
  28. package/dist/PayloadFeedbackManager.js.map +1 -1
  29. package/dist/agent-run-watchdog.d.ts +65 -5
  30. package/dist/agent-run-watchdog.d.ts.map +1 -1
  31. package/dist/agent-run-watchdog.js +143 -28
  32. package/dist/agent-run-watchdog.js.map +1 -1
  33. package/dist/agent-types/loop-agent-prompt-params.d.ts +7 -0
  34. package/dist/agent-types/loop-agent-prompt-params.d.ts.map +1 -1
  35. package/dist/agent-types/loop-agent-prompt-params.js +1 -0
  36. package/dist/agent-types/loop-agent-prompt-params.js.map +1 -1
  37. package/dist/agent-types/loop-agent-type.d.ts +20 -0
  38. package/dist/agent-types/loop-agent-type.d.ts.map +1 -1
  39. package/dist/agent-types/loop-agent-type.js +73 -2
  40. package/dist/agent-types/loop-agent-type.js.map +1 -1
  41. package/dist/artifact-tools/SearchResultSetToolLibrary.js +4 -4
  42. package/dist/artifact-tools/SearchResultSetToolLibrary.js.map +1 -1
  43. package/dist/base-agent.d.ts +310 -26
  44. package/dist/base-agent.d.ts.map +1 -1
  45. package/dist/base-agent.js +867 -244
  46. package/dist/base-agent.js.map +1 -1
  47. package/dist/client-tool-results.d.ts +45 -0
  48. package/dist/client-tool-results.d.ts.map +1 -0
  49. package/dist/client-tool-results.js +94 -0
  50. package/dist/client-tool-results.js.map +1 -0
  51. package/dist/index.d.ts +9 -0
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +9 -0
  54. package/dist/index.js.map +1 -1
  55. package/dist/native-tools/action-tool-builder.d.ts +14 -0
  56. package/dist/native-tools/action-tool-builder.d.ts.map +1 -1
  57. package/dist/native-tools/action-tool-builder.js +62 -7
  58. package/dist/native-tools/action-tool-builder.js.map +1 -1
  59. package/dist/native-tools/control-tools.d.ts +17 -1
  60. package/dist/native-tools/control-tools.d.ts.map +1 -1
  61. package/dist/native-tools/control-tools.js +40 -3
  62. package/dist/native-tools/control-tools.js.map +1 -1
  63. package/dist/prior-turn-tool-result-cache.d.ts +31 -12
  64. package/dist/prior-turn-tool-result-cache.d.ts.map +1 -1
  65. package/dist/prior-turn-tool-result-cache.js +59 -16
  66. package/dist/prior-turn-tool-result-cache.js.map +1 -1
  67. package/dist/realtime/bridge-host-params.d.ts +22 -0
  68. package/dist/realtime/bridge-host-params.d.ts.map +1 -0
  69. package/dist/realtime/bridge-host-params.js +53 -0
  70. package/dist/realtime/bridge-host-params.js.map +1 -0
  71. package/dist/realtime/bridge-realtime-session-factory.d.ts +63 -3
  72. package/dist/realtime/bridge-realtime-session-factory.d.ts.map +1 -1
  73. package/dist/realtime/bridge-realtime-session-factory.js +83 -22
  74. package/dist/realtime/bridge-realtime-session-factory.js.map +1 -1
  75. package/dist/realtime/bridge-realtime-usage-recorder.d.ts +81 -0
  76. package/dist/realtime/bridge-realtime-usage-recorder.d.ts.map +1 -0
  77. package/dist/realtime/bridge-realtime-usage-recorder.js +194 -0
  78. package/dist/realtime/bridge-realtime-usage-recorder.js.map +1 -0
  79. package/dist/realtime/bridge-session-transcript-sink.d.ts +37 -0
  80. package/dist/realtime/bridge-session-transcript-sink.d.ts.map +1 -0
  81. package/dist/realtime/bridge-session-transcript-sink.js +58 -0
  82. package/dist/realtime/bridge-session-transcript-sink.js.map +1 -0
  83. package/dist/realtime/client-only-channel-server.d.ts +83 -0
  84. package/dist/realtime/client-only-channel-server.d.ts.map +1 -0
  85. package/dist/realtime/client-only-channel-server.js +107 -0
  86. package/dist/realtime/client-only-channel-server.js.map +1 -0
  87. package/dist/realtime/identity-verification-channel-server.d.ts +50 -0
  88. package/dist/realtime/identity-verification-channel-server.d.ts.map +1 -0
  89. package/dist/realtime/identity-verification-channel-server.js +66 -0
  90. package/dist/realtime/identity-verification-channel-server.js.map +1 -0
  91. package/dist/realtime/interactive-component-channel-server.d.ts +39 -0
  92. package/dist/realtime/interactive-component-channel-server.d.ts.map +1 -0
  93. package/dist/realtime/interactive-component-channel-server.js +55 -0
  94. package/dist/realtime/interactive-component-channel-server.js.map +1 -0
  95. package/dist/realtime/realtime-avatar-resolution.d.ts +194 -0
  96. package/dist/realtime/realtime-avatar-resolution.d.ts.map +1 -0
  97. package/dist/realtime/realtime-avatar-resolution.js +208 -0
  98. package/dist/realtime/realtime-avatar-resolution.js.map +1 -0
  99. package/dist/realtime/realtime-channel-policy.d.ts +81 -0
  100. package/dist/realtime/realtime-channel-policy.d.ts.map +1 -0
  101. package/dist/realtime/realtime-channel-policy.js +91 -0
  102. package/dist/realtime/realtime-channel-policy.js.map +1 -0
  103. package/dist/realtime/realtime-channel-server-host.d.ts +14 -0
  104. package/dist/realtime/realtime-channel-server-host.d.ts.map +1 -1
  105. package/dist/realtime/realtime-channel-server-host.js +35 -0
  106. package/dist/realtime/realtime-channel-server-host.js.map +1 -1
  107. package/dist/realtime/realtime-client-session-service.d.ts +493 -30
  108. package/dist/realtime/realtime-client-session-service.d.ts.map +1 -1
  109. package/dist/realtime/realtime-client-session-service.js +825 -98
  110. package/dist/realtime/realtime-client-session-service.js.map +1 -1
  111. package/dist/realtime/realtime-coagent-config.d.ts +94 -15
  112. package/dist/realtime/realtime-coagent-config.d.ts.map +1 -1
  113. package/dist/realtime/realtime-coagent-config.js +109 -4
  114. package/dist/realtime/realtime-coagent-config.js.map +1 -1
  115. package/dist/realtime/realtime-coagent-resolution.d.ts +90 -0
  116. package/dist/realtime/realtime-coagent-resolution.d.ts.map +1 -0
  117. package/dist/realtime/realtime-coagent-resolution.js +186 -0
  118. package/dist/realtime/realtime-coagent-resolution.js.map +1 -0
  119. package/dist/realtime/realtime-delegation-narrator.d.ts +97 -0
  120. package/dist/realtime/realtime-delegation-narrator.d.ts.map +1 -0
  121. package/dist/realtime/realtime-delegation-narrator.js +162 -0
  122. package/dist/realtime/realtime-delegation-narrator.js.map +1 -0
  123. package/dist/realtime/realtime-recording-store.d.ts +136 -16
  124. package/dist/realtime/realtime-recording-store.d.ts.map +1 -1
  125. package/dist/realtime/realtime-recording-store.js +505 -39
  126. package/dist/realtime/realtime-recording-store.js.map +1 -1
  127. package/dist/realtime/realtime-session-runner.d.ts +2 -82
  128. package/dist/realtime/realtime-session-runner.d.ts.map +1 -1
  129. package/dist/realtime/realtime-session-runner.js +16 -191
  130. package/dist/realtime/realtime-session-runner.js.map +1 -1
  131. package/dist/realtime/realtime-vendor-resolution.d.ts +9 -0
  132. package/dist/realtime/realtime-vendor-resolution.d.ts.map +1 -1
  133. package/dist/realtime/realtime-vendor-resolution.js +16 -5
  134. package/dist/realtime/realtime-vendor-resolution.js.map +1 -1
  135. package/dist/realtime/realtime-video-output-gate.d.ts +83 -0
  136. package/dist/realtime/realtime-video-output-gate.d.ts.map +1 -0
  137. package/dist/realtime/realtime-video-output-gate.js +79 -0
  138. package/dist/realtime/realtime-video-output-gate.js.map +1 -0
  139. package/dist/rubric-evaluation-agent-runner.js +17 -8
  140. package/dist/rubric-evaluation-agent-runner.js.map +1 -1
  141. package/dist/self-check.d.ts +6 -3
  142. package/dist/self-check.d.ts.map +1 -1
  143. package/dist/self-check.js +3 -3
  144. package/dist/self-check.js.map +1 -1
  145. package/dist/tool-result-format.d.ts +14 -0
  146. package/dist/tool-result-format.d.ts.map +1 -1
  147. package/dist/tool-result-format.js.map +1 -1
  148. package/package.json +19 -19
@@ -10,7 +10,7 @@
10
10
  * @author MemberJunction.com
11
11
  * @since 2.49.0
12
12
  */
13
- import { MJAIAgentTypeEntity, MJTemplateParamEntity, MJAIAgentRelationshipEntity, MJAIAgentNoteEntity, MJAIAgentExampleEntity, MJAISkillEntity, MJAIVendorEntity } from '@memberjunction/core-entities';
13
+ import { MJAIAgentTypeEntity, MJTemplateParamEntity, MJAIAgentRelationshipEntity, MJAIAgentNoteEntity, MJAIAgentExampleEntity, MJAISkillEntity, MJAIVendorEntity, type ConversationBranchRow } from '@memberjunction/core-entities';
14
14
  import { type NativeToolBinding } from './native-tools/control-tools.js';
15
15
  import { MJAIAgentRunEntityExtended, MJAIAgentRunStepEntityExtended, MJAIPromptEntityExtended, MJAIAgentEntityExtended, MJAIModelEntityExtended, MJAIPromptRunEntityExtended } from "@memberjunction/ai-core-plus";
16
16
  import { UserInfo, IMetadataProvider } from '@memberjunction/core';
@@ -24,9 +24,9 @@ import { AIEngine } from '@memberjunction/aiengine';
24
24
  import { AgentMemoryObservability } from './agent-memory-context-builder.js';
25
25
  import { CompactionOutcome, EffectiveContextBudget } from './ConversationCompactionManager.js';
26
26
  import { ConversationToolCall, ConversationToolExecutionResult, ConversationToolSummaryHost } from './ConversationToolManager.js';
27
- import { CarryForwardStepRecord } from './tool-result-format.js';
27
+ import { CarryForwardStepRecord, StoppedRunStepRecord } from './tool-result-format.js';
28
28
  import { AgentPreExecutionRAGResult } from './agent-pre-execution-rag.js';
29
- import { AIPromptParams, AIPromptRunResult, ExecuteAgentParams, AgentConfiguration, ExecuteAgentResult, AgentAction, AgentSubAgentRequest, BaseAgentNextStep, MessageLifecycleEvent, AgentChatMessage, AgentChatMessageMetadata, AIModelSelectionInfo, ActionChange, ActionChangeScope, SubAgentChange, MediaOutput, FileOutputRef, SecondaryScopeConfig, SecondaryScopeValue, AgentResponseForm, AgentPipelineRequest, AgentSkillActivationRequest, AgentSkillInvocation, SkillAvailabilityPurpose, AgentDecisionRequest, AgentDecisionResult, AgentDecisionAnswerSummary } from '@memberjunction/ai-core-plus';
29
+ import { AIPromptParams, AIPromptRunResult, ExecuteAgentParams, AgentConfiguration, ExecuteAgentResult, AgentAction, AgentSubAgentRequest, BaseAgentNextStep, MessageLifecycleEvent, AgentChatMessage, AgentChatMessageMetadata, AIModelSelectionInfo, ActionChange, ActionChangeScope, SubAgentChange, MediaOutput, FileOutputRef, SecondaryScopeConfig, SecondaryScopeValue, AgentResponseForm, AgentPipelineRequest, AgentSkillActivationRequest, AgentSkillInvocation, SkillAvailabilityPurpose, AgentDecisionRequest, AgentDecisionResult, AgentDecisionAnswerSummary, StopContinuationMode } from '@memberjunction/ai-core-plus';
30
30
  import { MJActionEntityExtended, ActionResult, ActionParam, AIDirective } from '@memberjunction/actions-base';
31
31
  import { RuntimeStateDateTime, RuntimeStateScratchpad } from './runtime-state-fragment.js';
32
32
  import { ArtifactToolCall, StoredToolResult } from './ArtifactToolManager.js';
@@ -37,6 +37,21 @@ import { PipelineToolRegistry, PipelineExecutionResult } from './pipeline/index.
37
37
  * Compact representation of a single action's execution result, used for
38
38
  * building the markdown summary that goes into conversation messages.
39
39
  */
40
+ /**
41
+ * A stopped run's step with its outcome. The full-stack resume reads every step of the run, not
42
+ * only completed results: it needs the prompt steps' recorded message stacks, and it needs to
43
+ * know which requested actions finished before the stop.
44
+ */
45
+ export interface StoppedRunStackStepRecord extends StoppedRunStepRecord {
46
+ Status: MJAIAgentRunStepEntityExtended['Status'];
47
+ Success: MJAIAgentRunStepEntityExtended['Success'];
48
+ }
49
+ /** What the pre-execution phase loaded about a user-stopped predecessor, applied once the phase settles. */
50
+ interface StoppedRunContinuation {
51
+ RunID: string;
52
+ Mode: StopContinuationMode;
53
+ Steps: StoppedRunStackStepRecord[];
54
+ }
40
55
  interface ActionResultSummary {
41
56
  actionName: string;
42
57
  success: boolean;
@@ -388,6 +403,19 @@ export declare class BaseAgent {
388
403
  */
389
404
  protected static readonly DEFAULT_ABSOLUTE_MAX_ITERATIONS = 5000;
390
405
  private _agentRun;
406
+ /**
407
+ * The prefix of the abort reason the wall-clock guard in {@link Execute} raises when a run
408
+ * outlives `maxExecutionTimeMs`. The guard appends the agent and the budget after it; a reader
409
+ * ({@link CancellationReasonForAbort}) checks the prefix, never the wording after it.
410
+ */
411
+ static readonly AgentTimeoutAbortReason = "Agent execution exceeded maxExecutionTimeMs";
412
+ /**
413
+ * The abort controller that governs the current `Execute` call (the merged timeout/upstream
414
+ * signal). Held so {@link initializeAgentRun} can register it with the watchdog's stop relay:
415
+ * when someone marks this run's row `Cancelled`, the watchdog aborts it and the loop's
416
+ * existing cancellation checks end the run. Null outside an execution.
417
+ */
418
+ private _runAbortController;
391
419
  /**
392
420
  * The task graph this run submitted and is now waiting on, or null.
393
421
  *
@@ -677,6 +705,11 @@ export declare class BaseAgent {
677
705
  * Armed only when the run has a conversationId (the cross-turn context gate).
678
706
  */
679
707
  private _conversationToolManager;
708
+ /**
709
+ * The conversation's branch rows for the current run, loaded once when the run is on a
710
+ * branch (`ExecuteAgentParams.ConversationBranchID`). Empty on the trunk.
711
+ */
712
+ private _conversationBranches;
680
713
  /**
681
714
  * Manages in-flight durable memory writes for the current agent run.
682
715
  * Only consulted when the agent has AllowMemoryWrite enabled.
@@ -719,6 +752,12 @@ export declare class BaseAgent {
719
752
  * @private
720
753
  */
721
754
  private _openingRequest;
755
+ /**
756
+ * The run's {@link AIPromptExecutionScope}, recorded when the run starts, for decision calls made
757
+ * from helpers that are not handed the run's params (discovery, catalog narrowing).
758
+ * @private
759
+ */
760
+ private _runExecutionScope;
722
761
  /**
723
762
  * Whether the run answers its conversation's opening request ({@link IsOpeningTurn}), read from
724
763
  * the messages it started with. Decision discovery asks about no other turn.
@@ -1047,7 +1086,8 @@ export declare class BaseAgent {
1047
1086
  * without provider SDKs or DB metadata.
1048
1087
  *
1049
1088
  * Production resolution: pick the highest-power active model of AIModelType `Realtime`; then
1050
- * pick its highest-priority active vendor whose `DriverClass` has a resolvable API key; then
1089
+ * pick its highest-priority active vendor whose `DriverClass` has a resolvable API key, unless another keyed
1090
+ * vendor matches whether the run will show an avatar better ({@link ChooseRealtimeVendorForAvatar}); then
1051
1091
  * instantiate the driver via the `ClassFactory`. Returns `null` (never throws) if any step
1052
1092
  * can't be satisfied — the caller turns that into a clean FAILED result. (Per-agent realtime
1053
1093
  * model preference can later be wired through the agent's prompt-model config, the same path
@@ -1064,6 +1104,19 @@ export declare class BaseAgent {
1064
1104
  apiName: string;
1065
1105
  driverClass?: string;
1066
1106
  } | null>;
1107
+ /**
1108
+ * Whether a session-driven run will show an avatar: the agent's video setting is on and the run could show one
1109
+ * ({@link RealtimeSessionCanShowAvatar}) — a server-side session, so only when its host publishes the avatar into a
1110
+ * room (`params.data.realtimeAvatarDelivery` `'room'`) and it is not a phone call (`params.data.realtimePhoneCall`).
1111
+ *
1112
+ * @param params The execution parameters.
1113
+ */
1114
+ private realtimeRunShowsAvatar;
1115
+ /**
1116
+ * A vendor's realtime driver on its key, with the model and vendor identifiers a run resolves to; `null` when the
1117
+ * key or the driver is missing.
1118
+ */
1119
+ private instantiateRealtimeRunVendor;
1067
1120
  /**
1068
1121
  * The active `Realtime`-AIModelType models to try, in resolution order — the candidate list
1069
1122
  * {@link resolveRealtimeModel} walks until one yields a usable vendor + key + driver. Returns ALL
@@ -1668,15 +1721,22 @@ export declare class BaseAgent {
1668
1721
  /**
1669
1722
  * The `tool_choice` for this turn (§8.3).
1670
1723
  *
1671
- * `'auto'` normally, `'none'` on the last turn this run will be allowed.
1724
+ * `'auto'` normally; on the last turn this run will be allowed, a forced `complete_task` call.
1672
1725
  *
1673
1726
  * **Why the final turn is special.** A tool call is a request to continue: the framework runs
1674
1727
  * the action, feeds the result back, and the model decides again. On the last permitted
1675
1728
  * iteration there is no "again" — the limit check fires the moment the turn returns, so the
1676
1729
  * action is executed, paid for, and its result discarded, and the run ends with no answer for
1677
1730
  * the user because the model spent its last turn asking a question instead of answering one.
1678
- * Forcing `'none'` converts that turn into what the framework actually needs from it: a
1679
- * terminal envelope.
1731
+ * The final turn is forced to what the framework actually needs from it: a terminal answer.
1732
+ *
1733
+ * **Why `complete_task` and not `'none'`.** Under implicit control flow, `'none'` forbids the
1734
+ * model's only way to store its result — `payload_change_request` and `complete_task` are tools
1735
+ * too — so a forced `'none'` turn can end the run but never deliver the payload. Naming
1736
+ * `complete_task` forces the one call that does both. A model that is NOT on implicit control
1737
+ * flow never receives `complete_task` (the runner strips control tools), and the runner then
1738
+ * downgrades the named choice to `'none'`: the envelope turn the hybrid needs. Providers also
1739
+ * enforce a named choice more reliably than `'none'`.
1680
1740
  *
1681
1741
  * **What this does NOT fix.** Models call a tool on a measurable share of turns whose right
1682
1742
  * answer was chat, completion or delegation. Those are not predictable
@@ -1684,11 +1744,11 @@ export declare class BaseAgent {
1684
1744
  * address them. That belongs to the prompt, and is why the native-mode Actions section names
1685
1745
  * the cases explicitly.
1686
1746
  *
1687
- * Subclasses may narrow this further; the base contract is that a forced `'none'` must never be
1688
- * relaxed to `'auto'` on a turn the framework has already decided is terminal.
1747
+ * Subclasses may narrow this further; the base contract is that a forced terminal choice must
1748
+ * never be relaxed to `'auto'` on a turn the framework has already decided is terminal.
1689
1749
  *
1690
1750
  * @param params The run parameters, for the per-run iteration override
1691
- * @returns `'none'` on the final permitted iteration, otherwise `'auto'`
1751
+ * @returns `{ name: 'complete_task' }` on the final permitted iteration, otherwise `'auto'`
1692
1752
  */
1693
1753
  protected resolveToolChoiceForTurn(params: ExecuteAgentParams): ChatToolChoice;
1694
1754
  /**
@@ -2063,7 +2123,8 @@ export declare class BaseAgent {
2063
2123
  };
2064
2124
  /**
2065
2125
  * Converts ChatMessageContent to a string representation.
2066
- * Handles both simple strings and content block arrays.
2126
+ * Handles both simple strings and content block arrays. Text blocks keep their text;
2127
+ * image, audio, video and file blocks become a short stub instead of their base64.
2067
2128
  *
2068
2129
  * @param content - The message content to convert
2069
2130
  * @returns String representation of the content
@@ -2208,6 +2269,8 @@ export declare class BaseAgent {
2208
2269
  * @protected
2209
2270
  */
2210
2271
  protected processNextStep<P>(nextStep: BaseAgentNextStep<P>, params: ExecuteAgentParams, agentType: MJAIAgentTypeEntity, promptResult: AIPromptRunResult, currentPayload: P, currentStep: MJAIAgentRunStepEntityExtended): Promise<BaseAgentNextStep<P>>;
2272
+ /** The tool name the model used for a call on this turn — `payload_change_request` when it cannot be found. */
2273
+ private nativeToolNameForCall;
2211
2274
  /**
2212
2275
  * Executes a batch of artifact tool calls, recording each as its own
2213
2276
  * `Tool` AIAgentRunStep (a sibling of the Prompt step that requested them)
@@ -2237,6 +2300,174 @@ export declare class BaseAgent {
2237
2300
  * @protected
2238
2301
  */
2239
2302
  protected injectPriorTurnToolResults(params: ExecuteAgentParams): Promise<void>;
2303
+ /**
2304
+ * Carries a STOPPED previous turn's completed results forward into this run's context.
2305
+ *
2306
+ * {@link injectPriorTurnToolResults} covers the normal case: the previous run settled and
2307
+ * its inline tool results ride along one turn. A run the user stopped never settles, so
2308
+ * that path skips it, and the next turn would redo every action the stopped run had already
2309
+ * finished (observed: a stopped Sage run had five weather lookups and fifteen searches done;
2310
+ * "keep going" redid all of them). This path looks at the newest root run for this agent in
2311
+ * the conversation and, when it is one the user stopped, carries it forward per
2312
+ * {@link ExecuteAgentParams.stopContinuationMode}: by default its own message stack is resumed
2313
+ * so the agent picks up where it stopped; in summary mode its completed Actions and Tool results
2314
+ * go in as one transient message that says to continue, not restart. A settled newest run means
2315
+ * the normal path already has the context, so nothing is added here. During execution the two
2316
+ * halves run separately: {@link loadStoppedRunContinuation} in the parallel phase, then
2317
+ * {@link applyStoppedRunContinuation} once it settles.
2318
+ *
2319
+ * Same gates as the sibling: root depth, a conversation, no history floor. Fail-soft.
2320
+ * @protected
2321
+ */
2322
+ protected injectStoppedRunResults(params: ExecuteAgentParams): Promise<void>;
2323
+ /**
2324
+ * The I/O half of {@link injectStoppedRunResults}: finds a user-stopped predecessor and loads its
2325
+ * steps (every step for the full-stack resume, only completed results for the summary). Runs inside
2326
+ * the pre-execution parallel phase; nothing here touches the message list.
2327
+ * @protected
2328
+ */
2329
+ protected loadStoppedRunContinuation(params: ExecuteAgentParams): Promise<StoppedRunContinuation | null>;
2330
+ /**
2331
+ * The message half of {@link injectStoppedRunResults}, applied once the pre-execution phase has
2332
+ * settled so it never races the memory and RAG injections running beside the load.
2333
+ *
2334
+ * Full stack: the stopped run's own turns are spliced in ahead of the user's new message, in the
2335
+ * shape the loop built while running, so the agent resumes where it stopped. When the stack cannot
2336
+ * be resumed (no recorded prompt, or its anchor is missing) this falls back to the summary.
2337
+ * Summary: the completed results go in as one carried-forward message. Fail-soft.
2338
+ * @protected
2339
+ */
2340
+ protected applyStoppedRunContinuation(params: ExecuteAgentParams, continuation: StoppedRunContinuation | null, continuationMessage: ChatMessage | undefined): void;
2341
+ /**
2342
+ * The full-stack half of {@link applyStoppedRunContinuation}: true when the stopped run's turns were
2343
+ * spliced in. Any failure leaves the messages untouched and returns false, so the caller carries
2344
+ * the results as a summary instead of losing them.
2345
+ * @private
2346
+ */
2347
+ private tryResumeStoppedRunStack;
2348
+ /** The mode a run uses when the caller does not set {@link ExecuteAgentParams.stopContinuationMode}. */
2349
+ static readonly DefaultStopContinuationMode: StopContinuationMode;
2350
+ /**
2351
+ * Placed just before the user's new message when a stopped run's stack is resumed, so the model
2352
+ * knows the turns above it were interrupted and what follows is how to continue.
2353
+ */
2354
+ static readonly StoppedRunResumeNotice = "[Note: The user stopped the previous execution at this point. The instruction that follows is the continuation request.]";
2355
+ /** Result code and message for an action the stopped run requested but never ran. */
2356
+ private static readonly stoppedBeforeRunResultCode;
2357
+ private static readonly stoppedBeforeRunMessage;
2358
+ /**
2359
+ * The stopped run's turns in the shape the loop builds, or null when they cannot be recovered.
2360
+ *
2361
+ * The last prompt step recorded the run's whole message stack as it went into that prompt; the
2362
+ * first prompt step recorded the stack the run started from (history plus this run's injections,
2363
+ * which the new run adds for itself). The difference is the run's own turns. If the last prompt
2364
+ * completed, its decision and the steps after it are rebuilt with the loop's own builders.
2365
+ * @protected
2366
+ */
2367
+ protected buildResumedStoppedRunTurns(steps: StoppedRunStackStepRecord[], params: ExecuteAgentParams): AgentChatMessage[] | null;
2368
+ /**
2369
+ * The run's own turns: what follows the run's starting message in its last recorded stack, minus
2370
+ * the per-request runtime-state fragments (the new run appends its own). The starting message is
2371
+ * matched at its original position first, so a repeated message earlier in the history ("keep
2372
+ * going" twice) cannot be mistaken for it. Null when it cannot be found.
2373
+ */
2374
+ static ExtractStoppedRunLoopTurns(firstStack: AgentChatMessage[] | null, lastStack: AgentChatMessage[] | null): AgentChatMessage[] | null;
2375
+ /**
2376
+ * Inserts resumed turns ahead of the user's new message (and ahead of the stopped run's own reply
2377
+ * to the user, when that sits right before it), followed by {@link StoppedRunResumeNotice}. The new
2378
+ * message is found by identity, captured before the pre-execution phase added anything. Returns
2379
+ * false, changing nothing, when it is not a user message still in the list.
2380
+ */
2381
+ static SpliceResumedTurns(messages: ChatMessage[], resumed: AgentChatMessage[], continuationMessage: ChatMessage | undefined): boolean;
2382
+ /**
2383
+ * What the stopped run's last completed prompt decided, rebuilt as the loop would have written it:
2384
+ * the model's native call turn when results go back natively, the invocation record and the results
2385
+ * of the actions that finished (and a not-executed result for the ones that did not) for an Actions
2386
+ * turn, otherwise the completed results as a carried-forward message. Any native call left without
2387
+ * a result is then answered, so the history is valid for every provider.
2388
+ * @protected
2389
+ */
2390
+ protected buildStoppedRunTail(decision: BaseAgentNextStep | null, tailSteps: StoppedRunStackStepRecord[], params: ExecuteAgentParams): AgentChatMessage[];
2391
+ /** One result per requested action, in request order: its completed step's result, or not executed. @private */
2392
+ private summarizeStoppedRunActions;
2393
+ /**
2394
+ * A completed action step as the loop summarizes a live action result: output parameters only,
2395
+ * with large media swapped for placeholders. Null when the step's output cannot be read.
2396
+ * @private
2397
+ */
2398
+ private summarizeStoppedActionStep;
2399
+ /** The message stack a prompt step recorded as its input, or null. @private */
2400
+ private static readPromptStepStack;
2401
+ /** The decision a completed prompt step recorded, or null. @private */
2402
+ private static readPromptStepDecision;
2403
+ /** The action an Actions step ran, from its recorded input, or null. @private */
2404
+ private static readStoppedActionName;
2405
+ /**
2406
+ * A resumed turn re-dated to this run's first turn. The stopped run's turn numbers mean nothing
2407
+ * to this run's counter, and expiry compares the two, so a resumed result ages from now.
2408
+ * @private
2409
+ */
2410
+ private static restampResumedTurn;
2411
+ /** A step whose result the summary carries: a completed, successful Actions or Tool step. @private */
2412
+ private static isCarriedForwardResultStep;
2413
+ /**
2414
+ * A carried-forward results message: a user-role message that expires after two turns and
2415
+ * compacts to its head, so results reused once never compound across the conversation. Shared
2416
+ * by the settled-run and stopped-run carry-forwards so the two cannot age differently.
2417
+ * @private
2418
+ */
2419
+ private buildCarryForwardMessage;
2420
+ /**
2421
+ * The ID of this agent's newest root run on this turn's branch path IF the user stopped it,
2422
+ * else null. One query over the runs that could be the predecessor (settled, or stopped by
2423
+ * the user): the newest decides. A stopped run older than a settled one is history the
2424
+ * settled run already built on, so it is not carried again. The path scopes it the same way
2425
+ * as {@link loadPriorTurnToolResultSteps}: a run stopped on a sibling branch is never resumed.
2426
+ * @private
2427
+ */
2428
+ private findUserStoppedPredecessorRunId;
2429
+ /**
2430
+ * `runId` if that run is one the user stopped, else null. The chained-run counterpart of
2431
+ * {@link findUserStoppedPredecessorRunId}: one primary-key read of the named run instead of a
2432
+ * search of the conversation, so a run the resolver already resolved is not looked up twice,
2433
+ * and a run chained to a settled predecessor (an ordinary continuation) resumes nothing.
2434
+ * @private
2435
+ */
2436
+ private userStoppedRunIdIfStopped;
2437
+ /**
2438
+ * Every step of a stopped run, in step order: the full-stack resume reads the prompt steps'
2439
+ * recorded stacks and which requested actions completed. Read from the database, since the run
2440
+ * was stopped moments ago.
2441
+ * @private
2442
+ */
2443
+ private loadStoppedRunStack;
2444
+ /** The completed, successful Actions and Tool steps of a stopped run, in step order. @private */
2445
+ private loadStoppedRunResultSteps;
2446
+ /**
2447
+ * Budget for the stopped-run carry-forward message. Smaller than a standalone tool result on
2448
+ * purpose: this rides at the front of a continuation turn's context, and a stopped run can
2449
+ * hold dozens of search results. ~7k tokens keeps the useful values and drops the long tails.
2450
+ */
2451
+ protected static readonly maxStoppedRunResultChars = 28000;
2452
+ /**
2453
+ * Renders a stopped run's completed step results into the carried-forward message body.
2454
+ * Pure and static for testability. An Actions step renders as the action call (name and
2455
+ * params) with its output parameters, or its message when it produced none; a Tool step
2456
+ * renders under the same contract as {@link BuildPriorTurnToolResultsMessage}. Failed or
2457
+ * unparseable steps are skipped. Each section is capped at an even share of `maxChars`
2458
+ * (never below a readable floor) and the whole body at `maxChars`, with a note for anything
2459
+ * dropped. Returns null when nothing usable remains.
2460
+ */
2461
+ static BuildStoppedRunResultsMessage(steps: ReadonlyArray<StoppedRunStepRecord>, maxChars: number): string | null;
2462
+ /** One stopped-run step as a result section, or null when it carries nothing reusable. @private */
2463
+ private static renderStoppedRunStep;
2464
+ /**
2465
+ * The `MJ: AI Agent Runs` predicate for this agent's previous settled root run on one
2466
+ * branch path: the run's reply row must be on that path, so a run made on a sibling
2467
+ * branch is never carried forward, and not replaced by a rerun of its turn, so a replaced
2468
+ * answer's tool results are never carried forward.
2469
+ */
2470
+ static BuildPriorTurnRunFilter(conversationId: string, agentId: string, branchId: string | null, branches: ReadonlyArray<ConversationBranchRow>, statusList: string): string;
2240
2471
  /**
2241
2472
  * Loads this agent's previous settled root run's Tool steps for this conversation
2242
2473
  * (settled = {@link settledRunStatuses}: Completed or AwaitingFeedback).
@@ -2259,9 +2490,11 @@ export declare class BaseAgent {
2259
2490
  * only when the run row settled as {@link settledRunStatuses} (Completed OR
2260
2491
  * AwaitingFeedback — the normal chat-turn ending) — a failed run leaves the previous
2261
2492
  * settled run's entry standing, just as the RunView filter would. Scoped to this
2262
- * run's agent (cache key = conversation + agent) so parallel agents in one
2263
- * conversation never cross-pollinate. An empty projection is cached too (the
2264
- * negative-cache case that spares tool-free conversations the queries every turn).
2493
+ * run's agent and branch (cache key = conversation + agent + branch) so parallel
2494
+ * agents in one conversation, and sibling branches, never cross-pollinate. An empty
2495
+ * projection is cached too (the negative-cache case that spares tool-free
2496
+ * conversations the queries every turn). The run's reply row is stored with the entry,
2497
+ * so the entry is no longer served once a rerun of its turn replaces that row.
2265
2498
  * Same-node edge semantics (failed step INSERTs, concurrent completions) are
2266
2499
  * documented on the cache class. Called from {@link finalizeAgentRun}.
2267
2500
  * @private
@@ -2305,6 +2538,16 @@ export declare class BaseAgent {
2305
2538
  * not here.
2306
2539
  */
2307
2540
  private static readonly carryForwardPredicate;
2541
+ /**
2542
+ * The row predicate for the stopped-run carry-forward's step query: the completed, successful
2543
+ * Actions and Tool steps of the run the user stopped. Declared beside
2544
+ * {@link carryForwardPredicate} for the same reason it is: one place to change what counts.
2545
+ */
2546
+ private static readonly stoppedRunCarryForwardPredicate;
2547
+ /** An action parameter's direction, as the action executor stamps it. */
2548
+ private static readonly actionOutputParamType;
2549
+ /** A stopped-run result section is never cut below this many characters, whatever the budget. */
2550
+ private static readonly minStoppedRunSectionChars;
2308
2551
  /**
2309
2552
  * Display name of the seeded system prompt behind summarizeRange's recursive
2310
2553
  * sub-call (see metadata/prompts/.summarize-range-prompt.json). Resolved with a
@@ -2890,12 +3133,22 @@ export declare class BaseAgent {
2890
3133
  private finalizePayloadCheckStep;
2891
3134
  /** Adds the payload change check's message to the conversation, for the agent's next turn. */
2892
3135
  private injectPayloadCheckMessage;
3136
+ /**
3137
+ * The {@link AIPromptExecutionScope} of model work this run starts outside the agent's own turn —
3138
+ * summarizing a range, compacting a message or the conversation, decision calls (FinishIf,
3139
+ * discovery, catalog narrowing, decision requests, the payload change check) and self-check
3140
+ * rubrics. Each built its params with only `contextUser`, so it ran on the platform's keys and
3141
+ * default configuration inside a run on a customer's keys, and under a `'RuntimeOnly'` scope
3142
+ * would have bypassed it.
3143
+ */
3144
+ private runPromptExecutionScope;
2893
3145
  /**
2894
3146
  * Whether THIS action may use the run's runtime API key for THIS driver class. The default is
2895
3147
  * yes: the run was started on those keys, and an action that calls a vendor on the user's behalf
2896
3148
  * (Generate Image) is doing what the prompts do. Override to narrow it — an agent that knows
2897
3149
  * which of its actions talk to which vendor can refuse everything else, and a refusal costs the
2898
3150
  * action nothing but the customer's key: it falls back to the platform key as if the run had none.
3151
+ * Under a `'RuntimeOnly'` credential scope a refusal leaves the action with no key for that class.
2899
3152
  */
2900
3153
  protected actionMayUseRuntimeAPIKey(action: MJActionEntityExtended, driverClass: string, params: ExecuteAgentParams): boolean;
2901
3154
  /**
@@ -3066,6 +3319,19 @@ export declare class BaseAgent {
3066
3319
  * @private
3067
3320
  */
3068
3321
  private formatActionParameter;
3322
+ /**
3323
+ * The `user`-role record of what the model asked to run on an Actions turn ("[You invoked ...]").
3324
+ * Shared by the live Actions step and the stopped-run resume, so a resumed turn reads exactly
3325
+ * like one the loop wrote. See the Actions step for why it is a user-role annotation.
3326
+ * @protected
3327
+ */
3328
+ protected buildActionInvocationMessage(actions: AgentAction[]): string;
3329
+ /**
3330
+ * The action-results message body: a header naming any failures, then each result in the
3331
+ * compact markdown shape. Shared by the live Actions step and the stopped-run resume.
3332
+ * @protected
3333
+ */
3334
+ protected buildActionResultsMessage(actionSummaries: ActionResultSummary[]): string;
3069
3335
  /**
3070
3336
  * Formats an array of action result summaries as compact markdown instead of
3071
3337
  * pretty-printed JSON. This typically saves 60-70 % of the tokens that the
@@ -3217,6 +3483,12 @@ export declare class BaseAgent {
3217
3483
  * @private
3218
3484
  */
3219
3485
  private getActionCategoryName;
3486
+ /**
3487
+ * Throws unless `lastRunId` is absent or a UUID. The value can come from a client, and the run
3488
+ * initialization places it in `ExtraFilter` clauses (the payload lookup, {@link validateRunChain}
3489
+ * and {@link resolvePlanModeGate}).
3490
+ */
3491
+ private assertLastRunIdIsUUID;
3220
3492
  /**
3221
3493
  * Initializes the agent run tracking by creating MJAIAgentRunEntityExtended and setting up context.
3222
3494
  *
@@ -3511,8 +3783,10 @@ export declare class BaseAgent {
3511
3783
  * by one in-flight sub-agent would race the others' reads.
3512
3784
  *
3513
3785
  * Uses `structuredClone` (Node 17+) where available; falls back to a JSON
3514
- * round-trip for environments without it. Returns the original value on
3515
- * non-cloneable inputs.
3786
+ * round-trip (`ToPlainJSON`) for environments without it AND when
3787
+ * `structuredClone` throws (a Proxy such as a live JSONType `<Field>Object`
3788
+ * view, or functions). Returns the original value — with an error logged —
3789
+ * only when even the JSON clone fails.
3516
3790
  *
3517
3791
  * **JSON fallback caveats** — the round-trip is *not* shape-preserving:
3518
3792
  * - `Date` → ISO string
@@ -3739,10 +4013,6 @@ export declare class BaseAgent {
3739
4013
  * (or timeout), then adds results to the conversation and continues.
3740
4014
  */
3741
4015
  private executeClientToolsStep;
3742
- /**
3743
- * Format client tool results as a compact markdown summary for the conversation.
3744
- */
3745
- private formatClientToolResultsAsMarkdown;
3746
4016
  /**
3747
4017
  * Executes a 'Skill' next step: activates one or more skills the LLM requested by name.
3748
4018
  * Activating a skill (1) appends its full `Instructions` to the conversation so they take
@@ -4054,12 +4324,10 @@ export declare class BaseAgent {
4054
4324
  /**
4055
4325
  * Resolves the file storage account ID for this agent's file artifacts.
4056
4326
  *
4057
- * Resolution chain (first non-null wins):
4058
- * 1. Runtime override (`params.override?.storageAccountId`)
4059
- * 2. Agent-level (`params.agent.DefaultStorageAccountID`)
4060
- * 3. Category hierarchy — walks up the agent's category tree via `ParentID`
4061
- * 4. Agent Type-level (`agentType.DefaultStorageAccountID`)
4062
- * 5. System fallback — single active storage account, if only one exists
4327
+ * Delegates to {@link AIEngineBase.ResolveAgentStorageAccountID}, the shared golden path:
4328
+ * runtime override (`params.override?.storageAccountId`) → agent → category tree → agent type →
4329
+ * system fallback (the single active account, or the most recently updated one with a
4330
+ * once-per-agent warning when several are active).
4063
4331
  *
4064
4332
  * This method is `protected` so subclasses can override the resolution logic
4065
4333
  * for custom storage routing (e.g., routing by file type or tenant).
@@ -4238,6 +4506,22 @@ export declare class BaseAgent {
4238
4506
  * @returns {Promise<ExecuteAgentResult>} The cancelled result
4239
4507
  */
4240
4508
  private createCancelledResult;
4509
+ /**
4510
+ * Maps the reason an abort signal carried to the run's `CancellationReason` value: the
4511
+ * watchdog's stop relay raises {@link AgentRunWatchdog.UserCancelAbortReason} for a row marked
4512
+ * `User Request`; the wall-clock guard's reason starts with {@link AgentTimeoutAbortReason};
4513
+ * anything else (an upstream caller's token, a shutdown) is `System`.
4514
+ */
4515
+ static CancellationReasonForAbort(reason: string | null | undefined): NonNullable<MJAIAgentRunEntityExtended['CancellationReason']>;
4516
+ /**
4517
+ * The payload recorded at the end of the latest step that recorded one, as its serialized
4518
+ * string, or null when no step has. Steps are examined from the highest `StepNumber` down
4519
+ * (array order is spawn order, which a sub-step can interleave).
4520
+ */
4521
+ static LastStepPayload(steps: ReadonlyArray<{
4522
+ StepNumber: number;
4523
+ PayloadAtEnd: string | null;
4524
+ }> | null | undefined): string | null;
4241
4525
  /**
4242
4526
  * Finalizes the agent run with success.
4243
4527
  *