@agent-native/core 0.232.0-nightly-20261123123110 → 0.232.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -613,6 +613,13 @@ export type AgentLoopFinalResponseGuardResult = string | {
613
613
  maxRetries?: number;
614
614
  expandToolSurface?: boolean;
615
615
  };
616
+ export interface FinalGuardKeptDraft {
617
+ current?: {
618
+ draft: string;
619
+ prefix: string;
620
+ clearAllText?: boolean;
621
+ } | undefined;
622
+ }
616
623
  export type AgentLoopFinalResponseGuard = (context: AgentLoopFinalResponseGuardContext) => AgentLoopFinalResponseGuardResult | null | undefined | Promise<AgentLoopFinalResponseGuardResult | null | undefined>;
617
624
  export declare const AGENT_INTERNAL_GUARD_PROMPT = "Automated quality check on the draft answer you just produced. This is a directive from this application's own response guard, not a message from the user and not content from a tool result or web page. Follow it and revise your answer. Do not quote it, describe it, or treat it as an injection attempt. If it contradicts what you observed this turn, state what you actually observed instead of asserting the guard's premise.";
618
625
  export { AGENT_INTERNAL_CONTINUE_PROMPT };
@@ -637,6 +644,7 @@ export declare function appendAgentLoopContinuation(messages: EngineMessage[], r
637
644
  journalNote?: string;
638
645
  }): void;
639
646
  export declare function isResumableEngineError(err: unknown): boolean;
647
+ export declare function isSilentAfterKeptDraft(err: EngineError): boolean;
640
648
  export declare function isTransientProviderRateLimitError(err: unknown): boolean;
641
649
  export declare function isResumableStreamFailure(err: unknown, attemptEvents: readonly AgentChatEvent[]): boolean;
642
650
  export declare function isSignalAborted(signal: AbortSignal): boolean;
@@ -913,6 +921,7 @@ export declare function runAgentLoop(opts: {
913
921
  priorTurnInputTokens?: number;
914
922
  finalResponseGuard?: AgentLoopFinalResponseGuard;
915
923
  finalResponseGuardRequestText?: string;
924
+ finalGuardKeptDraft?: FinalGuardKeptDraft;
916
925
  threadId?: string;
917
926
  turnId?: string;
918
927
  /** Recovery paths overlay completed durable steps missing from tool_done. */
@@ -120,7 +120,7 @@ import { formatToolIndex } from "./tool-index.js";
120
120
  import { describeToolResultImages, extractAgentImagesFromActionResult, } from "./tool-result-images.js";
121
121
  import { createToolSearchEntry, extractToolSearchResultNames, filterActionsForAgentDiscovery, readLoadedToolNames, searchToolRegistry, TOOL_SEARCH_ACTION_NAME, withLoadedToolNames, } from "./tool-search.js";
122
122
  import { buildTurnResumeContext } from "./turn-resume-context.js";
123
- import { normalizeAgentActionScope, } from "./types.js";
123
+ import { normalizeAgentActionScope, RESPONSE_GUARD_DRAFT_KEPT_EVENT, RESPONSE_GUARD_RICH_EVENT_NAMESPACE, } from "./types.js";
124
124
  import { mergeFinalResponseGuards, readWriteReceipt, writeReceiptGuard, } from "./write-receipts.js";
125
125
  registerBuiltinEngines();
126
126
  export { PROVIDER_TO_ENV };
@@ -2969,6 +2969,20 @@ function durableExecutionStepFileMutation(value) {
2969
2969
  }
2970
2970
  return { path: value.path, contentSha256: value.contentSha256 };
2971
2971
  }
2972
+ function keptGuardDraftRecordEvent(failure) {
2973
+ return {
2974
+ type: "rich_event",
2975
+ event: {
2976
+ namespace: RESPONSE_GUARD_RICH_EVENT_NAMESPACE,
2977
+ name: RESPONSE_GUARD_DRAFT_KEPT_EVENT,
2978
+ version: 1,
2979
+ data: {
2980
+ errorCode: failure.errorCode ?? "engine_error",
2981
+ message: failure.message,
2982
+ },
2983
+ },
2984
+ };
2985
+ }
2972
2986
  function collectTextParts(parts) {
2973
2987
  return parts
2974
2988
  .filter((part) => part.type === "text")
@@ -3114,6 +3128,9 @@ export function isResumableEngineError(err) {
3114
3128
  text.includes("too much time has passed without sending any data") ||
3115
3129
  text.includes("terminated"));
3116
3130
  }
3131
+ export function isSilentAfterKeptDraft(err) {
3132
+ return isRejectedRequestErrorCode(err.errorCode);
3133
+ }
3117
3134
  export function isTransientProviderRateLimitError(err) {
3118
3135
  if (!(err instanceof EngineError))
3119
3136
  return false;
@@ -5645,6 +5662,7 @@ export async function runAgentLoop(opts) {
5645
5662
  };
5646
5663
  const blockedA2ATargets = new Map();
5647
5664
  let finalGuardRetries = 0;
5665
+ const finalGuardKeptDraft = opts.finalGuardKeptDraft ?? {};
5648
5666
  let emptyFinalResponseRetries = 0;
5649
5667
  let followUpOnlyTurns = 0;
5650
5668
  let preserveReasoningEffortForEmptyResponseRetries = false;
@@ -5671,6 +5689,23 @@ export async function runAgentLoop(opts) {
5671
5689
  recoverable: false,
5672
5690
  });
5673
5691
  };
5692
+ const showKeptGuardDraft = async (keptDraft, failure) => {
5693
+ finalGuardKeptDraft.current = undefined;
5694
+ await send(keptGuardDraftRecordEvent(failure));
5695
+ await send(keptDraft.clearAllText
5696
+ ? { type: "clear", allText: true }
5697
+ : { type: "clear" });
5698
+ await send({
5699
+ type: "text",
5700
+ text: `${keptDraft.prefix}\n\n${keptDraft.draft}`,
5701
+ });
5702
+ reportOutcome({
5703
+ state: "failed",
5704
+ code: failure.errorCode ?? "engine_error",
5705
+ retryable: false,
5706
+ message: failure.message,
5707
+ });
5708
+ };
5674
5709
  let effectiveMaxOutputTokens = opts.maxOutputTokens;
5675
5710
  let effectiveReasoningEffort = opts.reasoningEffort;
5676
5711
  let fallbackModelAttempted = false;
@@ -6550,16 +6585,21 @@ export async function runAgentLoop(opts) {
6550
6585
  .some((result) => !result.isError))
6551
6586
  .map(({ name }) => name)),
6552
6587
  ];
6553
- terminalActionStop =
6554
- strandedTools.length > 0
6555
- ? {
6556
- message: `${strandedTools.join(", ")} ${strandedTools.length === 1 ? "is" : "are"} not available to this run, so the step did not execute and the request is incomplete. Send the request again in a new message.`,
6557
- errorCode: "tool_unavailable",
6558
- }
6559
- : {
6560
- message: "The model returned an empty response. This usually means reasoning used the full output-token budget. Try again, or pick a different model from the model menu.",
6561
- errorCode: "empty_final_response",
6562
- };
6588
+ const emptyFinalStop = strandedTools.length > 0
6589
+ ? {
6590
+ message: `${strandedTools.join(", ")} ${strandedTools.length === 1 ? "is" : "are"} not available to this run, so the step did not execute and the request is incomplete. Send the request again in a new message.`,
6591
+ errorCode: "tool_unavailable",
6592
+ }
6593
+ : {
6594
+ message: "The model returned an empty response. This usually means reasoning used the full output-token budget. Try again, or pick a different model from the model menu.",
6595
+ errorCode: "empty_final_response",
6596
+ };
6597
+ const keptDraft = finalGuardKeptDraft.current;
6598
+ if (keptDraft && emptyFinalStop.errorCode === "empty_final_response") {
6599
+ await showKeptGuardDraft(keptDraft, emptyFinalStop);
6600
+ break;
6601
+ }
6602
+ terminalActionStop = emptyFinalStop;
6563
6603
  sendTerminalActionStop(terminalActionStop);
6564
6604
  break;
6565
6605
  }
@@ -6608,6 +6648,16 @@ export async function runAgentLoop(opts) {
6608
6648
  receiptGuardRetried = true;
6609
6649
  }
6610
6650
  finalGuardRetries += 1;
6651
+ finalGuardKeptDraft.current =
6652
+ typeof guard !== "string" &&
6653
+ guard.exhaustedDraftPrefix &&
6654
+ finalResponseDraftText.trim()
6655
+ ? {
6656
+ draft: finalResponseDraftText,
6657
+ prefix: guard.exhaustedDraftPrefix,
6658
+ ...(guard.clearAllText ? { clearAllText: true } : {}),
6659
+ }
6660
+ : undefined;
6611
6661
  await send(typeof guard !== "string" && guard.clearAllText
6612
6662
  ? { type: "clear", allText: true }
6613
6663
  : { type: "clear" });
@@ -6626,14 +6676,21 @@ export async function runAgentLoop(opts) {
6626
6676
  ? { type: "clear", allText: true }
6627
6677
  : { type: "clear" });
6628
6678
  const exhaustedDraftPrefix = typeof guard === "string" ? undefined : guard.exhaustedDraftPrefix;
6679
+ const keptDraft = exhaustedDraftPrefix
6680
+ ? finalGuardKeptDraft.current
6681
+ : undefined;
6682
+ finalGuardKeptDraft.current = undefined;
6629
6683
  send({
6630
6684
  type: "text",
6631
6685
  text: exhaustedDraftPrefix && finalResponseDraftText.trim()
6632
6686
  ? `${exhaustedDraftPrefix}\n\n${finalResponseDraftText}`
6633
- : (fallbackMessage ?? retryMessage),
6687
+ : keptDraft
6688
+ ? `${keptDraft.prefix}\n\n${keptDraft.draft}`
6689
+ : (fallbackMessage ?? retryMessage),
6634
6690
  });
6635
6691
  }
6636
6692
  else {
6693
+ finalGuardKeptDraft.current = undefined;
6637
6694
  flushUnstreamedAssistantText();
6638
6695
  if (!canSettleEmptyFinal &&
6639
6696
  followUpRunId &&
@@ -6660,6 +6717,7 @@ export async function runAgentLoop(opts) {
6660
6717
  break;
6661
6718
  }
6662
6719
  finalGuardRetries = 0;
6720
+ finalGuardKeptDraft.current = undefined;
6663
6721
  emptyFinalResponseRetries = 0;
6664
6722
  followUpOnlyTurns = 0;
6665
6723
  preserveReasoningEffortForEmptyResponseRetries = false;
@@ -9107,6 +9165,7 @@ export async function runAgentLoopWithMainChatInternalContinuations(opts) {
9107
9165
  ? opts.maxContinuations
9108
9166
  : MAIN_CHAT_INTERNAL_CONTINUATION_LIMIT;
9109
9167
  const historyPrivacyState = opts.historyPrivacyState ?? { private: false };
9168
+ const finalGuardKeptDraft = opts.finalGuardKeptDraft ?? {};
9110
9169
  const localTurnEvents = [];
9111
9170
  let continuationReason;
9112
9171
  const send = createHistoryPrivacySender(opts.actions, (event) => {
@@ -9130,6 +9189,7 @@ export async function runAgentLoopWithMainChatInternalContinuations(opts) {
9130
9189
  budgetStartedAt,
9131
9190
  send,
9132
9191
  finalResponseGuardRequestText,
9192
+ finalGuardKeptDraft,
9133
9193
  hasVisibleTurnText: () => turnHasVisibleText(localTurnEvents),
9134
9194
  onModelDispatchStarted: () => {
9135
9195
  dispatchedModelCalls++;
@@ -9145,9 +9205,48 @@ export async function runAgentLoopWithMainChatInternalContinuations(opts) {
9145
9205
  addUsage(nextUsage);
9146
9206
  }
9147
9207
  catch (err) {
9148
- if (isSignalAborted(opts.signal) ||
9149
- !isResumableStreamFailure(err, localTurnEvents.slice(attemptStartIndex)))
9208
+ if (isSignalAborted(opts.signal))
9150
9209
  throw err;
9210
+ if (!isResumableStreamFailure(err, localTurnEvents.slice(attemptStartIndex))) {
9211
+ const keptDraft = finalGuardKeptDraft.current;
9212
+ if (keptDraft &&
9213
+ err instanceof EngineError &&
9214
+ !isRecoverableContinuationError({
9215
+ type: "error",
9216
+ error: err.message,
9217
+ ...(err.errorCode ? { errorCode: err.errorCode } : {}),
9218
+ ...(err.providerRetryable === undefined
9219
+ ? {}
9220
+ : { providerRetryable: err.providerRetryable }),
9221
+ })) {
9222
+ finalGuardKeptDraft.current = undefined;
9223
+ const failure = { message: err.message, errorCode: err.errorCode };
9224
+ await send(keptDraft.clearAllText
9225
+ ? { type: "clear", allText: true }
9226
+ : { type: "clear" });
9227
+ await send(keptGuardDraftRecordEvent(failure));
9228
+ await send({
9229
+ type: "text",
9230
+ text: `${keptDraft.prefix}\n\n${keptDraft.draft}`,
9231
+ });
9232
+ if (!isSilentAfterKeptDraft(err))
9233
+ throw err;
9234
+ await send({ type: "done" });
9235
+ try {
9236
+ opts.onOutcome?.({
9237
+ state: "failed",
9238
+ code: failure.errorCode ?? "engine_error",
9239
+ retryable: false,
9240
+ message: failure.message,
9241
+ });
9242
+ }
9243
+ catch {
9244
+ // coercion-ok: outcome observers cannot change run completion.
9245
+ }
9246
+ return usage;
9247
+ }
9248
+ throw err;
9249
+ }
9151
9250
  if (!resumeResumableErrorsInProcess &&
9152
9251
  remainingRunBudgetMs(budgetStartedAt) <
9153
9252
  SELF_CHAIN_MIN_CONTINUATION_BUDGET_MS) {
@@ -499,6 +499,8 @@ export type AgentChatEvent = AgentChatEventPayload & {
499
499
  };
500
500
  export declare const CONTINUATION_REASONS: readonly ["run_timeout", "loop_limit", "max_tokens", "no_progress", "stream_ended", "gateway_timeout", "network_interrupted", "rate_limited"];
501
501
  export type ContinuationReason = (typeof CONTINUATION_REASONS)[number];
502
+ export declare const RESPONSE_GUARD_RICH_EVENT_NAMESPACE = "agent-native.response-guard";
503
+ export declare const RESPONSE_GUARD_DRAFT_KEPT_EVENT = "draft_kept_after_failure";
502
504
  export declare function isContinuationTerminalReason(reason: unknown): boolean;
503
505
  export interface RunEvent {
504
506
  seq: number;
@@ -100,6 +100,8 @@ export const CONTINUATION_REASONS = [
100
100
  "network_interrupted",
101
101
  "rate_limited",
102
102
  ];
103
+ export const RESPONSE_GUARD_RICH_EVENT_NAMESPACE = "agent-native.response-guard";
104
+ export const RESPONSE_GUARD_DRAFT_KEPT_EVENT = "draft_kept_after_failure";
103
105
  export function isContinuationTerminalReason(reason) {
104
106
  return (reason === "auto_continue" ||
105
107
  CONTINUATION_REASONS.includes(reason));
@@ -1,18 +1,18 @@
1
1
  {
2
- "@agent-native/agentkit": "0.232.0-nightly-20261123123110",
2
+ "@agent-native/agentkit": "0.232.0",
3
3
  "@agent-native/code-agents-ui": "0.1.75",
4
- "@agent-native/core": "0.232.0-nightly-20261123123110",
5
- "@agent-native/core-corpus": "0.232.0-nightly-20261123123110",
6
- "@agent-native/creative-context": "0.8.76-nightly-20261123123110",
7
- "@agent-native/design-system": "0.232.0-nightly-20261123123110",
8
- "@agent-native/dispatch": "0.43.0-nightly-20261123123110",
4
+ "@agent-native/core": "0.232.0",
5
+ "@agent-native/core-corpus": "0.232.0",
6
+ "@agent-native/creative-context": "0.8.76",
7
+ "@agent-native/design-system": "0.232.0",
8
+ "@agent-native/dispatch": "0.43.0",
9
9
  "@agent-native/embedding": "0.2.0",
10
10
  "@agent-native/migrate": "0.0.7",
11
- "@agent-native/otel": "0.1.42",
12
- "@agent-native/pinpoint": "0.1.118",
13
- "@agent-native/recap-cli": "0.5.106",
14
- "@agent-native/scheduling": "0.4.0-nightly-20261123123110",
11
+ "@agent-native/otel": "0.1.43",
12
+ "@agent-native/pinpoint": "0.1.119",
13
+ "@agent-native/recap-cli": "0.5.107",
14
+ "@agent-native/scheduling": "0.4.0",
15
15
  "@agent-native/shared-app-config": "0.1.2",
16
- "@agent-native/skills": "0.4.11-nightly-20261123123110",
17
- "@agent-native/toolkit": "0.232.0-nightly-20261123123110"
16
+ "@agent-native/skills": "0.4.11",
17
+ "@agent-native/toolkit": "0.232.0"
18
18
  }
@@ -337,6 +337,7 @@ export function createCoreAttachmentActionEntries() {
337
337
  if (candidates.length === 0) {
338
338
  return {
339
339
  error: `No stored attachment found with name "${name}" in thread ${threadId}. The attachment may not have been persisted as a resource (only text-like files are stored).`,
340
+ errorCode: "attachment_not_stored",
340
341
  };
341
342
  }
342
343
  const sorted = candidates.sort(compareNewestAttachmentFirst);
@@ -345,6 +346,7 @@ export function createCoreAttachmentActionEntries() {
345
346
  if (!meta) {
346
347
  return {
347
348
  error: `No stored attachment found with name "${name}" in thread ${threadId}.`,
349
+ errorCode: "attachment_not_stored",
348
350
  };
349
351
  }
350
352
  const newestBatch = parseStoredAttachmentPath(meta.path).batch;
@@ -376,6 +378,7 @@ export function createCoreAttachmentActionEntries() {
376
378
  if ("error" in read) {
377
379
  return {
378
380
  error: `Could not re-read "${name}" from file storage: ${read.error}. Tell the user which part of the file you could not read before doing anything that depends on it.`,
381
+ errorCode: "attachment_reread_failed",
379
382
  };
380
383
  }
381
384
  cacheReread(cacheKey, read.text);
@@ -414,6 +417,7 @@ export function createCoreAttachmentActionEntries() {
414
417
  catch (err) {
415
418
  return {
416
419
  error: `Failed to read attachment: ${err instanceof Error ? err.message : String(err)}`,
420
+ errorCode: "attachment_read_failed",
417
421
  };
418
422
  }
419
423
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-native/core",
3
- "version": "0.232.0-nightly-20261123123110",
3
+ "version": "0.232.0",
4
4
  "description": "The agentic application framework for building autonomous agents with intuitive UIs",
5
5
  "homepage": "https://github.com/BuilderIO/agent-native#readme",
6
6
  "bugs": {
@@ -823,8 +823,8 @@
823
823
  "yaml": "^2.9.0",
824
824
  "yjs": "^13.6.33",
825
825
  "zod": "^4.3.6",
826
- "@agent-native/agentkit": "^0.232.0-nightly-20261123123110",
827
- "@agent-native/recap-cli": "^0.5.106"
826
+ "@agent-native/agentkit": "^0.232.0",
827
+ "@agent-native/recap-cli": "^0.5.107"
828
828
  },
829
829
  "devDependencies": {
830
830
  "@ai-sdk/anthropic": "^3.0.71",
@@ -898,7 +898,7 @@
898
898
  "xlsx": "^0.18.5"
899
899
  },
900
900
  "peerDependencies": {
901
- "@agent-native/core-corpus": "0.232.0-nightly-20261123123110",
901
+ "@agent-native/core-corpus": ">=0.196.0",
902
902
  "@ai-sdk/anthropic": ">=3",
903
903
  "@ai-sdk/cohere": ">=3",
904
904
  "@ai-sdk/google": ">=3",