@elizaos/core 2.0.0-alpha.111 → 2.0.0-alpha.112

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.
@@ -60561,12 +60561,16 @@ rules[8]:
60561
60561
  - think briefly, then respond
60562
60562
  - actions execute in listed order
60563
60563
  - if replying, REPLY goes first
60564
- - use IGNORE only by itself
60564
+ - use IGNORE or STOP only by themselves
60565
60565
  - include providers only when needed
60566
60566
  - use provider_hints from context when present instead of restating the same rules
60567
60567
  - if an action needs inputs, include a <params> block with the required fields
60568
60568
  - if a required param is unknown, ask for clarification in <text>
60569
60569
 
60570
+ control_actions:
60571
+ - STOP means the task is done and the agent should end the run without executing more actions
60572
+ - STOP is a terminal control action even if it is not listed in available actions
60573
+
60570
60574
  fields[5]{name,meaning}:
60571
60575
  - thought | short plan
60572
60576
  - actions | ordered XML <action> elements
@@ -60747,6 +60751,46 @@ Here are the actions taken by the assistant to fulfill the request:
60747
60751
  </response>
60748
60752
  </output>
60749
60753
  `;
60754
+ var postActionDecisionTemplate = `<task>
60755
+ Continue helping the user after reviewing the latest action results.
60756
+ </task>
60757
+
60758
+ context:
60759
+ {{providers}}
60760
+
60761
+ recent conversation:
60762
+ {{recentMessages}}
60763
+
60764
+ recent action results:
60765
+ {{actionResults}}
60766
+
60767
+ rules[9]:
60768
+ - think briefly, then continue the task from the latest action results
60769
+ - actions execute in listed order
60770
+ - if replying, REPLY goes first
60771
+ - use IGNORE or STOP only by themselves
60772
+ - include providers only when needed
60773
+ - use provider_hints from context when present instead of restating the same rules
60774
+ - if an action needs inputs, include a <params> block with the required fields
60775
+ - if a required param is unknown, ask for clarification in <text>
60776
+ - if the task is complete, either reply to the user or use STOP to end the run
60777
+ - STOP is a terminal control action even if it is not listed in available actions
60778
+
60779
+ <output>
60780
+ XML only. Return exactly one <response> block. No prose before or after it. No <think>.
60781
+
60782
+ <response>
60783
+ <thought>Your thought here</thought>
60784
+ <actions>
60785
+ <action>
60786
+ <name>ACTION</name>
60787
+ </action>
60788
+ </actions>
60789
+ <providers></providers>
60790
+ <text>Your message here</text>
60791
+ <simple>true</simple>
60792
+ </response>
60793
+ </output>`;
60750
60794
  var replyTemplate = `# Task: Generate dialog for the character {{agentName}}.
60751
60795
 
60752
60796
  {{providers}}
@@ -61594,7 +61638,8 @@ async function runAutonomyPostResponse(runtime2, autonomousMessage, fields, call
61594
61638
  await runtime2.createMemory(responseMemory, "messages");
61595
61639
  }
61596
61640
  const isSimple = responseContent.actions?.length === 1 && String(responseContent.actions[0]).toUpperCase() === "REPLY" && (!responseContent.providers || responseContent.providers.length === 0);
61597
- const mode = isSimple && responseContent.text ? "simple" : "actions";
61641
+ const isStop = responseContent.actions?.length === 1 && String(responseContent.actions[0]).toUpperCase() === "STOP";
61642
+ const mode = isStop ? "none" : isSimple && responseContent.text ? "simple" : "actions";
61598
61643
  if (mode === "simple" && callback) {
61599
61644
  if (responseContent.text) {
61600
61645
  responseContent.text = runtime2.redactSecrets(responseContent.text);
@@ -61609,7 +61654,7 @@ async function runAutonomyPostResponse(runtime2, autonomousMessage, fields, call
61609
61654
  return [];
61610
61655
  }, {});
61611
61656
  }
61612
- const didRespond = typeof responseContent.text === "string" && responseContent.text.trim().length > 0 || responseContent.actions && responseContent.actions.length > 0 && responseContent.actions[0]?.toUpperCase() !== "IGNORE";
61657
+ const didRespond = typeof responseContent.text === "string" && responseContent.text.trim().length > 0 || responseContent.actions && responseContent.actions.length > 0 && responseContent.actions[0]?.toUpperCase() !== "IGNORE" && responseContent.actions[0]?.toUpperCase() !== "STOP";
61613
61658
  await runtime2.evaluate(autonomousMessage, state2, didRespond, async (content) => {
61614
61659
  runtime2.logger.debug({ src: "autonomy:facade", content }, "Autonomy evaluate callback");
61615
61660
  if (callback && content.text) {
@@ -91018,6 +91063,56 @@ var latestResponseIds = new Map;
91018
91063
  function isSimpleReplyResponse(responseContent) {
91019
91064
  return !!(responseContent?.actions && responseContent.actions.length === 1 && typeof responseContent.actions[0] === "string" && responseContent.actions[0].toUpperCase() === "REPLY");
91020
91065
  }
91066
+ function isStopResponse(responseContent) {
91067
+ return !!(responseContent?.actions && responseContent.actions.length === 1 && typeof responseContent.actions[0] === "string" && responseContent.actions[0].toUpperCase() === "STOP");
91068
+ }
91069
+ function shouldContinueAfterActions(responseContent) {
91070
+ return !!responseContent?.actions?.some((action) => {
91071
+ if (typeof action !== "string")
91072
+ return false;
91073
+ const normalized = action.trim().toUpperCase();
91074
+ return normalized !== "REPLY" && normalized !== "IGNORE" && normalized !== "STOP";
91075
+ });
91076
+ }
91077
+ function formatActionResultsForPrompt(actionResults) {
91078
+ if (actionResults.length === 0) {
91079
+ return "No action results available.";
91080
+ }
91081
+ return [
91082
+ "# Action Results",
91083
+ ...actionResults.map((result, index) => {
91084
+ const actionNameValue = result.data?.actionName;
91085
+ const actionName = typeof actionNameValue === "string" ? actionNameValue : "Unknown Action";
91086
+ const lines = [
91087
+ `${index + 1}. ${actionName} - ${result.success === false ? "failed" : "succeeded"}`
91088
+ ];
91089
+ if (typeof result.text === "string" && result.text.trim()) {
91090
+ lines.push(`Output: ${result.text.trim().slice(0, 2000)}`);
91091
+ }
91092
+ if (result.error) {
91093
+ const errorText = result.error instanceof Error ? result.error.message : String(result.error);
91094
+ lines.push(`Error: ${errorText.slice(0, 1000)}`);
91095
+ }
91096
+ return lines.join(`
91097
+ `);
91098
+ })
91099
+ ].join(`
91100
+
91101
+ `);
91102
+ }
91103
+ function withActionResults(state2, actionResults) {
91104
+ return {
91105
+ ...state2,
91106
+ values: {
91107
+ ...state2.values,
91108
+ actionResults: formatActionResultsForPrompt(actionResults)
91109
+ },
91110
+ data: {
91111
+ ...state2.data,
91112
+ actionResults
91113
+ }
91114
+ };
91115
+ }
91021
91116
 
91022
91117
  class DefaultMessageService {
91023
91118
  async handleMessage(runtime2, message2, callback, options) {
@@ -91030,6 +91125,7 @@ class DefaultMessageService {
91030
91125
  timeoutDuration: options?.timeoutDuration ?? 60 * 60 * 1000,
91031
91126
  useMultiStep: options?.useMultiStep ?? parseBooleanFromText2(String(runtime2.getSetting("USE_MULTI_STEP") ?? "")),
91032
91127
  maxMultiStepIterations: options?.maxMultiStepIterations ?? parseInt(String(runtime2.getSetting("MAX_MULTISTEP_ITERATIONS") ?? "6"), 10),
91128
+ continueAfterActions: options?.continueAfterActions ?? parseBooleanFromText2(String(runtime2.getSetting("CONTINUE_AFTER_ACTIONS") ?? "true")),
91033
91129
  onStreamChunk: options?.onStreamChunk,
91034
91130
  shouldRespondModel: resolvedShouldRespondModel
91035
91131
  };
@@ -91307,6 +91403,7 @@ class DefaultMessageService {
91307
91403
  }
91308
91404
  }
91309
91405
  let shouldRespondToMessage = true;
91406
+ let terminalDecision = null;
91310
91407
  const metadata = typeof message2.content.metadata === "object" && message2.content.metadata !== null ? message2.content.metadata : null;
91311
91408
  const isAutonomous = metadata?.isAutonomous === true;
91312
91409
  const autonomyMode = typeof metadata?.autonomyMode === "string" ? metadata.autonomyMode : null;
@@ -91371,8 +91468,11 @@ class DefaultMessageService {
91371
91468
  }
91372
91469
  });
91373
91470
  runtime2.logger.debug({ src: "service:message", responseObject }, "Parsed evaluation result");
91374
- const nonResponseActions = ["IGNORE", "NONE"];
91471
+ const nonResponseActions = ["IGNORE", "NONE", "STOP"];
91375
91472
  const actionValue = responseObject?.action;
91473
+ if (typeof actionValue === "string" && (actionValue.toUpperCase() === "IGNORE" || actionValue.toUpperCase() === "STOP")) {
91474
+ terminalDecision = actionValue.toUpperCase();
91475
+ }
91376
91476
  shouldRespondToMessage = typeof actionValue === "string" && !nonResponseActions.includes(actionValue.toUpperCase());
91377
91477
  }
91378
91478
  }
@@ -91445,6 +91545,20 @@ class DefaultMessageService {
91445
91545
  }
91446
91546
  return [];
91447
91547
  }, { onStreamChunk: opts.onStreamChunk });
91548
+ if (opts.continueAfterActions && message2.id && shouldContinueAfterActions(responseContent)) {
91549
+ const continuation = await this.runPostActionContinuation(runtime2, message2, state2, callback, opts, runtime2.getActionResults(message2.id));
91550
+ if (continuation.responseMessages.length > 0) {
91551
+ responseMessages = [
91552
+ ...responseMessages,
91553
+ ...continuation.responseMessages
91554
+ ];
91555
+ }
91556
+ if (continuation.responseContent) {
91557
+ responseContent = continuation.responseContent;
91558
+ mode = continuation.mode;
91559
+ }
91560
+ state2 = continuation.state;
91561
+ }
91448
91562
  }
91449
91563
  }
91450
91564
  } else {
@@ -91477,31 +91591,33 @@ class DefaultMessageService {
91477
91591
  mode: "none"
91478
91592
  };
91479
91593
  }
91480
- const ignoreContent = {
91481
- thought: "Agent decided not to respond to this message.",
91482
- actions: ["IGNORE"],
91594
+ const terminalAction = terminalDecision ?? "IGNORE";
91595
+ const terminalContent = {
91596
+ thought: terminalAction === "STOP" ? "Agent decided to stop and end the run." : "Agent decided not to respond to this message.",
91597
+ actions: [terminalAction],
91483
91598
  simple: true,
91484
91599
  inReplyTo: createUniqueUuid(runtime2, message2.id)
91485
91600
  };
91486
91601
  if (callback) {
91487
- await callback(ignoreContent);
91602
+ await callback(terminalContent);
91488
91603
  }
91489
- const ignoreMemory = {
91604
+ const terminalMemory = {
91490
91605
  id: asUUID(v4_default()),
91491
91606
  entityId: runtime2.agentId,
91492
91607
  agentId: runtime2.agentId,
91493
- content: ignoreContent,
91608
+ content: terminalContent,
91494
91609
  roomId: message2.roomId,
91495
91610
  createdAt: Date.now()
91496
91611
  };
91497
- await runtime2.createMemory(ignoreMemory, "messages");
91498
- runtime2.logger.debug({ src: "service:message", memoryId: ignoreMemory.id }, "Saved ignore response to memory");
91612
+ await runtime2.createMemory(terminalMemory, "messages");
91613
+ runtime2.logger.debug({ src: "service:message", memoryId: terminalMemory.id }, "Saved terminal response to memory");
91499
91614
  }
91500
91615
  agentResponses.delete(message2.roomId);
91501
91616
  if (agentResponses.size === 0) {
91502
91617
  latestResponseIds.delete(runtime2.agentId);
91503
91618
  }
91504
- const runEvaluate = () => runtime2.evaluate(message2, state2, shouldRespondToMessage, async (content) => {
91619
+ const didRespond = shouldRespondToMessage && !isStopResponse(responseContent);
91620
+ const runEvaluate = () => runtime2.evaluate(message2, state2, didRespond, async (content) => {
91505
91621
  runtime2.logger.debug({ src: "service:message", content }, "Evaluate callback");
91506
91622
  if (responseContent) {
91507
91623
  responseContent.evalCallbacks = content;
@@ -91581,7 +91697,7 @@ class DefaultMessageService {
91581
91697
  duration: Date.now() - startTime
91582
91698
  });
91583
91699
  return {
91584
- didRespond: shouldRespondToMessage,
91700
+ didRespond,
91585
91701
  responseContent,
91586
91702
  responseMessages,
91587
91703
  state: state2,
@@ -91790,15 +91906,99 @@ class DefaultMessageService {
91790
91906
  }));
91791
91907
  return processedAttachments;
91792
91908
  }
91793
- async runSingleShotCore(runtime2, message2, state2, opts, responseId) {
91794
- state2 = await runtime2.composeState(message2, ["ACTIONS"], false, false);
91909
+ async runPostActionContinuation(runtime2, message2, state2, callback, opts, initialActionResults) {
91910
+ if (!message2.id || initialActionResults.length === 0) {
91911
+ return {
91912
+ responseContent: null,
91913
+ responseMessages: [],
91914
+ state: state2,
91915
+ mode: "none"
91916
+ };
91917
+ }
91918
+ const traceActionResults = [...initialActionResults];
91919
+ const responseMessages = [];
91920
+ let accumulatedState = state2;
91921
+ let responseContent = null;
91922
+ for (let iterationCount = 0;iterationCount < opts.maxMultiStepIterations; iterationCount++) {
91923
+ accumulatedState = withActionResults(await runtime2.composeState(message2, ["ACTIONS"], false, false), traceActionResults);
91924
+ const continuation = await this.runSingleShotCore(runtime2, message2, accumulatedState, opts, asUUID(v4_default()), {
91925
+ prompt: runtime2.character.templates?.postActionDecisionTemplate || postActionDecisionTemplate,
91926
+ precomposedState: accumulatedState
91927
+ });
91928
+ if (!continuation.responseContent) {
91929
+ runtime2.logger.debug({ src: "service:message", iteration: iterationCount + 1 }, "Post-action continuation produced no response");
91930
+ break;
91931
+ }
91932
+ responseContent = continuation.responseContent;
91933
+ if (message2.id) {
91934
+ responseContent.inReplyTo = createUniqueUuid(runtime2, message2.id);
91935
+ }
91936
+ if (responseContent.providers && responseContent.providers.length > 0) {
91937
+ accumulatedState = withActionResults(await runtime2.composeState(message2, responseContent.providers, false, false), traceActionResults);
91938
+ } else {
91939
+ accumulatedState = withActionResults(continuation.state, traceActionResults);
91940
+ }
91941
+ if (continuation.responseMessages.length > 0) {
91942
+ for (const responseMemory of continuation.responseMessages) {
91943
+ responseMemory.content = responseContent;
91944
+ await runtime2.createMemory(responseMemory, "messages");
91945
+ await runtime2.emitEvent("MESSAGE_SENT" /* MESSAGE_SENT */, {
91946
+ runtime: runtime2,
91947
+ message: responseMemory,
91948
+ source: message2.content.source ?? "messageHandler"
91949
+ });
91950
+ }
91951
+ responseMessages.push(...continuation.responseMessages);
91952
+ }
91953
+ if (continuation.mode === "simple") {
91954
+ if (callback) {
91955
+ if (responseContent.text) {
91956
+ responseContent.text = runtime2.redactSecrets(responseContent.text);
91957
+ }
91958
+ await callback(responseContent);
91959
+ }
91960
+ break;
91961
+ }
91962
+ if (continuation.mode !== "actions") {
91963
+ break;
91964
+ }
91965
+ await runtime2.processActions(message2, continuation.responseMessages, accumulatedState, async (content) => {
91966
+ runtime2.logger.debug({ src: "service:message", content }, "Post-action callback");
91967
+ if (responseContent) {
91968
+ responseContent.actionCallbacks = content;
91969
+ }
91970
+ if (callback) {
91971
+ return callback(content);
91972
+ }
91973
+ return [];
91974
+ }, { onStreamChunk: opts.onStreamChunk });
91975
+ if (!shouldContinueAfterActions(responseContent)) {
91976
+ break;
91977
+ }
91978
+ const latestActionResults = runtime2.getActionResults(message2.id);
91979
+ if (latestActionResults.length === 0) {
91980
+ runtime2.logger.warn({ src: "service:message", iteration: iterationCount + 1 }, "Post-action continuation produced no new action results");
91981
+ break;
91982
+ }
91983
+ traceActionResults.push(...latestActionResults);
91984
+ }
91985
+ accumulatedState = withActionResults(accumulatedState, traceActionResults);
91986
+ return {
91987
+ responseContent,
91988
+ responseMessages,
91989
+ state: accumulatedState,
91990
+ mode: responseContent ? "simple" : "none"
91991
+ };
91992
+ }
91993
+ async runSingleShotCore(runtime2, message2, state2, opts, responseId, overrides) {
91994
+ state2 = overrides?.precomposedState ?? await runtime2.composeState(message2, ["ACTIONS"], false, false);
91795
91995
  if (!state2.values || !state2.values.actionNames) {
91796
91996
  runtime2.logger.warn({ src: "service:message" }, "actionNames data missing from state");
91797
91997
  }
91798
91998
  let responseContent = null;
91799
91999
  const streamingExtractor = opts.onStreamChunk ? new MarkableExtractor : undefined;
91800
92000
  const streamingCtx = streamingExtractor && opts.onStreamChunk ? createStreamingContext(streamingExtractor, opts.onStreamChunk, responseId) : undefined;
91801
- const prompt = runtime2.character.templates?.messageHandlerTemplate || messageHandlerTemplate;
92001
+ const prompt = overrides?.prompt || runtime2.character.templates?.messageHandlerTemplate || messageHandlerTemplate;
91802
92002
  const parsedXml = await runtime2.dynamicPromptExecFromState({
91803
92003
  state: state2,
91804
92004
  params: {
@@ -92037,7 +92237,9 @@ Output ONLY the continuation, starting immediately after the last character abov
92037
92237
  }
92038
92238
  if (responseContent.actions && responseContent.actions.length > 1) {
92039
92239
  const isIgnore = (a2) => typeof a2 === "string" && a2.toUpperCase() === "IGNORE";
92240
+ const isStop2 = (a2) => typeof a2 === "string" && a2.toUpperCase() === "STOP";
92040
92241
  const hasIgnore = responseContent.actions.some(isIgnore);
92242
+ const hasStop = responseContent.actions.some(isStop2);
92041
92243
  if (hasIgnore) {
92042
92244
  if (!responseContent.text || responseContent.text.trim() === "") {
92043
92245
  responseContent.actions = ["IGNORE"];
@@ -92046,8 +92248,13 @@ Output ONLY the continuation, starting immediately after the last character abov
92046
92248
  responseContent.actions = filtered.length ? filtered : ["REPLY"];
92047
92249
  }
92048
92250
  }
92251
+ if (hasStop) {
92252
+ const filtered = responseContent.actions.filter((a2) => !isStop2(a2));
92253
+ responseContent.actions = filtered.length ? filtered : ["STOP"];
92254
+ }
92049
92255
  }
92050
92256
  const isSimple = isSimpleReplyResponse(responseContent);
92257
+ const isStop = isStopResponse(responseContent);
92051
92258
  responseContent.simple = isSimple;
92052
92259
  responseContent.responseId = responseId;
92053
92260
  const responseMessages = [
@@ -92064,7 +92271,7 @@ Output ONLY the continuation, starting immediately after the last character abov
92064
92271
  responseContent,
92065
92272
  responseMessages,
92066
92273
  state: state2,
92067
- mode: isSimple && responseContent.text ? "simple" : "actions"
92274
+ mode: isStop ? "none" : isSimple && responseContent.text ? "simple" : "actions"
92068
92275
  };
92069
92276
  }
92070
92277
  async runMultiStepCore(runtime2, message2, state2, callback, opts, responseId) {
@@ -101417,6 +101624,7 @@ export {
101417
101624
  processAttachments,
101418
101625
  prewarmUuidCache,
101419
101626
  postCreationTemplate,
101627
+ postActionDecisionTemplate,
101420
101628
  participantSchema,
101421
101629
  parseKeyValueXml,
101422
101630
  parseJSONObjectFromText,
@@ -101847,5 +102055,5 @@ export {
101847
102055
  ADD_CONTACT_TEMPLATE
101848
102056
  };
101849
102057
 
101850
- //# debugId=1CAF66F23CE2ED3E64756E2164756E21
102058
+ //# debugId=FFE1112D5C10AE7964756E2164756E21
101851
102059
  //# sourceMappingURL=index.edge.js.map