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

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.
@@ -54840,12 +54840,16 @@ rules[8]:
54840
54840
  - think briefly, then respond
54841
54841
  - actions execute in listed order
54842
54842
  - if replying, REPLY goes first
54843
- - use IGNORE only by itself
54843
+ - use IGNORE or STOP only by themselves
54844
54844
  - include providers only when needed
54845
54845
  - use provider_hints from context when present instead of restating the same rules
54846
54846
  - if an action needs inputs, include a <params> block with the required fields
54847
54847
  - if a required param is unknown, ask for clarification in <text>
54848
54848
 
54849
+ control_actions:
54850
+ - STOP means the task is done and the agent should end the run without executing more actions
54851
+ - STOP is a terminal control action even if it is not listed in available actions
54852
+
54849
54853
  fields[5]{name,meaning}:
54850
54854
  - thought | short plan
54851
54855
  - actions | ordered XML <action> elements
@@ -55026,6 +55030,46 @@ Here are the actions taken by the assistant to fulfill the request:
55026
55030
  </response>
55027
55031
  </output>
55028
55032
  `;
55033
+ var postActionDecisionTemplate = `<task>
55034
+ Continue helping the user after reviewing the latest action results.
55035
+ </task>
55036
+
55037
+ context:
55038
+ {{providers}}
55039
+
55040
+ recent conversation:
55041
+ {{recentMessages}}
55042
+
55043
+ recent action results:
55044
+ {{actionResults}}
55045
+
55046
+ rules[9]:
55047
+ - think briefly, then continue the task from the latest action results
55048
+ - actions execute in listed order
55049
+ - if replying, REPLY goes first
55050
+ - use IGNORE or STOP only by themselves
55051
+ - include providers only when needed
55052
+ - use provider_hints from context when present instead of restating the same rules
55053
+ - if an action needs inputs, include a <params> block with the required fields
55054
+ - if a required param is unknown, ask for clarification in <text>
55055
+ - if the task is complete, either reply to the user or use STOP to end the run
55056
+ - STOP is a terminal control action even if it is not listed in available actions
55057
+
55058
+ <output>
55059
+ XML only. Return exactly one <response> block. No prose before or after it. No <think>.
55060
+
55061
+ <response>
55062
+ <thought>Your thought here</thought>
55063
+ <actions>
55064
+ <action>
55065
+ <name>ACTION</name>
55066
+ </action>
55067
+ </actions>
55068
+ <providers></providers>
55069
+ <text>Your message here</text>
55070
+ <simple>true</simple>
55071
+ </response>
55072
+ </output>`;
55029
55073
  var replyTemplate = `# Task: Generate dialog for the character {{agentName}}.
55030
55074
 
55031
55075
  {{providers}}
@@ -55873,7 +55917,8 @@ async function runAutonomyPostResponse(runtime2, autonomousMessage, fields, call
55873
55917
  await runtime2.createMemory(responseMemory, "messages");
55874
55918
  }
55875
55919
  const isSimple = responseContent.actions?.length === 1 && String(responseContent.actions[0]).toUpperCase() === "REPLY" && (!responseContent.providers || responseContent.providers.length === 0);
55876
- const mode = isSimple && responseContent.text ? "simple" : "actions";
55920
+ const isStop = responseContent.actions?.length === 1 && String(responseContent.actions[0]).toUpperCase() === "STOP";
55921
+ const mode = isStop ? "none" : isSimple && responseContent.text ? "simple" : "actions";
55877
55922
  if (mode === "simple" && callback) {
55878
55923
  if (responseContent.text) {
55879
55924
  responseContent.text = runtime2.redactSecrets(responseContent.text);
@@ -55888,7 +55933,7 @@ async function runAutonomyPostResponse(runtime2, autonomousMessage, fields, call
55888
55933
  return [];
55889
55934
  }, {});
55890
55935
  }
55891
- const didRespond = typeof responseContent.text === "string" && responseContent.text.trim().length > 0 || responseContent.actions && responseContent.actions.length > 0 && responseContent.actions[0]?.toUpperCase() !== "IGNORE";
55936
+ 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";
55892
55937
  await runtime2.evaluate(autonomousMessage, state2, didRespond, async (content) => {
55893
55938
  runtime2.logger.debug({ src: "autonomy:facade", content }, "Autonomy evaluate callback");
55894
55939
  if (callback && content.text) {
@@ -79498,6 +79543,56 @@ var latestResponseIds = new Map;
79498
79543
  function isSimpleReplyResponse(responseContent) {
79499
79544
  return !!(responseContent?.actions && responseContent.actions.length === 1 && typeof responseContent.actions[0] === "string" && responseContent.actions[0].toUpperCase() === "REPLY");
79500
79545
  }
79546
+ function isStopResponse(responseContent) {
79547
+ return !!(responseContent?.actions && responseContent.actions.length === 1 && typeof responseContent.actions[0] === "string" && responseContent.actions[0].toUpperCase() === "STOP");
79548
+ }
79549
+ function shouldContinueAfterActions(responseContent) {
79550
+ return !!responseContent?.actions?.some((action) => {
79551
+ if (typeof action !== "string")
79552
+ return false;
79553
+ const normalized = action.trim().toUpperCase();
79554
+ return normalized !== "REPLY" && normalized !== "IGNORE" && normalized !== "STOP";
79555
+ });
79556
+ }
79557
+ function formatActionResultsForPrompt(actionResults) {
79558
+ if (actionResults.length === 0) {
79559
+ return "No action results available.";
79560
+ }
79561
+ return [
79562
+ "# Action Results",
79563
+ ...actionResults.map((result, index) => {
79564
+ const actionNameValue = result.data?.actionName;
79565
+ const actionName = typeof actionNameValue === "string" ? actionNameValue : "Unknown Action";
79566
+ const lines = [
79567
+ `${index + 1}. ${actionName} - ${result.success === false ? "failed" : "succeeded"}`
79568
+ ];
79569
+ if (typeof result.text === "string" && result.text.trim()) {
79570
+ lines.push(`Output: ${result.text.trim().slice(0, 2000)}`);
79571
+ }
79572
+ if (result.error) {
79573
+ const errorText = result.error instanceof Error ? result.error.message : String(result.error);
79574
+ lines.push(`Error: ${errorText.slice(0, 1000)}`);
79575
+ }
79576
+ return lines.join(`
79577
+ `);
79578
+ })
79579
+ ].join(`
79580
+
79581
+ `);
79582
+ }
79583
+ function withActionResults(state2, actionResults) {
79584
+ return {
79585
+ ...state2,
79586
+ values: {
79587
+ ...state2.values,
79588
+ actionResults: formatActionResultsForPrompt(actionResults)
79589
+ },
79590
+ data: {
79591
+ ...state2.data,
79592
+ actionResults
79593
+ }
79594
+ };
79595
+ }
79501
79596
 
79502
79597
  class DefaultMessageService {
79503
79598
  async handleMessage(runtime2, message2, callback, options) {
@@ -79510,6 +79605,7 @@ class DefaultMessageService {
79510
79605
  timeoutDuration: options?.timeoutDuration ?? 60 * 60 * 1000,
79511
79606
  useMultiStep: options?.useMultiStep ?? parseBooleanFromText2(String(runtime2.getSetting("USE_MULTI_STEP") ?? "")),
79512
79607
  maxMultiStepIterations: options?.maxMultiStepIterations ?? parseInt(String(runtime2.getSetting("MAX_MULTISTEP_ITERATIONS") ?? "6"), 10),
79608
+ continueAfterActions: options?.continueAfterActions ?? parseBooleanFromText2(String(runtime2.getSetting("CONTINUE_AFTER_ACTIONS") ?? "true")),
79513
79609
  onStreamChunk: options?.onStreamChunk,
79514
79610
  shouldRespondModel: resolvedShouldRespondModel
79515
79611
  };
@@ -79787,6 +79883,7 @@ class DefaultMessageService {
79787
79883
  }
79788
79884
  }
79789
79885
  let shouldRespondToMessage = true;
79886
+ let terminalDecision = null;
79790
79887
  const metadata = typeof message2.content.metadata === "object" && message2.content.metadata !== null ? message2.content.metadata : null;
79791
79888
  const isAutonomous = metadata?.isAutonomous === true;
79792
79889
  const autonomyMode = typeof metadata?.autonomyMode === "string" ? metadata.autonomyMode : null;
@@ -79851,8 +79948,11 @@ class DefaultMessageService {
79851
79948
  }
79852
79949
  });
79853
79950
  runtime2.logger.debug({ src: "service:message", responseObject }, "Parsed evaluation result");
79854
- const nonResponseActions = ["IGNORE", "NONE"];
79951
+ const nonResponseActions = ["IGNORE", "NONE", "STOP"];
79855
79952
  const actionValue = responseObject?.action;
79953
+ if (typeof actionValue === "string" && (actionValue.toUpperCase() === "IGNORE" || actionValue.toUpperCase() === "STOP")) {
79954
+ terminalDecision = actionValue.toUpperCase();
79955
+ }
79856
79956
  shouldRespondToMessage = typeof actionValue === "string" && !nonResponseActions.includes(actionValue.toUpperCase());
79857
79957
  }
79858
79958
  }
@@ -79925,6 +80025,20 @@ class DefaultMessageService {
79925
80025
  }
79926
80026
  return [];
79927
80027
  }, { onStreamChunk: opts.onStreamChunk });
80028
+ if (opts.continueAfterActions && message2.id && shouldContinueAfterActions(responseContent)) {
80029
+ const continuation = await this.runPostActionContinuation(runtime2, message2, state2, callback, opts, runtime2.getActionResults(message2.id));
80030
+ if (continuation.responseMessages.length > 0) {
80031
+ responseMessages = [
80032
+ ...responseMessages,
80033
+ ...continuation.responseMessages
80034
+ ];
80035
+ }
80036
+ if (continuation.responseContent) {
80037
+ responseContent = continuation.responseContent;
80038
+ mode = continuation.mode;
80039
+ }
80040
+ state2 = continuation.state;
80041
+ }
79928
80042
  }
79929
80043
  }
79930
80044
  } else {
@@ -79957,31 +80071,33 @@ class DefaultMessageService {
79957
80071
  mode: "none"
79958
80072
  };
79959
80073
  }
79960
- const ignoreContent = {
79961
- thought: "Agent decided not to respond to this message.",
79962
- actions: ["IGNORE"],
80074
+ const terminalAction = terminalDecision ?? "IGNORE";
80075
+ const terminalContent = {
80076
+ thought: terminalAction === "STOP" ? "Agent decided to stop and end the run." : "Agent decided not to respond to this message.",
80077
+ actions: [terminalAction],
79963
80078
  simple: true,
79964
80079
  inReplyTo: createUniqueUuid(runtime2, message2.id)
79965
80080
  };
79966
80081
  if (callback) {
79967
- await callback(ignoreContent);
80082
+ await callback(terminalContent);
79968
80083
  }
79969
- const ignoreMemory = {
80084
+ const terminalMemory = {
79970
80085
  id: asUUID(v4_default()),
79971
80086
  entityId: runtime2.agentId,
79972
80087
  agentId: runtime2.agentId,
79973
- content: ignoreContent,
80088
+ content: terminalContent,
79974
80089
  roomId: message2.roomId,
79975
80090
  createdAt: Date.now()
79976
80091
  };
79977
- await runtime2.createMemory(ignoreMemory, "messages");
79978
- runtime2.logger.debug({ src: "service:message", memoryId: ignoreMemory.id }, "Saved ignore response to memory");
80092
+ await runtime2.createMemory(terminalMemory, "messages");
80093
+ runtime2.logger.debug({ src: "service:message", memoryId: terminalMemory.id }, "Saved terminal response to memory");
79979
80094
  }
79980
80095
  agentResponses.delete(message2.roomId);
79981
80096
  if (agentResponses.size === 0) {
79982
80097
  latestResponseIds.delete(runtime2.agentId);
79983
80098
  }
79984
- const runEvaluate = () => runtime2.evaluate(message2, state2, shouldRespondToMessage, async (content) => {
80099
+ const didRespond = shouldRespondToMessage && !isStopResponse(responseContent);
80100
+ const runEvaluate = () => runtime2.evaluate(message2, state2, didRespond, async (content) => {
79985
80101
  runtime2.logger.debug({ src: "service:message", content }, "Evaluate callback");
79986
80102
  if (responseContent) {
79987
80103
  responseContent.evalCallbacks = content;
@@ -80061,7 +80177,7 @@ class DefaultMessageService {
80061
80177
  duration: Date.now() - startTime
80062
80178
  });
80063
80179
  return {
80064
- didRespond: shouldRespondToMessage,
80180
+ didRespond,
80065
80181
  responseContent,
80066
80182
  responseMessages,
80067
80183
  state: state2,
@@ -80270,15 +80386,99 @@ class DefaultMessageService {
80270
80386
  }));
80271
80387
  return processedAttachments;
80272
80388
  }
80273
- async runSingleShotCore(runtime2, message2, state2, opts, responseId) {
80274
- state2 = await runtime2.composeState(message2, ["ACTIONS"], false, false);
80389
+ async runPostActionContinuation(runtime2, message2, state2, callback, opts, initialActionResults) {
80390
+ if (!message2.id || initialActionResults.length === 0) {
80391
+ return {
80392
+ responseContent: null,
80393
+ responseMessages: [],
80394
+ state: state2,
80395
+ mode: "none"
80396
+ };
80397
+ }
80398
+ const traceActionResults = [...initialActionResults];
80399
+ const responseMessages = [];
80400
+ let accumulatedState = state2;
80401
+ let responseContent = null;
80402
+ for (let iterationCount = 0;iterationCount < opts.maxMultiStepIterations; iterationCount++) {
80403
+ accumulatedState = withActionResults(await runtime2.composeState(message2, ["ACTIONS"], false, false), traceActionResults);
80404
+ const continuation = await this.runSingleShotCore(runtime2, message2, accumulatedState, opts, asUUID(v4_default()), {
80405
+ prompt: runtime2.character.templates?.postActionDecisionTemplate || postActionDecisionTemplate,
80406
+ precomposedState: accumulatedState
80407
+ });
80408
+ if (!continuation.responseContent) {
80409
+ runtime2.logger.debug({ src: "service:message", iteration: iterationCount + 1 }, "Post-action continuation produced no response");
80410
+ break;
80411
+ }
80412
+ responseContent = continuation.responseContent;
80413
+ if (message2.id) {
80414
+ responseContent.inReplyTo = createUniqueUuid(runtime2, message2.id);
80415
+ }
80416
+ if (responseContent.providers && responseContent.providers.length > 0) {
80417
+ accumulatedState = withActionResults(await runtime2.composeState(message2, responseContent.providers, false, false), traceActionResults);
80418
+ } else {
80419
+ accumulatedState = withActionResults(continuation.state, traceActionResults);
80420
+ }
80421
+ if (continuation.responseMessages.length > 0) {
80422
+ for (const responseMemory of continuation.responseMessages) {
80423
+ responseMemory.content = responseContent;
80424
+ await runtime2.createMemory(responseMemory, "messages");
80425
+ await runtime2.emitEvent("MESSAGE_SENT" /* MESSAGE_SENT */, {
80426
+ runtime: runtime2,
80427
+ message: responseMemory,
80428
+ source: message2.content.source ?? "messageHandler"
80429
+ });
80430
+ }
80431
+ responseMessages.push(...continuation.responseMessages);
80432
+ }
80433
+ if (continuation.mode === "simple") {
80434
+ if (callback) {
80435
+ if (responseContent.text) {
80436
+ responseContent.text = runtime2.redactSecrets(responseContent.text);
80437
+ }
80438
+ await callback(responseContent);
80439
+ }
80440
+ break;
80441
+ }
80442
+ if (continuation.mode !== "actions") {
80443
+ break;
80444
+ }
80445
+ await runtime2.processActions(message2, continuation.responseMessages, accumulatedState, async (content) => {
80446
+ runtime2.logger.debug({ src: "service:message", content }, "Post-action callback");
80447
+ if (responseContent) {
80448
+ responseContent.actionCallbacks = content;
80449
+ }
80450
+ if (callback) {
80451
+ return callback(content);
80452
+ }
80453
+ return [];
80454
+ }, { onStreamChunk: opts.onStreamChunk });
80455
+ if (!shouldContinueAfterActions(responseContent)) {
80456
+ break;
80457
+ }
80458
+ const latestActionResults = runtime2.getActionResults(message2.id);
80459
+ if (latestActionResults.length === 0) {
80460
+ runtime2.logger.warn({ src: "service:message", iteration: iterationCount + 1 }, "Post-action continuation produced no new action results");
80461
+ break;
80462
+ }
80463
+ traceActionResults.push(...latestActionResults);
80464
+ }
80465
+ accumulatedState = withActionResults(accumulatedState, traceActionResults);
80466
+ return {
80467
+ responseContent,
80468
+ responseMessages,
80469
+ state: accumulatedState,
80470
+ mode: responseContent ? "simple" : "none"
80471
+ };
80472
+ }
80473
+ async runSingleShotCore(runtime2, message2, state2, opts, responseId, overrides) {
80474
+ state2 = overrides?.precomposedState ?? await runtime2.composeState(message2, ["ACTIONS"], false, false);
80275
80475
  if (!state2.values || !state2.values.actionNames) {
80276
80476
  runtime2.logger.warn({ src: "service:message" }, "actionNames data missing from state");
80277
80477
  }
80278
80478
  let responseContent = null;
80279
80479
  const streamingExtractor = opts.onStreamChunk ? new MarkableExtractor : undefined;
80280
80480
  const streamingCtx = streamingExtractor && opts.onStreamChunk ? createStreamingContext(streamingExtractor, opts.onStreamChunk, responseId) : undefined;
80281
- const prompt = runtime2.character.templates?.messageHandlerTemplate || messageHandlerTemplate;
80481
+ const prompt = overrides?.prompt || runtime2.character.templates?.messageHandlerTemplate || messageHandlerTemplate;
80282
80482
  const parsedXml = await runtime2.dynamicPromptExecFromState({
80283
80483
  state: state2,
80284
80484
  params: {
@@ -80517,7 +80717,9 @@ Output ONLY the continuation, starting immediately after the last character abov
80517
80717
  }
80518
80718
  if (responseContent.actions && responseContent.actions.length > 1) {
80519
80719
  const isIgnore = (a) => typeof a === "string" && a.toUpperCase() === "IGNORE";
80720
+ const isStop2 = (a) => typeof a === "string" && a.toUpperCase() === "STOP";
80520
80721
  const hasIgnore = responseContent.actions.some(isIgnore);
80722
+ const hasStop = responseContent.actions.some(isStop2);
80521
80723
  if (hasIgnore) {
80522
80724
  if (!responseContent.text || responseContent.text.trim() === "") {
80523
80725
  responseContent.actions = ["IGNORE"];
@@ -80526,8 +80728,13 @@ Output ONLY the continuation, starting immediately after the last character abov
80526
80728
  responseContent.actions = filtered.length ? filtered : ["REPLY"];
80527
80729
  }
80528
80730
  }
80731
+ if (hasStop) {
80732
+ const filtered = responseContent.actions.filter((a) => !isStop2(a));
80733
+ responseContent.actions = filtered.length ? filtered : ["STOP"];
80734
+ }
80529
80735
  }
80530
80736
  const isSimple = isSimpleReplyResponse(responseContent);
80737
+ const isStop = isStopResponse(responseContent);
80531
80738
  responseContent.simple = isSimple;
80532
80739
  responseContent.responseId = responseId;
80533
80740
  const responseMessages = [
@@ -80544,7 +80751,7 @@ Output ONLY the continuation, starting immediately after the last character abov
80544
80751
  responseContent,
80545
80752
  responseMessages,
80546
80753
  state: state2,
80547
- mode: isSimple && responseContent.text ? "simple" : "actions"
80754
+ mode: isStop ? "none" : isSimple && responseContent.text ? "simple" : "actions"
80548
80755
  };
80549
80756
  }
80550
80757
  async runMultiStepCore(runtime2, message2, state2, callback, opts, responseId) {
@@ -90777,6 +90984,7 @@ export {
90777
90984
  processAttachments,
90778
90985
  prewarmUuidCache,
90779
90986
  postCreationTemplate,
90987
+ postActionDecisionTemplate,
90780
90988
  pingServer,
90781
90989
  participantSchema,
90782
90990
  parseKeyValueXml,
@@ -91259,5 +91467,5 @@ export {
91259
91467
  ADD_CONTACT_TEMPLATE
91260
91468
  };
91261
91469
 
91262
- //# debugId=263B3CD9FD646BA964756E2164756E21
91470
+ //# debugId=9450800FDA6F17B664756E2164756E21
91263
91471
  //# sourceMappingURL=index.node.js.map