deepagents 1.16.3 → 1.16.5
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/{agent-DOFzksfM.d.cts → agent-Di09Mxb3.d.cts} +34 -1
- package/dist/{agent-BAuGxPZn.d.ts → agent-DiA5yRzO.d.ts} +35 -2
- package/dist/browser.cjs +1 -1
- package/dist/browser.d.cts +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/{langsmith-BCgECepG.js → langsmith-CH6GPPud.js} +260 -31
- package/dist/langsmith-CH6GPPud.js.map +1 -0
- package/dist/{langsmith-CAjAu64d.cjs → langsmith-CR3a2-Z7.cjs} +263 -28
- package/dist/langsmith-CR3a2-Z7.cjs.map +1 -0
- package/dist/node.cjs +2 -2
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +2 -2
- package/dist/{src-BB1S1Jfy.cjs → src-DeLlHk9u.cjs} +151 -26
- package/dist/src-DeLlHk9u.cjs.map +1 -0
- package/dist/{src-0lJMqL6V.js → src-tRcDW-tU.js} +151 -26
- package/dist/src-tRcDW-tU.js.map +1 -0
- package/package.json +6 -6
- package/dist/langsmith-BCgECepG.js.map +0 -1
- package/dist/langsmith-CAjAu64d.cjs.map +0 -1
- package/dist/src-0lJMqL6V.js.map +0 -1
- package/dist/src-BB1S1Jfy.cjs.map +0 -1
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { AIMessage, HumanMessage, SystemMessage, ToolMessage, anthropicPromptCachingMiddleware, bedrockPromptCachingMiddleware, context, countTokensApproximately, createAgent, createMiddleware, humanInTheLoopMiddleware, todoListMiddleware, tool } from "langchain";
|
|
1
|
+
import { AIMessage, HumanMessage, SystemMessage, ToolMessage, anthropicPromptCachingMiddleware, bedrockPromptCachingMiddleware, context, countTokensApproximately, createAgent, createMiddleware, humanInTheLoopMiddleware, modelRefusalMiddleware, todoListMiddleware, tool } from "langchain";
|
|
2
2
|
import { omitPayload } from "@langchain/core/tracers/tracer_langchain";
|
|
3
|
-
import { ContextOverflowError } from "@langchain/core/errors";
|
|
3
|
+
import { ContextOverflowError, ModelRefusalError } from "@langchain/core/errors";
|
|
4
4
|
import { Command, Overwrite, REMOVE_ALL_MESSAGES, ReducedValue, StateSchema, getConfig, getCurrentTaskInput, getStore, isCommand, isGraphBubbleUp } from "@langchain/langgraph";
|
|
5
5
|
import { z } from "zod/v4";
|
|
6
6
|
import micromatch from "micromatch";
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
8
8
|
import { AIMessage as AIMessage$1, BaseMessage, HumanMessage as HumanMessage$1, RemoveMessage, SystemMessage as SystemMessage$1, ToolMessage as ToolMessage$1, addNotificationMetadata, coerceMessageLikeToMessage, getBufferString, getNotificationMetadata } from "@langchain/core/messages";
|
|
9
|
+
import { Runnable, RunnableBinding } from "@langchain/core/runnables";
|
|
9
10
|
import * as z$2 from "zod";
|
|
10
11
|
import { z as z$1 } from "zod";
|
|
11
12
|
import { initChatModel } from "langchain/chat_models/universal";
|
|
12
13
|
import yaml from "yaml";
|
|
13
|
-
import { Runnable, RunnableBinding } from "@langchain/core/runnables";
|
|
14
14
|
import { isLangChainTool } from "@langchain/core/tools";
|
|
15
15
|
import { isOpenAITool } from "@langchain/core/language_models/base";
|
|
16
16
|
import { convertToOpenAIFunction } from "@langchain/core/utils/function_calling";
|
|
@@ -34,6 +34,20 @@ function setRealpath(target, fn) {
|
|
|
34
34
|
configurable: true
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
+
// src/backends/pin.ts
|
|
38
|
+
const PIN = Symbol.for("deepagents.pin");
|
|
39
|
+
function getPin(backend) {
|
|
40
|
+
if (typeof backend !== "object" || backend === null) return;
|
|
41
|
+
const fn = backend[PIN];
|
|
42
|
+
return typeof fn === "function" ? fn : void 0;
|
|
43
|
+
}
|
|
44
|
+
function setPin(target, fn) {
|
|
45
|
+
Object.defineProperty(target, PIN, {
|
|
46
|
+
value: fn,
|
|
47
|
+
enumerable: false,
|
|
48
|
+
configurable: true
|
|
49
|
+
});
|
|
50
|
+
}
|
|
37
51
|
// src/backends/utils.ts
|
|
38
52
|
/**
|
|
39
53
|
* Shared utility functions for memory backend implementations.
|
|
@@ -667,6 +681,8 @@ function adaptBackendProtocol(backend) {
|
|
|
667
681
|
}
|
|
668
682
|
const realpath = getRealpath(backend);
|
|
669
683
|
if (realpath !== void 0) setRealpath(adapted, realpath);
|
|
684
|
+
const pin = getPin(backend);
|
|
685
|
+
if (pin !== void 0) setPin(adapted, pin);
|
|
670
686
|
const resolveBackendForPath = backend.resolveBackendForPath;
|
|
671
687
|
if (typeof resolveBackendForPath === "function") Object.defineProperty(adapted, "resolveBackendForPath", {
|
|
672
688
|
value: (path) => resolveBackendForPath.call(backend, path),
|
|
@@ -1719,6 +1735,7 @@ var CompositeBackend = class {
|
|
|
1719
1735
|
this.routes = Object.fromEntries(Object.entries(routes).map(([k, v]) => [k.endsWith("/") ? k : `${k}/`, isSandboxProtocol(v) ? adaptSandboxProtocol(v) : adaptBackendProtocol(v)]));
|
|
1720
1736
|
this.sortedRoutes = Object.entries(this.routes).sort((a, b) => b[0].length - a[0].length);
|
|
1721
1737
|
setRealpath(this, (path) => this.resolveRealPath(path));
|
|
1738
|
+
setPin(this, (path, options, authorize, operation) => this.runPinned(path, options, authorize, operation));
|
|
1722
1739
|
}
|
|
1723
1740
|
/** Delegates to default backend's id if it is a sandbox, otherwise empty string. */
|
|
1724
1741
|
get id() {
|
|
@@ -1760,6 +1777,22 @@ var CompositeBackend = class {
|
|
|
1760
1777
|
return realpath === void 0 ? path : await realpath(path);
|
|
1761
1778
|
}
|
|
1762
1779
|
/**
|
|
1780
|
+
* Pin via the backend that owns `path`, re-adding the route prefix to the
|
|
1781
|
+
* real path it authorizes. Runs `operation` unpinned when that backend has
|
|
1782
|
+
* no pin hook.
|
|
1783
|
+
*/
|
|
1784
|
+
runPinned(path, options, authorize, operation) {
|
|
1785
|
+
for (const [routePrefix, backend] of this.sortedRoutes) if (this.isPathWithinRoute(path, routePrefix)) {
|
|
1786
|
+
const pin = getPin(backend);
|
|
1787
|
+
if (pin === void 0) return operation();
|
|
1788
|
+
const prefix = routePrefix.slice(0, -1);
|
|
1789
|
+
const suffix = path.substring(routePrefix.length);
|
|
1790
|
+
return pin(suffix ? "/" + suffix : "/", options, (realPath) => authorize(prefix + realPath), operation);
|
|
1791
|
+
}
|
|
1792
|
+
const pin = getPin(this.default);
|
|
1793
|
+
return pin === void 0 ? operation() : pin(path, options, authorize, operation);
|
|
1794
|
+
}
|
|
1795
|
+
/**
|
|
1763
1796
|
* Determine which backend handles this key and strip prefix.
|
|
1764
1797
|
*
|
|
1765
1798
|
* @param key - Original file path
|
|
@@ -2565,11 +2598,15 @@ async function resolveRealPath(backend, canonical) {
|
|
|
2565
2598
|
/**
|
|
2566
2599
|
* Check whether `path` is permitted under `rules` for `operation`.
|
|
2567
2600
|
*
|
|
2568
|
-
* Returns the canonical path to hand the backend
|
|
2569
|
-
*
|
|
2570
|
-
*
|
|
2571
|
-
* backend has a realpath hook, the
|
|
2572
|
-
* touch. A deny on either blocks the
|
|
2601
|
+
* Returns the canonical path, the `target` to hand the backend for a
|
|
2602
|
+
* single-file operation, or an error string to surface to the model. The
|
|
2603
|
+
* decision covers every form of the target: the lexical canonical path (dot
|
|
2604
|
+
* and empty segments dropped) and, when the backend has a realpath hook, the
|
|
2605
|
+
* symlink-resolved path it would actually touch. A deny on either blocks the
|
|
2606
|
+
* call.
|
|
2607
|
+
*
|
|
2608
|
+
* `target` is the path with its parent resolved once and checked, so a
|
|
2609
|
+
* symlink swapped after the check cannot redirect the operation.
|
|
2573
2610
|
*
|
|
2574
2611
|
* Never throws: an invalid path (non-absolute, or containing `..` or `~`), one
|
|
2575
2612
|
* the backend cannot resolve, or a denied one is a recoverable tool error, not
|
|
@@ -2578,18 +2615,64 @@ async function resolveRealPath(backend, canonical) {
|
|
|
2578
2615
|
* @internal
|
|
2579
2616
|
*/
|
|
2580
2617
|
async function checkPermission(backend, rules, operation, path) {
|
|
2581
|
-
if (rules.length === 0) return {
|
|
2618
|
+
if (rules.length === 0) return {
|
|
2619
|
+
path,
|
|
2620
|
+
target: path
|
|
2621
|
+
};
|
|
2582
2622
|
let canonical;
|
|
2623
|
+
let target;
|
|
2583
2624
|
let real;
|
|
2584
2625
|
try {
|
|
2585
2626
|
canonical = validatePath(path);
|
|
2586
2627
|
if (decidePathAccess(rules, operation, canonical) === "deny") return { error: `Error: permission denied for ${operation} on ${canonical}` };
|
|
2587
|
-
|
|
2628
|
+
target = await resolveParentRealPath(backend, canonical);
|
|
2629
|
+
real = await resolveRealPath(backend, target);
|
|
2588
2630
|
} catch (error) {
|
|
2589
2631
|
return { error: `Error: ${getErrorMessage$1(error)}` };
|
|
2590
2632
|
}
|
|
2633
|
+
if (crossesRoute(backend, canonical, target)) return { error: `Error: ${canonical} resolves to ${target}, which is served by a different backend` };
|
|
2591
2634
|
if (real !== canonical && decidePathAccess(rules, operation, real) === "deny") return { error: `Error: permission denied for ${operation} on ${canonical} (resolves to ${real})` };
|
|
2592
|
-
return {
|
|
2635
|
+
return {
|
|
2636
|
+
path: canonical,
|
|
2637
|
+
target
|
|
2638
|
+
};
|
|
2639
|
+
}
|
|
2640
|
+
/**
|
|
2641
|
+
* Run a single-path `operation` on `target` through the backend's pin hook when
|
|
2642
|
+
* rules are configured and the backend has one, so the final decision is made
|
|
2643
|
+
* on the directory the operation actually uses. `isDenied` receives the real
|
|
2644
|
+
* path. Without a hook, `operation` runs on the path `checkPermission` resolved.
|
|
2645
|
+
*
|
|
2646
|
+
* Errors raised here, rather than by `operation`, start with `errorPrefix` so
|
|
2647
|
+
* they match how the calling tool formats backend errors.
|
|
2648
|
+
*/
|
|
2649
|
+
async function runBoundToTarget(backend, rules, target, options, isDenied, operation) {
|
|
2650
|
+
const pin = rules.length > 0 ? getPin(backend) : void 0;
|
|
2651
|
+
if (pin === void 0) return operation();
|
|
2652
|
+
const { create, describe, errorPrefix } = options;
|
|
2653
|
+
let operationStarted = false;
|
|
2654
|
+
try {
|
|
2655
|
+
return await pin(target, { create }, (realPath) => {
|
|
2656
|
+
const real = validatePath(realPath);
|
|
2657
|
+
return isDenied(real) ? `${errorPrefix}permission denied for ${describe} (resolves to ${real})` : void 0;
|
|
2658
|
+
}, () => {
|
|
2659
|
+
operationStarted = true;
|
|
2660
|
+
return operation();
|
|
2661
|
+
});
|
|
2662
|
+
} catch (error) {
|
|
2663
|
+
if (operationStarted) throw error;
|
|
2664
|
+
return { error: `${errorPrefix}${describe} failed: ${getErrorMessage$1(error)}` };
|
|
2665
|
+
}
|
|
2666
|
+
}
|
|
2667
|
+
/**
|
|
2668
|
+
* Whether `target` is served by a different `CompositeBackend` route than
|
|
2669
|
+
* `requested`. Symlink resolution must not move an operation to another
|
|
2670
|
+
* backend.
|
|
2671
|
+
*/
|
|
2672
|
+
function crossesRoute(backend, requested, target) {
|
|
2673
|
+
const resolveBackendForPath = backend.resolveBackendForPath;
|
|
2674
|
+
if (typeof resolveBackendForPath !== "function" || requested === target) return false;
|
|
2675
|
+
return resolveBackendForPath.call(backend, requested)[0] !== resolveBackendForPath.call(backend, target)[0];
|
|
2593
2676
|
}
|
|
2594
2677
|
/**
|
|
2595
2678
|
* Build an error {@link ToolMessage} for a denied path or a failed backend
|
|
@@ -2763,10 +2846,11 @@ function parentPath(path) {
|
|
|
2763
2846
|
return `/${parts.slice(0, -1).join("/")}`;
|
|
2764
2847
|
}
|
|
2765
2848
|
/**
|
|
2766
|
-
* Resolve
|
|
2767
|
-
*
|
|
2849
|
+
* Resolve symlinks in the parent of `target`, keeping its leaf as given.
|
|
2850
|
+
* Backends refuse to follow (or, for delete, unlink) a symlinked leaf, so this
|
|
2851
|
+
* is the path a single-file operation actually touches.
|
|
2768
2852
|
*/
|
|
2769
|
-
async function
|
|
2853
|
+
async function resolveParentRealPath(backend, target) {
|
|
2770
2854
|
const parts = posixParts(target);
|
|
2771
2855
|
if (parts.length === 0) return resolveRealPath(backend, target);
|
|
2772
2856
|
return validatePath(`${await resolveRealPath(backend, parentPath(target))}/${parts[parts.length - 1]}`);
|
|
@@ -2933,7 +3017,11 @@ function createReadFileTool(backend, options) {
|
|
|
2933
3017
|
if (permission.error !== void 0) return toolError(runtime, "read_file", permission.error);
|
|
2934
3018
|
const { file_path, offset: requestedOffset = 0, limit: requestedLimit = 100 } = input;
|
|
2935
3019
|
const { offset, limit } = normalizeReadPagination(requestedOffset, requestedLimit);
|
|
2936
|
-
const readResult = await resolvedBackend
|
|
3020
|
+
const readResult = await runBoundToTarget(resolvedBackend, permissions, permission.target, {
|
|
3021
|
+
create: false,
|
|
3022
|
+
describe: `read on ${permission.path}`,
|
|
3023
|
+
errorPrefix: ""
|
|
3024
|
+
}, (real) => decidePathAccess(permissions, "read", real) === "deny", async () => resolvedBackend.read(permission.target, offset, limit));
|
|
2937
3025
|
if (readResult.error) return toolError(runtime, "read_file", `Error: ${readResult.error}`);
|
|
2938
3026
|
const mimeType = readResult.mimeType ?? getMimeType(file_path);
|
|
2939
3027
|
if (!isTextMimeType(mimeType)) {
|
|
@@ -3017,7 +3105,11 @@ function createWriteFileTool(backend, options) {
|
|
|
3017
3105
|
const permission = await checkPermission(resolvedBackend, permissions, "write", input.file_path);
|
|
3018
3106
|
if (permission.error !== void 0) return toolError(runtime, "write_file", permission.error);
|
|
3019
3107
|
const { file_path, content } = input;
|
|
3020
|
-
const result = await resolvedBackend
|
|
3108
|
+
const result = await runBoundToTarget(resolvedBackend, permissions, permission.target, {
|
|
3109
|
+
create: true,
|
|
3110
|
+
describe: `write on ${permission.path}`,
|
|
3111
|
+
errorPrefix: "Error: "
|
|
3112
|
+
}, (real) => decidePathAccess(permissions, "write", real) === "deny", async () => resolvedBackend.write(permission.target, content));
|
|
3021
3113
|
if (result.error) return toolError(runtime, "write_file", result.error);
|
|
3022
3114
|
const message = new ToolMessage({
|
|
3023
3115
|
content: `Successfully wrote to '${file_path}'`,
|
|
@@ -3049,7 +3141,11 @@ function createEditFileTool(backend, options) {
|
|
|
3049
3141
|
const permission = await checkPermission(resolvedBackend, permissions, "write", input.file_path);
|
|
3050
3142
|
if (permission.error !== void 0) return toolError(runtime, "edit_file", permission.error);
|
|
3051
3143
|
const { file_path, old_string, new_string, replace_all = false } = input;
|
|
3052
|
-
const result = await resolvedBackend
|
|
3144
|
+
const result = await runBoundToTarget(resolvedBackend, permissions, permission.target, {
|
|
3145
|
+
create: false,
|
|
3146
|
+
describe: `write on ${permission.path}`,
|
|
3147
|
+
errorPrefix: "Error: "
|
|
3148
|
+
}, (real) => decidePathAccess(permissions, "write", real) === "deny", async () => resolvedBackend.edit(permission.target, old_string, new_string, replace_all));
|
|
3053
3149
|
if (result.error) return toolError(runtime, "edit_file", result.error);
|
|
3054
3150
|
const message = new ToolMessage({
|
|
3055
3151
|
content: `Successfully replaced ${result.occurrences} occurrence(s) in '${file_path}'`,
|
|
@@ -3089,22 +3185,29 @@ function createDeleteTool(backend, options) {
|
|
|
3089
3185
|
const hasDescendants = await deleteTargetMayHaveDescendants(resolvedBackend, validatedPath, permissions.length > 0);
|
|
3090
3186
|
const denyingPatterns = findDeleteDenyPatterns(permissions, validatedPath, hasDescendants);
|
|
3091
3187
|
if (denyingPatterns.length > 0) return toolError(runtime, "delete", `Error: permission denied for write on ${validatedPath} (matches deny rule(s): ${denyingPatterns.join(", ")})`);
|
|
3188
|
+
let deleteTarget = validatedPath;
|
|
3092
3189
|
if (permissions.length > 0) {
|
|
3093
3190
|
let realTarget;
|
|
3094
3191
|
try {
|
|
3095
|
-
realTarget = await
|
|
3192
|
+
realTarget = await resolveParentRealPath(resolvedBackend, validatedPath);
|
|
3096
3193
|
} catch (error) {
|
|
3097
3194
|
return toolError(runtime, "delete", `Error: ${getErrorMessage$1(error)}`);
|
|
3098
3195
|
}
|
|
3196
|
+
if (crossesRoute(resolvedBackend, validatedPath, realTarget)) return toolError(runtime, "delete", `Error: ${validatedPath} resolves to ${realTarget}, which is served by a different backend`);
|
|
3099
3197
|
if (realTarget !== validatedPath) {
|
|
3100
3198
|
if (findDeleteDenyPatterns(permissions, realTarget, hasDescendants).length > 0) return toolError(runtime, "delete", `Error: permission denied for write on ${validatedPath} (resolves to ${realTarget})`);
|
|
3101
3199
|
}
|
|
3200
|
+
deleteTarget = realTarget;
|
|
3102
3201
|
}
|
|
3103
3202
|
if (!supportsDelete(resolvedBackend)) return toolError(runtime, "delete", `Error: deletion is not available for '${validatedPath}'.`);
|
|
3104
|
-
const result = await resolvedBackend
|
|
3203
|
+
const result = await runBoundToTarget(resolvedBackend, permissions, deleteTarget, {
|
|
3204
|
+
create: false,
|
|
3205
|
+
describe: `write on ${validatedPath}`,
|
|
3206
|
+
errorPrefix: "Error: "
|
|
3207
|
+
}, (real) => findDeleteDenyPatterns(permissions, real, hasDescendants).length > 0, async () => resolvedBackend.delete(deleteTarget));
|
|
3105
3208
|
if (result.error) return toolError(runtime, "delete", result.error);
|
|
3106
3209
|
const message = new ToolMessage({
|
|
3107
|
-
content: `Deleted ${result.path
|
|
3210
|
+
content: `Deleted ${result.path === void 0 || result.path === deleteTarget ? validatedPath : result.path}`,
|
|
3108
3211
|
tool_call_id: runtime.toolCall?.id,
|
|
3109
3212
|
name: "delete",
|
|
3110
3213
|
metadata: result.metadata
|
|
@@ -3540,6 +3643,54 @@ function createFilesystemMiddleware(options = {}) {
|
|
|
3540
3643
|
}
|
|
3541
3644
|
});
|
|
3542
3645
|
}
|
|
3646
|
+
// src/middleware/refusal.ts
|
|
3647
|
+
/**
|
|
3648
|
+
* The task result reported when a model in the subagent refused.
|
|
3649
|
+
*
|
|
3650
|
+
* @param refusal - The refusal block from the model's reply.
|
|
3651
|
+
*/
|
|
3652
|
+
function refusalNotice(refusal) {
|
|
3653
|
+
let notice = "The subagent stopped because a model refused the request.";
|
|
3654
|
+
const category = refusal.extras?.category;
|
|
3655
|
+
if (category) notice += ` Category: ${String(category)}.`;
|
|
3656
|
+
if (refusal.refusal) notice += ` Explanation: "${refusal.refusal}"`;
|
|
3657
|
+
return `${notice} Retrying the same request is unlikely to succeed; rephrase it or continue without it.`;
|
|
3658
|
+
}
|
|
3659
|
+
/**
|
|
3660
|
+
* The refusal block in `message`, if it is a message that refused.
|
|
3661
|
+
*
|
|
3662
|
+
* @param message - The message to check. Callers often take it from an
|
|
3663
|
+
* unchecked cast, so non-messages are treated as no refusal.
|
|
3664
|
+
*/
|
|
3665
|
+
function refusalIn(message) {
|
|
3666
|
+
if (!BaseMessage.isInstance(message)) return void 0;
|
|
3667
|
+
try {
|
|
3668
|
+
return message.contentBlocks.find((block) => block.type === "refusal");
|
|
3669
|
+
} catch {
|
|
3670
|
+
return;
|
|
3671
|
+
}
|
|
3672
|
+
}
|
|
3673
|
+
/**
|
|
3674
|
+
* The task result for an error caused by a refusal, or `undefined` to rethrow it.
|
|
3675
|
+
*
|
|
3676
|
+
* Middleware wraps errors in `MiddlewareError`, so this walks the `cause` chain.
|
|
3677
|
+
*
|
|
3678
|
+
* @param error - The error the subagent run threw.
|
|
3679
|
+
*/
|
|
3680
|
+
function refusalNoticeFor(error) {
|
|
3681
|
+
let current = error;
|
|
3682
|
+
while (current) {
|
|
3683
|
+
if (ModelRefusalError.isInstance(current)) return refusalNotice(refusalIn(current.rawMessage) ?? {
|
|
3684
|
+
type: "refusal",
|
|
3685
|
+
refusal: current.message
|
|
3686
|
+
});
|
|
3687
|
+
if (typeof current === "object" && "aiMessage" in current) {
|
|
3688
|
+
const refusal = refusalIn(current.aiMessage);
|
|
3689
|
+
if (refusal) return refusalNotice(refusal);
|
|
3690
|
+
}
|
|
3691
|
+
current = typeof current === "object" && "cause" in current ? current.cause : void 0;
|
|
3692
|
+
}
|
|
3693
|
+
}
|
|
3543
3694
|
// src/middleware/summarization.ts
|
|
3544
3695
|
/**
|
|
3545
3696
|
* Summarization middleware with backend support for conversation history offloading.
|
|
@@ -4492,10 +4643,12 @@ const INVALID_TOOL_MESSAGE_BLOCK_TYPES = [
|
|
|
4492
4643
|
/**
|
|
4493
4644
|
* Create Command with filtered state update from subagent result
|
|
4494
4645
|
*/
|
|
4495
|
-
function returnCommandWithStateUpdate(result, toolCallId) {
|
|
4646
|
+
function returnCommandWithStateUpdate(result, toolCallId, checkpointNs) {
|
|
4496
4647
|
const stateUpdate = filterStateForSubagent(result);
|
|
4497
4648
|
let content;
|
|
4649
|
+
const refusal = refusalIn(result.messages?.at(-1));
|
|
4498
4650
|
if (result.structuredResponse != null) content = JSON.stringify(result.structuredResponse);
|
|
4651
|
+
else if (refusal) content = refusalNotice(refusal);
|
|
4499
4652
|
else {
|
|
4500
4653
|
const messages = result.messages ?? [];
|
|
4501
4654
|
content = "Task completed";
|
|
@@ -4514,10 +4667,66 @@ function returnCommandWithStateUpdate(result, toolCallId) {
|
|
|
4514
4667
|
messages: [new ToolMessage({
|
|
4515
4668
|
content,
|
|
4516
4669
|
tool_call_id: toolCallId,
|
|
4517
|
-
name: "task"
|
|
4670
|
+
name: "task",
|
|
4671
|
+
...checkpointNs ? { artifact: { checkpoint_ns: checkpointNs } } : {}
|
|
4518
4672
|
})]
|
|
4519
4673
|
} });
|
|
4520
4674
|
}
|
|
4675
|
+
function isCompiledGraph(value) {
|
|
4676
|
+
return typeof value === "object" && value !== null && "lg_is_pregel" in value && value.lg_is_pregel === true;
|
|
4677
|
+
}
|
|
4678
|
+
/**
|
|
4679
|
+
* Whether `value` is a plain `RunnableBinding`, such as `withListeners`
|
|
4680
|
+
* returns, and not a subclass. A subclass can override `invoke` with behaviour
|
|
4681
|
+
* that streaming its inner graph would skip, such as the `RunnableRetry` from
|
|
4682
|
+
* `withRetry`.
|
|
4683
|
+
*/
|
|
4684
|
+
function isPlainRunnableBinding(value) {
|
|
4685
|
+
return value?.constructor === RunnableBinding;
|
|
4686
|
+
}
|
|
4687
|
+
/**
|
|
4688
|
+
* The compiled graph behind a subagent: the subagent itself, the `graph` of a
|
|
4689
|
+
* `createAgent` agent, or the graph a plain `RunnableBinding` wraps.
|
|
4690
|
+
* `undefined` for any other runnable.
|
|
4691
|
+
*/
|
|
4692
|
+
function getCompiledGraph(subagent) {
|
|
4693
|
+
const unwrapped = isPlainRunnableBinding(subagent) ? subagent.bound : subagent;
|
|
4694
|
+
if (isCompiledGraph(unwrapped)) return unwrapped;
|
|
4695
|
+
const graph = unwrapped.graph;
|
|
4696
|
+
return isCompiledGraph(graph) ? graph : void 0;
|
|
4697
|
+
}
|
|
4698
|
+
/**
|
|
4699
|
+
* Invoke a subagent, returning its final state and the namespace it
|
|
4700
|
+
* checkpointed under.
|
|
4701
|
+
*
|
|
4702
|
+
* A compiled subagent is streamed rather than invoked so its checkpoint events
|
|
4703
|
+
* report the namespace it saved under. LangGraph changes that namespace from
|
|
4704
|
+
* the `task` call's own for a second run in the same step (`<namespace>|1`)
|
|
4705
|
+
* and for `checkpointer: true` (task ids removed). No checkpoint event means
|
|
4706
|
+
* nothing was saved. Any other runnable is invoked and assumed to save under
|
|
4707
|
+
* the `task` call's namespace.
|
|
4708
|
+
*/
|
|
4709
|
+
async function runSubagent(subagent, state, config) {
|
|
4710
|
+
const graph = getCompiledGraph(subagent);
|
|
4711
|
+
if (graph === void 0) return {
|
|
4712
|
+
result: await subagent.invoke(state, config),
|
|
4713
|
+
checkpointNs: config.configurable?.checkpoint_ns
|
|
4714
|
+
};
|
|
4715
|
+
let result = {};
|
|
4716
|
+
let checkpointNs;
|
|
4717
|
+
const options = {
|
|
4718
|
+
...config,
|
|
4719
|
+
streamMode: ["values", "checkpoints"],
|
|
4720
|
+
outputKeys: graph.outputChannels
|
|
4721
|
+
};
|
|
4722
|
+
const stream = await subagent.stream(state, options);
|
|
4723
|
+
for await (const [mode, chunk] of stream) if (mode === "values") result = chunk;
|
|
4724
|
+
else checkpointNs ??= chunk.config.configurable?.checkpoint_ns;
|
|
4725
|
+
return {
|
|
4726
|
+
result,
|
|
4727
|
+
checkpointNs
|
|
4728
|
+
};
|
|
4729
|
+
}
|
|
4521
4730
|
/** Drop the trailing in-flight AIMessage with unresolved tool_calls. */
|
|
4522
4731
|
function stripInFlightAIMessage(messages) {
|
|
4523
4732
|
const last = messages.at(-1);
|
|
@@ -4696,18 +4905,30 @@ function createTaskTool(options) {
|
|
|
4696
4905
|
...config,
|
|
4697
4906
|
metadata: {
|
|
4698
4907
|
...config.metadata,
|
|
4699
|
-
lc_agent_name: subagent_type
|
|
4908
|
+
lc_agent_name: subagent_type,
|
|
4909
|
+
...config.toolCall?.id && { lc_subagent_tool_call_id: config.toolCall.id }
|
|
4700
4910
|
},
|
|
4701
4911
|
configurable: {
|
|
4702
4912
|
...config.configurable,
|
|
4703
4913
|
ls_agent_type: "subagent"
|
|
4704
4914
|
}
|
|
4705
4915
|
};
|
|
4706
|
-
|
|
4916
|
+
let result;
|
|
4917
|
+
let checkpointNs;
|
|
4918
|
+
try {
|
|
4919
|
+
({result, checkpointNs} = await runSubagent(subagent, subagentState, subagentConfig));
|
|
4920
|
+
} catch (error) {
|
|
4921
|
+
const notice = refusalNoticeFor(error);
|
|
4922
|
+
if (notice === void 0) throw error;
|
|
4923
|
+
return notice;
|
|
4924
|
+
}
|
|
4707
4925
|
if (!config.toolCall?.id) {
|
|
4708
4926
|
if (result.structuredResponse != null) return JSON.stringify(result.structuredResponse);
|
|
4709
4927
|
const messages = result.messages;
|
|
4710
|
-
|
|
4928
|
+
const lastMessage = messages?.[messages.length - 1];
|
|
4929
|
+
const refusal = refusalIn(lastMessage);
|
|
4930
|
+
if (refusal) return refusalNotice(refusal);
|
|
4931
|
+
let content = lastMessage?.content || "Task completed";
|
|
4711
4932
|
if (Array.isArray(content)) {
|
|
4712
4933
|
content = content.filter((block) => !INVALID_TOOL_MESSAGE_BLOCK_TYPES.includes(block.type));
|
|
4713
4934
|
if (content.length === 0) return "Task completed";
|
|
@@ -4715,7 +4936,7 @@ function createTaskTool(options) {
|
|
|
4715
4936
|
}
|
|
4716
4937
|
return content;
|
|
4717
4938
|
}
|
|
4718
|
-
return returnCommandWithStateUpdate(result, config.toolCall.id);
|
|
4939
|
+
return returnCommandWithStateUpdate(result, config.toolCall.id, checkpointNs);
|
|
4719
4940
|
}
|
|
4720
4941
|
const taskToolSchema = z.object({
|
|
4721
4942
|
description: z.string().describe("The task to execute with the selected agent"),
|
|
@@ -7155,7 +7376,13 @@ function finalContent(values) {
|
|
|
7155
7376
|
}];
|
|
7156
7377
|
const last = messages[messages.length - 1];
|
|
7157
7378
|
try {
|
|
7158
|
-
|
|
7379
|
+
const message = coerceMessageLikeToMessage(last);
|
|
7380
|
+
const refusal = refusalIn(message);
|
|
7381
|
+
if (refusal) return [{
|
|
7382
|
+
type: "text",
|
|
7383
|
+
text: refusalNotice(refusal)
|
|
7384
|
+
}];
|
|
7385
|
+
return message.contentBlocks;
|
|
7159
7386
|
} catch {
|
|
7160
7387
|
return [{
|
|
7161
7388
|
type: "text",
|
|
@@ -8641,7 +8868,8 @@ function createDeepAgent(params = {}) {
|
|
|
8641
8868
|
backend,
|
|
8642
8869
|
sources: memory,
|
|
8643
8870
|
addCacheControl: anthropicModel
|
|
8644
|
-
})] : []
|
|
8871
|
+
})] : [],
|
|
8872
|
+
modelRefusalMiddleware()
|
|
8645
8873
|
]);
|
|
8646
8874
|
if (subagentProfile.excludedMiddleware.size > 0) subagentMiddleware = subagentMiddleware.filter((middleware) => !subagentProfile.excludedMiddleware.has(middleware.name));
|
|
8647
8875
|
if (subagentProfile.excludedTools.size > 0) subagentMiddleware.push(createToolExclusionMiddleware(subagentProfile.excludedTools));
|
|
@@ -8698,7 +8926,8 @@ function createDeepAgent(params = {}) {
|
|
|
8698
8926
|
...skillsMiddleware,
|
|
8699
8927
|
...cacheMiddleware,
|
|
8700
8928
|
...memoryMiddleware,
|
|
8701
|
-
...interruptOn ? [humanInTheLoopMiddleware({ interruptOn })] : []
|
|
8929
|
+
...interruptOn ? [humanInTheLoopMiddleware({ interruptOn })] : [],
|
|
8930
|
+
modelRefusalMiddleware()
|
|
8702
8931
|
]);
|
|
8703
8932
|
if (harnessProfile.excludedMiddleware.size > 0) {
|
|
8704
8933
|
const excluded = harnessProfile.excludedMiddleware;
|
|
@@ -10832,6 +11061,6 @@ var LangSmithSandbox = class LangSmithSandbox extends BaseSandbox {
|
|
|
10832
11061
|
});
|
|
10833
11062
|
}
|
|
10834
11063
|
};
|
|
10835
|
-
export { adaptSandboxProtocol as $, filesValue as A, createFilesystemMiddleware as B, MAX_SKILL_FILE_SIZE as C, skillsMetadataValue as D, pinnedSkillsValue as E, SUBAGENT_RESPONSE_FORMAT_CONFIG_KEY as F, scrubUnsupportedMultimodalContent as G, MULTIMODAL_BLOCK_TYPES as H, createSubAgent as I, applyGrepMaxCount as J, StateBackend as K, createSubAgentMiddleware as L, DEFAULT_GENERAL_PURPOSE_DESCRIPTION as M, DEFAULT_SUBAGENT_PROMPT as N, ConfigurationError as O, GENERAL_PURPOSE_SUBAGENT as P, adaptBackendProtocol as Q, computeSummarizationDefaults as R, MAX_SKILL_DESCRIPTION_LENGTH as S, createSkillsMiddleware as T, createUnsupportedContentMiddleware as U, CompositeBackend as V, multimodalBlockSupported as W, isSandboxProtocol as X, isSandboxBackend as Y, resolveBackend as Z, createHarnessProfile as _, ASYNC_TASK_SYSTEM_PROMPT as a,
|
|
11064
|
+
export { adaptSandboxProtocol as $, filesValue as A, createFilesystemMiddleware as B, MAX_SKILL_FILE_SIZE as C, skillsMetadataValue as D, pinnedSkillsValue as E, SUBAGENT_RESPONSE_FORMAT_CONFIG_KEY as F, scrubUnsupportedMultimodalContent as G, MULTIMODAL_BLOCK_TYPES as H, createSubAgent as I, applyGrepMaxCount as J, StateBackend as K, createSubAgentMiddleware as L, DEFAULT_GENERAL_PURPOSE_DESCRIPTION as M, DEFAULT_SUBAGENT_PROMPT as N, ConfigurationError as O, GENERAL_PURPOSE_SUBAGENT as P, adaptBackendProtocol as Q, computeSummarizationDefaults as R, MAX_SKILL_DESCRIPTION_LENGTH as S, createSkillsMiddleware as T, createUnsupportedContentMiddleware as U, CompositeBackend as V, multimodalBlockSupported as W, isSandboxProtocol as X, isSandboxBackend as Y, resolveBackend as Z, createHarnessProfile as _, ASYNC_TASK_SYSTEM_PROMPT as a, setPin as at, isAsyncSubAgent as b, TASK_SYSTEM_PROMPT as c, registerHarnessProfile as d, checkEmptyContent as et, generalPurposeSubagentConfigSchema as f, EMPTY_HARNESS_PROFILE as g, serializeProfile as h, StoreBackend as i, performStringReplacement as it, createPatchToolCallsMiddleware as j, createMemoryMiddleware as k, createDeepAgent as l, parseHarnessProfileConfig as m, BaseSandbox as n, isTextMimeType as nt, BASE_AGENT_PROMPT as o, setRealpath as ot, harnessProfileConfigSchema as p, SandboxError as q, ContextHubBackend as r, normalizeReadPagination as rt, EXECUTION_SYSTEM_PROMPT as s, LangSmithSandbox as t, getMimeType as tt, getHarnessProfile as u, REQUIRED_MIDDLEWARE_NAMES as v, MAX_SKILL_NAME_LENGTH as w, createCompletionCallbackMiddleware as x, createAsyncSubAgentMiddleware as y, createSummarizationMiddleware as z };
|
|
10836
11065
|
|
|
10837
|
-
//# sourceMappingURL=langsmith-
|
|
11066
|
+
//# sourceMappingURL=langsmith-CH6GPPud.js.map
|