deepagents 1.10.4 → 1.10.6

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.
@@ -424,16 +424,19 @@ function grepMatchesFromFiles(files, pattern, path = null, glob = null) {
424
424
  /**
425
425
  * Determine MIME type from a file path's extension.
426
426
  *
427
- * Returns "application/octet-stream" for unknown extensions so that
428
- * binary files are not accidentally treated as text (grep, read_file,
429
- * etc. rely on {@link isTextMimeType} which would return true for
430
- * "text/plain").
427
+ * Defaults to "text/plain" for unknown extensions. Only the known non-text
428
+ * formats above (images, audio, video, PDF/PPT) are treated as binary by
429
+ * {@link isTextMimeType}; everything else reads as text, including source files
430
+ * with uncommon extensions (.properties, .scss, .tf) and extension-less files
431
+ * (Dockerfile, mvnw). This avoids base64-encoding text into document blocks,
432
+ * which the model can't read and which the Anthropic provider rejects with a
433
+ * 400.
431
434
  *
432
435
  * @param filePath - File path to inspect
433
- * @returns MIME type string (e.g., "image/png", "application/octet-stream")
436
+ * @returns MIME type string (e.g., "image/png", "text/plain")
434
437
  */
435
438
  function getMimeType(filePath) {
436
- return MIME_TYPES[extname(filePath).toLocaleLowerCase()] || "application/octet-stream";
439
+ return MIME_TYPES[extname(filePath).toLocaleLowerCase()] || "text/plain";
437
440
  }
438
441
  /**
439
442
  * Check whether a MIME type represents text content.
@@ -2336,11 +2339,16 @@ function returnCommandWithStateUpdate(result, toolCallId) {
2336
2339
  let content;
2337
2340
  if (result.structuredResponse != null) content = JSON.stringify(result.structuredResponse);
2338
2341
  else {
2339
- const messages = result.messages;
2340
- content = (messages?.[messages.length - 1])?.content || "Task completed";
2341
- if (Array.isArray(content)) {
2342
- content = content.filter((block) => !INVALID_TOOL_MESSAGE_BLOCK_TYPES.includes(block.type));
2343
- if (content.length === 0) content = "Task completed";
2342
+ const messages = result.messages ?? [];
2343
+ content = "Task completed";
2344
+ for (let i = messages.length - 1; i >= 0; i -= 1) {
2345
+ const message = messages[i];
2346
+ if (!message || !_langchain_core_messages.AIMessage.isInstance(message)) continue;
2347
+ const text = typeof message.content === "string" ? message.content.trim() : message.text?.trim() ?? "";
2348
+ if (text) {
2349
+ content = text;
2350
+ break;
2351
+ }
2344
2352
  }
2345
2353
  }
2346
2354
  return new _langchain_langgraph.Command({ update: {
@@ -2702,6 +2710,30 @@ function isAnthropicModel(model) {
2702
2710
  return model.getName() === "ChatAnthropic";
2703
2711
  }
2704
2712
  /**
2713
+ * Detect whether a model is an AWS Bedrock Converse model.
2714
+ *
2715
+ * Accepts the wider `RunnableInterface` shape (the type of `request.model`
2716
+ * inside `wrapModelCall`, aliased as `AgentLanguageModelLike` in langchain)
2717
+ * because the function only depends on `.getName()`, which is part of the
2718
+ * Runnable contract. `BaseLanguageModel` extends `Runnable`, so existing
2719
+ * call sites still type-check.
2720
+ */
2721
+ function isBedrockConverseModel(model) {
2722
+ if (typeof model === "string") {
2723
+ const colonIdx = model.indexOf(":");
2724
+ if (colonIdx !== -1) {
2725
+ const prefix = model.slice(0, colonIdx);
2726
+ if (prefix === "bedrock" || prefix === "aws") return true;
2727
+ }
2728
+ return model.startsWith("amazon.");
2729
+ }
2730
+ if (model.getName() === "ConfigurableModel") {
2731
+ const provider = model._defaultConfig?.modelProvider;
2732
+ return provider === "bedrock" || provider === "aws";
2733
+ }
2734
+ return model.getName() === "ChatBedrockConverse";
2735
+ }
2736
+ /**
2705
2737
  * Extract the provider name from a model instance for profile lookup.
2706
2738
  *
2707
2739
  * Checks `_defaultConfig.modelProvider` (ConfigurableModel) and falls
@@ -4505,7 +4537,7 @@ const ASYNC_TASK_TOOL_NAMES = [
4505
4537
  "cancel_async_task",
4506
4538
  "list_async_tasks"
4507
4539
  ];
4508
- const TERMINAL_STATUSES = new Set([
4540
+ const TERMINAL_STATUSES = /* @__PURE__ */ new Set([
4509
4541
  "cancelled",
4510
4542
  "success",
4511
4543
  "error",
@@ -5031,271 +5063,6 @@ function createCacheBreakpointMiddleware() {
5031
5063
  });
5032
5064
  }
5033
5065
  //#endregion
5034
- //#region src/stream.ts
5035
- /**
5036
- * Deep Agent streaming support (experimental).
5037
- *
5038
- * Provides:
5039
- * - `DeepAgentRunStream` — type overlay that adds `.subagents` to the
5040
- * `AgentRunStream` shape
5041
- * - `createSubagentTransformer` — a `__native` transformer whose
5042
- * projection (`subagents`) lands directly on the `GraphRunStream`
5043
- * instance via langgraph-core's native transformer support
5044
- *
5045
- * See protocol proposal §15 (In-Process Streaming Interface) and §16
5046
- * (Native Stream Transformers).
5047
- */
5048
- function hasPrefix(ns, prefix) {
5049
- if (prefix.length > ns.length) return false;
5050
- for (let i = 0; i < prefix.length; i += 1) if (ns[i] !== prefix[i]) return false;
5051
- return true;
5052
- }
5053
- /**
5054
- * Native transformer that correlates `task` tool calls into
5055
- * {@link SubagentRunStream} objects and routes child-namespace
5056
- * `tools` and `messages` events into per-subagent channels.
5057
- *
5058
- * Marked `__native: true` — the `subagents` projection key lands
5059
- * directly on the `GraphRunStream` instance as `run.subagents`.
5060
- */
5061
- function createSubagentTransformer(path) {
5062
- return () => {
5063
- const subagentsLog = _langchain_langgraph.StreamChannel.local();
5064
- const pendingByCallId = /* @__PURE__ */ new Map();
5065
- const pendingByNamespaceSegment = /* @__PURE__ */ new Map();
5066
- const latestValuesByNamespaceSegment = /* @__PURE__ */ new Map();
5067
- const subagentsByName = /* @__PURE__ */ new Map();
5068
- /** Maps tools-node namespace segment to subagent name. */
5069
- const toolsNodeToName = /* @__PURE__ */ new Map();
5070
- const childToolCalls = /* @__PURE__ */ new Map();
5071
- /** Active ChatModelStreamImpl per subagent (keyed by subagent name). */
5072
- const activeMessages = /* @__PURE__ */ new Map();
5073
- function deletePendingSubagent(pending) {
5074
- pendingByCallId.delete(pending.callId);
5075
- for (const [segment, entry] of pendingByNamespaceSegment) if (entry === pending) {
5076
- pendingByNamespaceSegment.delete(segment);
5077
- latestValuesByNamespaceSegment.delete(segment);
5078
- }
5079
- }
5080
- function subagentSegment(ns) {
5081
- return ns.length === path.length + 1 ? ns[path.length] : void 0;
5082
- }
5083
- function getOrCreateSubagentLogs(name) {
5084
- let logs = subagentsByName.get(name);
5085
- if (!logs) {
5086
- logs = {
5087
- messagesLog: _langchain_langgraph.StreamChannel.local(),
5088
- toolCallsLog: _langchain_langgraph.StreamChannel.local(),
5089
- nestedSubagentsLog: _langchain_langgraph.StreamChannel.local()
5090
- };
5091
- subagentsByName.set(name, logs);
5092
- }
5093
- return logs;
5094
- }
5095
- return {
5096
- __native: true,
5097
- init: () => ({ subagents: subagentsLog }),
5098
- process(event) {
5099
- if (!hasPrefix(event.params.namespace, path)) return true;
5100
- const ns = event.params.namespace;
5101
- const depth = ns.length - path.length;
5102
- if (depth <= 1 && event.method === "tools") {
5103
- const data = event.params.data;
5104
- const toolCallId = data.tool_call_id;
5105
- const toolName = data.tool_name;
5106
- if (toolName === "task" && data.event === "tool-started") {
5107
- const rawInput = data.input;
5108
- const input = typeof rawInput === "string" ? JSON.parse(rawInput) : rawInput ?? {};
5109
- const subagentName = input.subagent_type ?? "unknown";
5110
- const taskDescription = input.description ?? "";
5111
- let resolveTaskInput;
5112
- let resolveOutput;
5113
- let rejectOutput;
5114
- const taskInput = new Promise((res) => {
5115
- resolveTaskInput = res;
5116
- });
5117
- const output = new Promise((res, rej) => {
5118
- resolveOutput = res;
5119
- rejectOutput = rej;
5120
- });
5121
- const pending = {
5122
- name: subagentName,
5123
- callId: toolCallId,
5124
- resolveTaskInput,
5125
- resolveOutput,
5126
- rejectOutput
5127
- };
5128
- if (toolCallId) pendingByCallId.set(toolCallId, pending);
5129
- resolveTaskInput(taskDescription);
5130
- if (depth === 1) {
5131
- toolsNodeToName.set(ns[path.length], subagentName);
5132
- pendingByNamespaceSegment.set(ns[path.length], pending);
5133
- }
5134
- if (toolCallId) {
5135
- const taskSegment = `tools:${toolCallId}`;
5136
- toolsNodeToName.set(taskSegment, subagentName);
5137
- pendingByNamespaceSegment.set(taskSegment, pending);
5138
- }
5139
- const logs = getOrCreateSubagentLogs(subagentName);
5140
- subagentsLog.push({
5141
- name: subagentName,
5142
- taskInput,
5143
- output,
5144
- messages: logs.messagesLog,
5145
- toolCalls: logs.toolCallsLog,
5146
- subagents: logs.nestedSubagentsLog
5147
- });
5148
- }
5149
- if (toolName === "task" && toolCallId) {
5150
- const pending = pendingByCallId.get(toolCallId);
5151
- if (pending) {
5152
- if (data.event === "tool-finished") {
5153
- pending.resolveOutput(data.output);
5154
- deletePendingSubagent(pending);
5155
- } else if (data.event === "tool-error") {
5156
- const message = data.message ?? "unknown error";
5157
- pending.rejectOutput(new Error(message));
5158
- deletePendingSubagent(pending);
5159
- }
5160
- }
5161
- }
5162
- }
5163
- const segment = subagentSegment(ns);
5164
- const pending = segment ? pendingByNamespaceSegment.get(segment) : void 0;
5165
- if (pending) {
5166
- if (event.method === "values") latestValuesByNamespaceSegment.set(segment, event.params.data);
5167
- else if (event.method === "lifecycle") {
5168
- const data = event.params.data;
5169
- if (data.event === "completed" || data.event === "interrupted") {
5170
- pending.resolveOutput(latestValuesByNamespaceSegment.get(segment));
5171
- deletePendingSubagent(pending);
5172
- } else if (data.event === "failed") {
5173
- pending.rejectOutput(/* @__PURE__ */ new Error(`Subagent ${pending.name} failed`));
5174
- deletePendingSubagent(pending);
5175
- }
5176
- }
5177
- }
5178
- if (depth >= 2) {
5179
- const parentSegment = ns[path.length];
5180
- const subagentName = toolsNodeToName.get(parentSegment);
5181
- const logs = subagentName ? subagentsByName.get(subagentName) : void 0;
5182
- if (logs && subagentName) {
5183
- if (event.method === "tools") {
5184
- const data = event.params.data;
5185
- const toolCallId = data.tool_call_id;
5186
- const toolName = data.tool_name;
5187
- if (data.event === "tool-started") {
5188
- let resolveOutput;
5189
- let rejectOutput;
5190
- let resolveStatus;
5191
- let resolveError;
5192
- const output = new Promise((res, rej) => {
5193
- resolveOutput = res;
5194
- rejectOutput = rej;
5195
- });
5196
- const status = new Promise((res) => {
5197
- resolveStatus = res;
5198
- });
5199
- const error = new Promise((res) => {
5200
- resolveError = res;
5201
- });
5202
- childToolCalls.set(toolCallId, {
5203
- resolveOutput,
5204
- rejectOutput,
5205
- resolveStatus,
5206
- resolveError
5207
- });
5208
- const rawInput = data.input;
5209
- const parsedInput = typeof rawInput === "string" ? JSON.parse(rawInput) : rawInput;
5210
- logs.toolCallsLog.push({
5211
- name: toolName ?? "unknown",
5212
- callId: toolCallId,
5213
- input: parsedInput,
5214
- output,
5215
- status,
5216
- error
5217
- });
5218
- }
5219
- const pending = toolCallId ? childToolCalls.get(toolCallId) : void 0;
5220
- if (pending) {
5221
- if (data.event === "tool-finished") {
5222
- pending.resolveOutput(data.output);
5223
- pending.resolveStatus("finished");
5224
- pending.resolveError(void 0);
5225
- childToolCalls.delete(toolCallId);
5226
- } else if (data.event === "tool-error") {
5227
- const message = data.message ?? "unknown error";
5228
- pending.rejectOutput(new Error(message));
5229
- pending.resolveStatus("error");
5230
- pending.resolveError(message);
5231
- childToolCalls.delete(toolCallId);
5232
- }
5233
- }
5234
- }
5235
- if (event.method === "messages") {
5236
- const data = event.params.data;
5237
- if (data.event === "message-start") {
5238
- const eventsLog = _langchain_langgraph.StreamChannel.local();
5239
- const stream = new _langchain_langgraph.ChatModelStreamImpl(eventsLog);
5240
- eventsLog.push(data);
5241
- activeMessages.set(subagentName, {
5242
- stream,
5243
- eventsLog
5244
- });
5245
- logs.messagesLog.push(stream);
5246
- } else if (data.event === "message-finish") {
5247
- const active = activeMessages.get(subagentName);
5248
- if (active) {
5249
- active.eventsLog.push(data);
5250
- active.eventsLog.close();
5251
- activeMessages.delete(subagentName);
5252
- }
5253
- } else activeMessages.get(subagentName)?.eventsLog.push(data);
5254
- }
5255
- }
5256
- }
5257
- return true;
5258
- },
5259
- finalize() {
5260
- for (const pending of pendingByCallId.values()) pending.resolveOutput(void 0);
5261
- pendingByCallId.clear();
5262
- for (const pending of childToolCalls.values()) {
5263
- pending.resolveOutput(void 0);
5264
- pending.resolveStatus("finished");
5265
- pending.resolveError(void 0);
5266
- }
5267
- childToolCalls.clear();
5268
- for (const active of activeMessages.values()) active.eventsLog.fail(/* @__PURE__ */ new Error("run finalized before message completed"));
5269
- activeMessages.clear();
5270
- subagentsLog.close();
5271
- for (const logs of subagentsByName.values()) {
5272
- logs.toolCallsLog.close();
5273
- logs.messagesLog.close();
5274
- logs.nestedSubagentsLog.close();
5275
- }
5276
- },
5277
- fail(err) {
5278
- for (const pending of pendingByCallId.values()) pending.rejectOutput(err);
5279
- pendingByCallId.clear();
5280
- for (const pending of childToolCalls.values()) {
5281
- pending.rejectOutput(err);
5282
- pending.resolveStatus("error");
5283
- pending.resolveError(err instanceof Error ? err.message : String(err));
5284
- }
5285
- childToolCalls.clear();
5286
- for (const active of activeMessages.values()) active.eventsLog.fail(err);
5287
- activeMessages.clear();
5288
- subagentsLog.fail(err);
5289
- for (const logs of subagentsByName.values()) {
5290
- logs.toolCallsLog.fail(err);
5291
- logs.messagesLog.fail(err);
5292
- logs.nestedSubagentsLog.fail(err);
5293
- }
5294
- }
5295
- };
5296
- };
5297
- }
5298
- //#endregion
5299
5066
  //#region src/profiles/keys.ts
5300
5067
  /**
5301
5068
  * Normalize and validate a profile registry key.
@@ -5336,7 +5103,7 @@ function validateProfileKey(key) {
5336
5103
  * filesystem permissions.
5337
5104
  * - `SubAgentMiddleware` backs the `task` tool for subagent delegation.
5338
5105
  */
5339
- const REQUIRED_MIDDLEWARE_NAMES = new Set(["FilesystemMiddleware", "SubAgentMiddleware"]);
5106
+ const REQUIRED_MIDDLEWARE_NAMES = /* @__PURE__ */ new Set(["FilesystemMiddleware", "SubAgentMiddleware"]);
5340
5107
  /**
5341
5108
  * Type guard: is this a fully-constructed HarnessProfile (frozen with
5342
5109
  * Set fields) or raw options?
@@ -5423,7 +5190,7 @@ function createHarnessProfile(options = {}) {
5423
5190
  const EMPTY_HARNESS_PROFILE = createHarnessProfile();
5424
5191
  //#endregion
5425
5192
  //#region src/profiles/harness/serialization.ts
5426
- const POISONED_KEYS = new Set([
5193
+ const POISONED_KEYS = /* @__PURE__ */ new Set([
5427
5194
  "__proto__",
5428
5195
  "constructor",
5429
5196
  "prototype"
@@ -5999,7 +5766,7 @@ const BASE_AGENT_PROMPT = langchain.context`
5999
5766
 
6000
5767
  For longer tasks, provide brief progress updates at reasonable intervals — a concise sentence recapping what you've done and what's next.
6001
5768
  `;
6002
- const BUILTIN_TOOL_NAMES = new Set([
5769
+ const BUILTIN_TOOL_NAMES = /* @__PURE__ */ new Set([
6003
5770
  ...FILESYSTEM_TOOL_NAMES,
6004
5771
  ...ASYNC_TASK_TOOL_NAMES,
6005
5772
  "task",
@@ -6047,10 +5814,17 @@ function createDeepAgent(params = {}) {
6047
5814
  const toolOverrides = harnessProfile.toolDescriptionOverrides;
6048
5815
  const effectiveTools = Object.keys(toolOverrides).length > 0 ? tools.map((t) => t.name in toolOverrides ? Object.assign(Object.create(Object.getPrototypeOf(t)), t, { description: toolOverrides[t.name] }) : t) : tools;
6049
5816
  const anthropicModel = isAnthropicModel(model);
6050
- const cacheMiddleware = anthropicModel ? [(0, langchain.anthropicPromptCachingMiddleware)({
6051
- unsupportedModelBehavior: "ignore",
6052
- minMessagesToCache: 1
6053
- }), createCacheBreakpointMiddleware()] : [];
5817
+ const bedrockModel = isBedrockConverseModel(model);
5818
+ let cacheMiddleware = [];
5819
+ if (anthropicModel) cacheMiddleware = [
5820
+ ...cacheMiddleware,
5821
+ (0, langchain.anthropicPromptCachingMiddleware)({
5822
+ unsupportedModelBehavior: "ignore",
5823
+ minMessagesToCache: 1
5824
+ }),
5825
+ createCacheBreakpointMiddleware()
5826
+ ];
5827
+ if (bedrockModel) cacheMiddleware = [...cacheMiddleware, (0, langchain.bedrockPromptCachingMiddleware)({ unsupportedModelBehavior: "ignore" })];
6054
5828
  /**
6055
5829
  * Process subagents to add SkillsMiddleware for those with their own skills.
6056
5830
  *
@@ -6192,7 +5966,7 @@ function createDeepAgent(params = {}) {
6192
5966
  checkpointer,
6193
5967
  store,
6194
5968
  name,
6195
- streamTransformers: [createSubagentTransformer([]), ...streamTransformers]
5969
+ streamTransformers
6196
5970
  }).withConfig({
6197
5971
  recursionLimit: 1e4,
6198
5972
  metadata: {
@@ -7810,12 +7584,6 @@ Object.defineProperty(exports, "createSubAgentMiddleware", {
7810
7584
  return createSubAgentMiddleware;
7811
7585
  }
7812
7586
  });
7813
- Object.defineProperty(exports, "createSubagentTransformer", {
7814
- enumerable: true,
7815
- get: function() {
7816
- return createSubagentTransformer;
7817
- }
7818
- });
7819
7587
  Object.defineProperty(exports, "createSummarizationMiddleware", {
7820
7588
  enumerable: true,
7821
7589
  get: function() {
@@ -7907,4 +7675,4 @@ Object.defineProperty(exports, "serializeProfile", {
7907
7675
  }
7908
7676
  });
7909
7677
 
7910
- //# sourceMappingURL=langsmith-D-SD2NFy.cjs.map
7678
+ //# sourceMappingURL=langsmith-Cpzy6cFq.cjs.map