deepagents 1.16.3 → 1.16.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.
package/dist/browser.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_langsmith = require("./langsmith-CAjAu64d.cjs");
2
+ const require_langsmith = require("./langsmith-D_tzVwxp.cjs");
3
3
  exports.ASYNC_TASK_SYSTEM_PROMPT = require_langsmith.ASYNC_TASK_SYSTEM_PROMPT;
4
4
  exports.BASE_AGENT_PROMPT = require_langsmith.BASE_AGENT_PROMPT;
5
5
  exports.BaseSandbox = require_langsmith.BaseSandbox;
package/dist/browser.js CHANGED
@@ -1 +1 @@
1
- export { a as ASYNC_TASK_SYSTEM_PROMPT, o as BASE_AGENT_PROMPT, n as BaseSandbox, V as CompositeBackend, O as ConfigurationError, r as ContextHubBackend, M as DEFAULT_GENERAL_PURPOSE_DESCRIPTION, N as DEFAULT_SUBAGENT_PROMPT, g as EMPTY_HARNESS_PROFILE, s as EXECUTION_SYSTEM_PROMPT, P as GENERAL_PURPOSE_SUBAGENT, t as LangSmithSandbox, S as MAX_SKILL_DESCRIPTION_LENGTH, C as MAX_SKILL_FILE_SIZE, w as MAX_SKILL_NAME_LENGTH, v as REQUIRED_MIDDLEWARE_NAMES, q as SandboxError, K as StateBackend, i as StoreBackend, c as TASK_SYSTEM_PROMPT, Q as adaptBackendProtocol, $ as adaptSandboxProtocol, R as computeSummarizationDefaults, y as createAsyncSubAgentMiddleware, x as createCompletionCallbackMiddleware, l as createDeepAgent, B as createFilesystemMiddleware, _ as createHarnessProfile, k as createMemoryMiddleware, j as createPatchToolCallsMiddleware, T as createSkillsMiddleware, L as createSubAgentMiddleware, z as createSummarizationMiddleware, A as filesValue, f as generalPurposeSubagentConfigSchema, u as getHarnessProfile, p as harnessProfileConfigSchema, b as isAsyncSubAgent, Y as isSandboxBackend, X as isSandboxProtocol, m as parseHarnessProfileConfig, E as pinnedSkillsValue, d as registerHarnessProfile, Z as resolveBackend, h as serializeProfile, D as skillsMetadataValue } from "./langsmith-BCgECepG.js";
1
+ export { a as ASYNC_TASK_SYSTEM_PROMPT, o as BASE_AGENT_PROMPT, n as BaseSandbox, V as CompositeBackend, O as ConfigurationError, r as ContextHubBackend, M as DEFAULT_GENERAL_PURPOSE_DESCRIPTION, N as DEFAULT_SUBAGENT_PROMPT, g as EMPTY_HARNESS_PROFILE, s as EXECUTION_SYSTEM_PROMPT, P as GENERAL_PURPOSE_SUBAGENT, t as LangSmithSandbox, S as MAX_SKILL_DESCRIPTION_LENGTH, C as MAX_SKILL_FILE_SIZE, w as MAX_SKILL_NAME_LENGTH, v as REQUIRED_MIDDLEWARE_NAMES, q as SandboxError, K as StateBackend, i as StoreBackend, c as TASK_SYSTEM_PROMPT, Q as adaptBackendProtocol, $ as adaptSandboxProtocol, R as computeSummarizationDefaults, y as createAsyncSubAgentMiddleware, x as createCompletionCallbackMiddleware, l as createDeepAgent, B as createFilesystemMiddleware, _ as createHarnessProfile, k as createMemoryMiddleware, j as createPatchToolCallsMiddleware, T as createSkillsMiddleware, L as createSubAgentMiddleware, z as createSummarizationMiddleware, A as filesValue, f as generalPurposeSubagentConfigSchema, u as getHarnessProfile, p as harnessProfileConfigSchema, b as isAsyncSubAgent, Y as isSandboxBackend, X as isSandboxProtocol, m as parseHarnessProfileConfig, E as pinnedSkillsValue, d as registerHarnessProfile, Z as resolveBackend, h as serializeProfile, D as skillsMetadataValue } from "./langsmith-DfobOVRO.js";
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_langsmith = require("./langsmith-CAjAu64d.cjs");
3
- const require_src = require("./src-BB1S1Jfy.cjs");
2
+ const require_langsmith = require("./langsmith-D_tzVwxp.cjs");
3
+ const require_src = require("./src-DTOh2Xrc.cjs");
4
4
  exports.ASYNC_TASK_SYSTEM_PROMPT = require_langsmith.ASYNC_TASK_SYSTEM_PROMPT;
5
5
  exports.BASE_AGENT_PROMPT = require_langsmith.BASE_AGENT_PROMPT;
6
6
  exports.BaseSandbox = require_langsmith.BaseSandbox;
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { $ as adaptSandboxProtocol, A as filesValue, B as createFilesystemMiddleware, C as MAX_SKILL_FILE_SIZE, D as skillsMetadataValue, E as pinnedSkillsValue, F as SUBAGENT_RESPONSE_FORMAT_CONFIG_KEY, G as scrubUnsupportedMultimodalContent, H as MULTIMODAL_BLOCK_TYPES, I as createSubAgent, J as applyGrepMaxCount, K as StateBackend, L as createSubAgentMiddleware, M as DEFAULT_GENERAL_PURPOSE_DESCRIPTION, N as DEFAULT_SUBAGENT_PROMPT, O as ConfigurationError, P as GENERAL_PURPOSE_SUBAGENT, Q as adaptBackendProtocol, R as computeSummarizationDefaults, S as MAX_SKILL_DESCRIPTION_LENGTH, T as createSkillsMiddleware, U as createUnsupportedContentMiddleware, V as CompositeBackend, W as multimodalBlockSupported, X as isSandboxProtocol, Y as isSandboxBackend, Z as resolveBackend, _ as createHarnessProfile, a as ASYNC_TASK_SYSTEM_PROMPT, b as isAsyncSubAgent, c as TASK_SYSTEM_PROMPT, d as registerHarnessProfile, f as generalPurposeSubagentConfigSchema, g as EMPTY_HARNESS_PROFILE, h as serializeProfile, i as StoreBackend, j as createPatchToolCallsMiddleware, k as createMemoryMiddleware, l as createDeepAgent, m as parseHarnessProfileConfig, n as BaseSandbox, o as BASE_AGENT_PROMPT, p as harnessProfileConfigSchema, q as SandboxError, r as ContextHubBackend, rt as normalizeReadPagination, s as EXECUTION_SYSTEM_PROMPT, t as LangSmithSandbox, u as getHarnessProfile, v as REQUIRED_MIDDLEWARE_NAMES, w as MAX_SKILL_NAME_LENGTH, x as createCompletionCallbackMiddleware, y as createAsyncSubAgentMiddleware, z as createSummarizationMiddleware } from "./langsmith-BCgECepG.js";
2
- import { a as createAgentMemoryMiddleware, i as parseSkillMetadata, n as FilesystemBackend, o as createSettings, r as listSkills, s as findProjectRoot, t as LocalShellBackend } from "./src-0lJMqL6V.js";
1
+ import { $ as adaptSandboxProtocol, A as filesValue, B as createFilesystemMiddleware, C as MAX_SKILL_FILE_SIZE, D as skillsMetadataValue, E as pinnedSkillsValue, F as SUBAGENT_RESPONSE_FORMAT_CONFIG_KEY, G as scrubUnsupportedMultimodalContent, H as MULTIMODAL_BLOCK_TYPES, I as createSubAgent, J as applyGrepMaxCount, K as StateBackend, L as createSubAgentMiddleware, M as DEFAULT_GENERAL_PURPOSE_DESCRIPTION, N as DEFAULT_SUBAGENT_PROMPT, O as ConfigurationError, P as GENERAL_PURPOSE_SUBAGENT, Q as adaptBackendProtocol, R as computeSummarizationDefaults, S as MAX_SKILL_DESCRIPTION_LENGTH, T as createSkillsMiddleware, U as createUnsupportedContentMiddleware, V as CompositeBackend, W as multimodalBlockSupported, X as isSandboxProtocol, Y as isSandboxBackend, Z as resolveBackend, _ as createHarnessProfile, a as ASYNC_TASK_SYSTEM_PROMPT, b as isAsyncSubAgent, c as TASK_SYSTEM_PROMPT, d as registerHarnessProfile, f as generalPurposeSubagentConfigSchema, g as EMPTY_HARNESS_PROFILE, h as serializeProfile, i as StoreBackend, j as createPatchToolCallsMiddleware, k as createMemoryMiddleware, l as createDeepAgent, m as parseHarnessProfileConfig, n as BaseSandbox, o as BASE_AGENT_PROMPT, p as harnessProfileConfigSchema, q as SandboxError, r as ContextHubBackend, rt as normalizeReadPagination, s as EXECUTION_SYSTEM_PROMPT, t as LangSmithSandbox, u as getHarnessProfile, v as REQUIRED_MIDDLEWARE_NAMES, w as MAX_SKILL_NAME_LENGTH, x as createCompletionCallbackMiddleware, y as createAsyncSubAgentMiddleware, z as createSummarizationMiddleware } from "./langsmith-DfobOVRO.js";
2
+ import { a as createAgentMemoryMiddleware, i as parseSkillMetadata, n as FilesystemBackend, o as createSettings, r as listSkills, s as findProjectRoot, t as LocalShellBackend } from "./src-KaJuKnnd.js";
3
3
  export { ASYNC_TASK_SYSTEM_PROMPT, BASE_AGENT_PROMPT, BaseSandbox, CompositeBackend, ConfigurationError, ContextHubBackend, DEFAULT_GENERAL_PURPOSE_DESCRIPTION, DEFAULT_SUBAGENT_PROMPT, EMPTY_HARNESS_PROFILE, EXECUTION_SYSTEM_PROMPT, FilesystemBackend, GENERAL_PURPOSE_SUBAGENT, LangSmithSandbox, LocalShellBackend, MAX_SKILL_DESCRIPTION_LENGTH, MAX_SKILL_FILE_SIZE, MAX_SKILL_NAME_LENGTH, MULTIMODAL_BLOCK_TYPES, REQUIRED_MIDDLEWARE_NAMES, SUBAGENT_RESPONSE_FORMAT_CONFIG_KEY, SandboxError, StateBackend, StoreBackend, TASK_SYSTEM_PROMPT, adaptBackendProtocol, adaptSandboxProtocol, applyGrepMaxCount, computeSummarizationDefaults, createAgentMemoryMiddleware, createAsyncSubAgentMiddleware, createCompletionCallbackMiddleware, createDeepAgent, createFilesystemMiddleware, createHarnessProfile, createMemoryMiddleware, createPatchToolCallsMiddleware, createSettings, createSkillsMiddleware, createSubAgent, createSubAgentMiddleware, createSummarizationMiddleware, createUnsupportedContentMiddleware, filesValue, findProjectRoot, generalPurposeSubagentConfigSchema, getHarnessProfile, harnessProfileConfigSchema, isAsyncSubAgent, isSandboxBackend, isSandboxProtocol, listSkills, multimodalBlockSupported, normalizeReadPagination, parseHarnessProfileConfig, parseSkillMetadata, pinnedSkillsValue, registerHarnessProfile, resolveBackend, scrubUnsupportedMultimodalContent, serializeProfile, skillsMetadataValue };
@@ -3563,6 +3563,54 @@ function createFilesystemMiddleware(options = {}) {
3563
3563
  }
3564
3564
  });
3565
3565
  }
3566
+ // src/middleware/refusal.ts
3567
+ /**
3568
+ * The task result reported when a model in the subagent refused.
3569
+ *
3570
+ * @param refusal - The refusal block from the model's reply.
3571
+ */
3572
+ function refusalNotice(refusal) {
3573
+ let notice = "The subagent stopped because a model refused the request.";
3574
+ const category = refusal.extras?.category;
3575
+ if (category) notice += ` Category: ${String(category)}.`;
3576
+ if (refusal.refusal) notice += ` Explanation: "${refusal.refusal}"`;
3577
+ return `${notice} Retrying the same request is unlikely to succeed; rephrase it or continue without it.`;
3578
+ }
3579
+ /**
3580
+ * The refusal block in `message`, if it is a message that refused.
3581
+ *
3582
+ * @param message - The message to check. Callers often take it from an
3583
+ * unchecked cast, so non-messages are treated as no refusal.
3584
+ */
3585
+ function refusalIn(message) {
3586
+ if (!_langchain_core_messages.BaseMessage.isInstance(message)) return void 0;
3587
+ try {
3588
+ return message.contentBlocks.find((block) => block.type === "refusal");
3589
+ } catch {
3590
+ return;
3591
+ }
3592
+ }
3593
+ /**
3594
+ * The task result for an error caused by a refusal, or `undefined` to rethrow it.
3595
+ *
3596
+ * Middleware wraps errors in `MiddlewareError`, so this walks the `cause` chain.
3597
+ *
3598
+ * @param error - The error the subagent run threw.
3599
+ */
3600
+ function refusalNoticeFor(error) {
3601
+ let current = error;
3602
+ while (current) {
3603
+ if (_langchain_core_errors.ModelRefusalError.isInstance(current)) return refusalNotice(refusalIn(current.rawMessage) ?? {
3604
+ type: "refusal",
3605
+ refusal: current.message
3606
+ });
3607
+ if (typeof current === "object" && "aiMessage" in current) {
3608
+ const refusal = refusalIn(current.aiMessage);
3609
+ if (refusal) return refusalNotice(refusal);
3610
+ }
3611
+ current = typeof current === "object" && "cause" in current ? current.cause : void 0;
3612
+ }
3613
+ }
3566
3614
  // src/middleware/summarization.ts
3567
3615
  /**
3568
3616
  * Summarization middleware with backend support for conversation history offloading.
@@ -4518,7 +4566,9 @@ const INVALID_TOOL_MESSAGE_BLOCK_TYPES = [
4518
4566
  function returnCommandWithStateUpdate(result, toolCallId) {
4519
4567
  const stateUpdate = filterStateForSubagent(result);
4520
4568
  let content;
4569
+ const refusal = refusalIn(result.messages?.at(-1));
4521
4570
  if (result.structuredResponse != null) content = JSON.stringify(result.structuredResponse);
4571
+ else if (refusal) content = refusalNotice(refusal);
4522
4572
  else {
4523
4573
  const messages = result.messages ?? [];
4524
4574
  content = "Task completed";
@@ -4719,18 +4769,29 @@ function createTaskTool(options) {
4719
4769
  ...config,
4720
4770
  metadata: {
4721
4771
  ...config.metadata,
4722
- lc_agent_name: subagent_type
4772
+ lc_agent_name: subagent_type,
4773
+ ...config.toolCall?.id && { lc_subagent_tool_call_id: config.toolCall.id }
4723
4774
  },
4724
4775
  configurable: {
4725
4776
  ...config.configurable,
4726
4777
  ls_agent_type: "subagent"
4727
4778
  }
4728
4779
  };
4729
- const result = await subagent.invoke(subagentState, subagentConfig);
4780
+ let result;
4781
+ try {
4782
+ result = await subagent.invoke(subagentState, subagentConfig);
4783
+ } catch (error) {
4784
+ const notice = refusalNoticeFor(error);
4785
+ if (notice === void 0) throw error;
4786
+ return notice;
4787
+ }
4730
4788
  if (!config.toolCall?.id) {
4731
4789
  if (result.structuredResponse != null) return JSON.stringify(result.structuredResponse);
4732
4790
  const messages = result.messages;
4733
- let content = (messages?.[messages.length - 1])?.content || "Task completed";
4791
+ const lastMessage = messages?.[messages.length - 1];
4792
+ const refusal = refusalIn(lastMessage);
4793
+ if (refusal) return refusalNotice(refusal);
4794
+ let content = lastMessage?.content || "Task completed";
4734
4795
  if (Array.isArray(content)) {
4735
4796
  content = content.filter((block) => !INVALID_TOOL_MESSAGE_BLOCK_TYPES.includes(block.type));
4736
4797
  if (content.length === 0) return "Task completed";
@@ -7178,7 +7239,13 @@ function finalContent(values) {
7178
7239
  }];
7179
7240
  const last = messages[messages.length - 1];
7180
7241
  try {
7181
- return (0, _langchain_core_messages.coerceMessageLikeToMessage)(last).contentBlocks;
7242
+ const message = (0, _langchain_core_messages.coerceMessageLikeToMessage)(last);
7243
+ const refusal = refusalIn(message);
7244
+ if (refusal) return [{
7245
+ type: "text",
7246
+ text: refusalNotice(refusal)
7247
+ }];
7248
+ return message.contentBlocks;
7182
7249
  } catch {
7183
7250
  return [{
7184
7251
  type: "text",
@@ -8664,7 +8731,8 @@ function createDeepAgent(params = {}) {
8664
8731
  backend,
8665
8732
  sources: memory,
8666
8733
  addCacheControl: anthropicModel
8667
- })] : []
8734
+ })] : [],
8735
+ (0, langchain.modelRefusalMiddleware)()
8668
8736
  ]);
8669
8737
  if (subagentProfile.excludedMiddleware.size > 0) subagentMiddleware = subagentMiddleware.filter((middleware) => !subagentProfile.excludedMiddleware.has(middleware.name));
8670
8738
  if (subagentProfile.excludedTools.size > 0) subagentMiddleware.push(createToolExclusionMiddleware(subagentProfile.excludedTools));
@@ -8721,7 +8789,8 @@ function createDeepAgent(params = {}) {
8721
8789
  ...skillsMiddleware,
8722
8790
  ...cacheMiddleware,
8723
8791
  ...memoryMiddleware,
8724
- ...interruptOn ? [(0, langchain.humanInTheLoopMiddleware)({ interruptOn })] : []
8792
+ ...interruptOn ? [(0, langchain.humanInTheLoopMiddleware)({ interruptOn })] : [],
8793
+ (0, langchain.modelRefusalMiddleware)()
8725
8794
  ]);
8726
8795
  if (harnessProfile.excludedMiddleware.size > 0) {
8727
8796
  const excluded = harnessProfile.excludedMiddleware;
@@ -11216,4 +11285,4 @@ Object.defineProperty(exports, "skillsMetadataValue", {
11216
11285
  }
11217
11286
  });
11218
11287
 
11219
- //# sourceMappingURL=langsmith-CAjAu64d.cjs.map
11288
+ //# sourceMappingURL=langsmith-D_tzVwxp.cjs.map