@botbotgo/agent-harness 0.0.326 → 0.0.328
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/cli/chat-stream.js +33 -27
- package/dist/cli/main.js +30 -3
- package/dist/contracts/runtime-requests.d.ts +1 -2
- package/dist/contracts/runtime-scheduling.d.ts +1 -1
- package/dist/flow/flow-graph-upstream.js +3 -7
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -1
- package/dist/projections/request-events.js +0 -1
- package/dist/resource/isolation.js +51 -10
- package/dist/resources/toolkit.mjs +183 -0
- package/dist/resources/tools/cancel_request.mjs +1 -1
- package/dist/resources/tools/fetch_url.mjs +1 -1
- package/dist/resources/tools/http_request.mjs +1 -1
- package/dist/resources/tools/inspect_approvals.mjs +1 -1
- package/dist/resources/tools/inspect_artifacts.mjs +1 -1
- package/dist/resources/tools/inspect_events.mjs +1 -1
- package/dist/resources/tools/inspect_requests.mjs +1 -1
- package/dist/resources/tools/inspect_sessions.mjs +1 -1
- package/dist/resources/tools/list_files.mjs +1 -1
- package/dist/resources/tools/read_artifact.mjs +1 -1
- package/dist/resources/tools/request_approval.mjs +1 -1
- package/dist/resources/tools/run_command.mjs +1 -1
- package/dist/resources/tools/schedule_task.mjs +1 -1
- package/dist/resources/tools/search_files.mjs +1 -1
- package/dist/resources/tools/send_message.mjs +1 -1
- package/dist/runtime/adapter/compat/deepagent-compat.d.ts +0 -9
- package/dist/runtime/adapter/compat/deepagent-compat.js +0 -22
- package/dist/runtime/adapter/flow/stream-runtime.d.ts +4 -0
- package/dist/runtime/adapter/flow/stream-runtime.js +239 -8
- package/dist/runtime/adapter/local-tool-invocation.js +53 -0
- package/dist/runtime/adapter/middleware-assembly.js +174 -29
- package/dist/runtime/adapter/runtime-adapter-support.js +1 -2
- package/dist/runtime/adapter/stream-event-projection.d.ts +17 -0
- package/dist/runtime/adapter/stream-event-projection.js +217 -4
- package/dist/runtime/adapter/tool/builtin-middleware-tools.d.ts +0 -3
- package/dist/runtime/adapter/tool/builtin-middleware-tools.js +37 -17
- package/dist/runtime/adapter/tool/resolved-tool.js +29 -3
- package/dist/runtime/agent-runtime-adapter.d.ts +3 -3
- package/dist/runtime/agent-runtime-adapter.js +12 -33
- package/dist/runtime/agent-runtime-assembly.d.ts +3 -21
- package/dist/runtime/agent-runtime-assembly.js +4 -56
- package/dist/runtime/harness/run/inspection.js +21 -5
- package/dist/runtime/harness/run/run-operations.js +2 -1
- package/dist/runtime/harness/run/stream-run.d.ts +3 -1
- package/dist/runtime/harness/run/stream-run.js +206 -30
- package/dist/runtime/harness.js +3 -0
- package/dist/runtime/parsing/output-content.js +11 -4
- package/dist/runtime/parsing/output-recovery.d.ts +3 -0
- package/dist/runtime/parsing/output-recovery.js +57 -11
- package/dist/runtime/parsing/output-tool-args.d.ts +4 -0
- package/dist/runtime/parsing/output-tool-args.js +122 -0
- package/dist/runtime/parsing/stream-event-parsing.js +37 -3
- package/dist/runtime/support/harness-support.d.ts +1 -0
- package/dist/runtime/support/harness-support.js +44 -2
- package/dist/tools.js +34 -4
- package/package.json +8 -8
|
@@ -4,6 +4,28 @@ import { isSandboxBackend } from "deepagents";
|
|
|
4
4
|
import { isRecord } from "../../../utils/object.js";
|
|
5
5
|
import { formatBuiltinTodoSnapshot, isLowSignalTodoContent, summarizeBuiltinWriteTodosArgs, truncateLines } from "../runtime-adapter-support.js";
|
|
6
6
|
import { maybePersistLargeToolOutput, resolveToolRuntimeContext } from "./tool-output-artifacts.js";
|
|
7
|
+
const taskToolSchema = z.preprocess((value) => {
|
|
8
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
return normalizeTaskToolInput(value);
|
|
12
|
+
}, z.object({
|
|
13
|
+
description: z.string(),
|
|
14
|
+
subagent_type: z.string(),
|
|
15
|
+
}).passthrough());
|
|
16
|
+
function normalizeTaskToolInput(typed) {
|
|
17
|
+
const description = typeof typed.description === "string" && typed.description.trim().length > 0
|
|
18
|
+
? typed.description
|
|
19
|
+
: undefined;
|
|
20
|
+
const subagentType = typeof typed.subagent_type === "string" && typed.subagent_type.trim().length > 0
|
|
21
|
+
? typed.subagent_type
|
|
22
|
+
: undefined;
|
|
23
|
+
return {
|
|
24
|
+
...typed,
|
|
25
|
+
...(description !== undefined ? { description } : {}),
|
|
26
|
+
...(subagentType !== undefined ? { subagent_type: subagentType } : {}),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
7
29
|
export const BUILTIN_MIDDLEWARE_TOOL_DESCRIPTORS = [
|
|
8
30
|
{ name: "write_todos", description: "Create and update the runtime todo board for multi-step work." },
|
|
9
31
|
{ name: "read_todos", description: "Read the current runtime todo board." },
|
|
@@ -23,7 +45,6 @@ export const BUILTIN_MIDDLEWARE_TOOL_DESCRIPTORS = [
|
|
|
23
45
|
{ name: "request_approval", description: "Request an approval decision from the runtime." },
|
|
24
46
|
{ name: "schedule_task", description: "Create, inspect, update, list, and delete system-level scheduled tasks." },
|
|
25
47
|
{ name: "task", description: "Delegate a bounded task to a subagent." },
|
|
26
|
-
{ name: "delegate_task", description: "Delegate a bounded task to a subagent." },
|
|
27
48
|
];
|
|
28
49
|
function toDisplayContent(content) {
|
|
29
50
|
if (typeof content === "string") {
|
|
@@ -181,7 +202,6 @@ export async function createBuiltinMiddlewareTools(backend, options) {
|
|
|
181
202
|
completed: 0,
|
|
182
203
|
failed: 0,
|
|
183
204
|
cancelled: 0,
|
|
184
|
-
blocked: 0,
|
|
185
205
|
},
|
|
186
206
|
};
|
|
187
207
|
const finalizeOutput = async (toolName, output, toolConfig) => maybePersistLargeToolOutput({
|
|
@@ -193,7 +213,17 @@ export async function createBuiltinMiddlewareTools(backend, options) {
|
|
|
193
213
|
name: "write_todos",
|
|
194
214
|
description: "Create and update the runtime todo board for multi-step work.",
|
|
195
215
|
schema: z.object({
|
|
196
|
-
todos: z.array(z.object({
|
|
216
|
+
todos: z.array(z.object({
|
|
217
|
+
id: z.string().optional(),
|
|
218
|
+
content: z.string().optional(),
|
|
219
|
+
description: z.string().optional(),
|
|
220
|
+
status: z.enum(["pending", "in_progress", "completed", "failed", "cancelled"]).optional(),
|
|
221
|
+
ownerAgentId: z.string().optional(),
|
|
222
|
+
startedAt: z.string().optional(),
|
|
223
|
+
endedAt: z.string().optional(),
|
|
224
|
+
result: z.unknown().optional(),
|
|
225
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
226
|
+
}).passthrough()).optional(),
|
|
197
227
|
}).passthrough(),
|
|
198
228
|
invoke: async (input) => {
|
|
199
229
|
const args = isRecord(input) ? input : {};
|
|
@@ -584,20 +614,10 @@ export async function createBuiltinMiddlewareTools(backend, options) {
|
|
|
584
614
|
tools.set("task", {
|
|
585
615
|
name: "task",
|
|
586
616
|
description: "Delegate a bounded task to a subagent.",
|
|
587
|
-
schema:
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
invoke: options.invokeTaskTool,
|
|
592
|
-
});
|
|
593
|
-
tools.set("delegate_task", {
|
|
594
|
-
name: "delegate_task",
|
|
595
|
-
description: "Delegate a bounded task to a subagent.",
|
|
596
|
-
schema: z.object({
|
|
597
|
-
description: z.string(),
|
|
598
|
-
subagent_type: z.string(),
|
|
599
|
-
}).passthrough(),
|
|
600
|
-
invoke: async (input) => tools.get("task").invoke(input),
|
|
617
|
+
schema: taskToolSchema,
|
|
618
|
+
invoke: async (input, config) => options.invokeTaskTool(typeof input === "object" && input !== null && !Array.isArray(input)
|
|
619
|
+
? normalizeTaskToolInput(input)
|
|
620
|
+
: {}),
|
|
601
621
|
});
|
|
602
622
|
}
|
|
603
623
|
return tools;
|
|
@@ -19,6 +19,9 @@ function getZodLikeTypeName(value) {
|
|
|
19
19
|
return undefined;
|
|
20
20
|
}
|
|
21
21
|
const typed = value;
|
|
22
|
+
if (typeof typed.def?.type === "string") {
|
|
23
|
+
return typed.def.type;
|
|
24
|
+
}
|
|
22
25
|
if (typeof typed._zod?.def?.type === "string") {
|
|
23
26
|
return typed._zod.def.type;
|
|
24
27
|
}
|
|
@@ -32,7 +35,21 @@ function getZodLikeInnerSchema(value) {
|
|
|
32
35
|
return undefined;
|
|
33
36
|
}
|
|
34
37
|
const typed = value;
|
|
35
|
-
return typed.
|
|
38
|
+
return typed.def?.innerType
|
|
39
|
+
?? typed.def?.element
|
|
40
|
+
?? typed.def?.valueType
|
|
41
|
+
?? typed.def?.schema
|
|
42
|
+
?? typed.def?.out
|
|
43
|
+
?? typed.def?.in
|
|
44
|
+
?? typed._zod?.def?.innerType
|
|
45
|
+
?? typed._zod?.def?.element
|
|
46
|
+
?? typed._zod?.def?.valueType
|
|
47
|
+
?? typed._def?.innerType
|
|
48
|
+
?? typed._def?.schema
|
|
49
|
+
?? typed._def?.type
|
|
50
|
+
?? typed._def?.valueType
|
|
51
|
+
?? typed._def?.in
|
|
52
|
+
?? typed._def?.out;
|
|
36
53
|
}
|
|
37
54
|
function getZodLikeObjectShape(value) {
|
|
38
55
|
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
@@ -58,7 +75,13 @@ function isZodLikeOptional(value) {
|
|
|
58
75
|
if (!typeName) {
|
|
59
76
|
return false;
|
|
60
77
|
}
|
|
61
|
-
|
|
78
|
+
if (typeName === "optional" || typeName === "default" || typeName === "catch") {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
if (typeName === "effects" || typeName === "pipeline" || typeName === "pipe" || typeName === "transform") {
|
|
82
|
+
return isZodLikeOptional(getZodLikeInnerSchema(value));
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
62
85
|
}
|
|
63
86
|
function buildBestEffortJsonSchema(value) {
|
|
64
87
|
const shape = isZodRawShape(value) ? value : getZodLikeObjectShape(value);
|
|
@@ -70,7 +93,7 @@ function buildBestEffortJsonSchema(value) {
|
|
|
70
93
|
return {
|
|
71
94
|
type: "object",
|
|
72
95
|
properties,
|
|
73
|
-
|
|
96
|
+
required,
|
|
74
97
|
};
|
|
75
98
|
}
|
|
76
99
|
const typeName = getZodLikeTypeName(value);
|
|
@@ -101,6 +124,9 @@ function buildBestEffortJsonSchema(value) {
|
|
|
101
124
|
additionalProperties: buildBestEffortJsonSchema(getZodLikeInnerSchema(value)) ?? {},
|
|
102
125
|
};
|
|
103
126
|
}
|
|
127
|
+
if (typeName === "effects" || typeName === "pipeline" || typeName === "pipe" || typeName === "transform") {
|
|
128
|
+
return buildBestEffortJsonSchema(getZodLikeInnerSchema(value)) ?? {};
|
|
129
|
+
}
|
|
104
130
|
return {};
|
|
105
131
|
}
|
|
106
132
|
function jsonSchemaPreservesShape(schema, expectedKeys) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { CompiledAgentBinding, MessageContent, RequestResult, RuntimeAdapterOptions, TranscriptMessage } from "../contracts/types.js";
|
|
2
2
|
import { type RuntimeStreamChunk } from "./parsing/stream-event-parsing.js";
|
|
3
|
-
import { AGENT_INTERRUPT_SENTINEL_PREFIX, buildDeepAgentCreateParams, buildLangChainCreateParams,
|
|
3
|
+
import { AGENT_INTERRUPT_SENTINEL_PREFIX, buildDeepAgentCreateParams, buildLangChainCreateParams, materializeModelExposedBuiltinMiddlewareTools, resolveLangChainInvocationConfig, resolveRunnableCheckpointer, resolveRunnableInterruptOn } from "./agent-runtime-assembly.js";
|
|
4
4
|
import { RuntimeOperationTimeoutError } from "./adapter/runtime-shell.js";
|
|
5
|
-
export {
|
|
5
|
+
export { materializeDeepAgentSkillSourcePaths, resolveDeepAgentSkillSourcePaths, relativizeDeepAgentSkillSourcePaths, } from "./adapter/compat/deepagent-compat.js";
|
|
6
6
|
export { buildAuthOmittingFetch, normalizeOpenAICompatibleInit } from "./adapter/compat/openai-compatible.js";
|
|
7
7
|
export { buildToolNameMapping, createModelFacingToolNameCandidates, createModelFacingToolNameLookupCandidates, resolveModelFacingToolName, sanitizeToolNameForModel, } from "./adapter/tool/tool-name-mapping.js";
|
|
8
8
|
export { computeRemainingTimeoutMs, isRetryableProviderError, resolveBindingTimeout, resolveProviderRetryPolicy, resolveStreamIdleTimeout, resolveTimeoutMs, } from "./adapter/resilience.js";
|
|
@@ -66,4 +66,4 @@ export declare class AgentRuntimeAdapter {
|
|
|
66
66
|
toolRuntimeContext?: Record<string, unknown>;
|
|
67
67
|
}): AsyncGenerator<RuntimeStreamChunk | string>;
|
|
68
68
|
}
|
|
69
|
-
export { AgentRuntimeAdapter as RuntimeAdapter, AGENT_INTERRUPT_SENTINEL_PREFIX, AGENT_INTERRUPT_SENTINEL_PREFIX as INTERRUPT_SENTINEL_PREFIX, buildDeepAgentCreateParams, buildLangChainCreateParams,
|
|
69
|
+
export { AgentRuntimeAdapter as RuntimeAdapter, AGENT_INTERRUPT_SENTINEL_PREFIX, AGENT_INTERRUPT_SENTINEL_PREFIX as INTERRUPT_SENTINEL_PREFIX, buildDeepAgentCreateParams, buildLangChainCreateParams, materializeModelExposedBuiltinMiddlewareTools, resolveLangChainInvocationConfig, resolveRunnableCheckpointer, resolveRunnableInterruptOn, RuntimeOperationTimeoutError, };
|
|
@@ -2,7 +2,7 @@ import path from "node:path";
|
|
|
2
2
|
import { createDeepAgent, FilesystemBackend, } from "deepagents";
|
|
3
3
|
import { createAgent } from "langchain";
|
|
4
4
|
import { wrapResolvedModel, } from "./parsing/output-parsing.js";
|
|
5
|
-
import { AGENT_INTERRUPT_SENTINEL_PREFIX, buildDeepAgentCreateParams, buildLangChainCreateParams,
|
|
5
|
+
import { AGENT_INTERRUPT_SENTINEL_PREFIX, buildDeepAgentCreateParams, buildLangChainCreateParams, materializeModelExposedBuiltinMiddlewareTools, resolveLangChainInvocationConfig, resolveRunnableCheckpointer, resolveRunnableInterruptOn, shouldAttachDeepAgentBackend, shouldAttachDeepAgentCheckpointer, shouldAttachDeepAgentStore, } from "./agent-runtime-assembly.js";
|
|
6
6
|
import { resolveDeepAgentSkillSourcePaths, } from "./adapter/compat/deepagent-compat.js";
|
|
7
7
|
import { buildToolNameMapping, } from "./adapter/tool/tool-name-mapping.js";
|
|
8
8
|
import { executeRequestInvocation } from "./adapter/flow/invocation-flow.js";
|
|
@@ -15,7 +15,7 @@ import { renderDirectWorkspaceListing, shouldDirectlyListWorkspaceFiles } from "
|
|
|
15
15
|
import { resolveAdapterTools } from "./adapter/tool-resolution.js";
|
|
16
16
|
import { resolveRuntimeStreamExecutionContext, } from "./adapter/flow/execution-context.js";
|
|
17
17
|
import { isRetryableProviderError } from "./adapter/resilience.js";
|
|
18
|
-
export {
|
|
18
|
+
export { materializeDeepAgentSkillSourcePaths, resolveDeepAgentSkillSourcePaths, relativizeDeepAgentSkillSourcePaths, } from "./adapter/compat/deepagent-compat.js";
|
|
19
19
|
export { buildAuthOmittingFetch, normalizeOpenAICompatibleInit } from "./adapter/compat/openai-compatible.js";
|
|
20
20
|
export { buildToolNameMapping, createModelFacingToolNameCandidates, createModelFacingToolNameLookupCandidates, resolveModelFacingToolName, sanitizeToolNameForModel, } from "./adapter/tool/tool-name-mapping.js";
|
|
21
21
|
export { computeRemainingTimeoutMs, isRetryableProviderError, resolveBindingTimeout, resolveProviderRetryPolicy, resolveStreamIdleTimeout, resolveTimeoutMs, } from "./adapter/resilience.js";
|
|
@@ -354,18 +354,11 @@ export class AgentRuntimeAdapter {
|
|
|
354
354
|
const resolvedMiddleware = await this.resolveMiddleware(binding);
|
|
355
355
|
const resolvedSubagents = await this.resolveDeepAgentSubagents(getBindingDeepAgentSubagents(binding), binding);
|
|
356
356
|
const resolvedInterruptOn = resolveRunnableInterruptOn(binding);
|
|
357
|
-
const
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
: resolveRunnableCheckpointer(this.options, binding);
|
|
363
|
-
const resolvedStore = substrateMode === "minimal"
|
|
364
|
-
? (shouldAttachMinimalDeepAgentStore(binding) ? this.options.storeResolver?.(binding) : undefined)
|
|
365
|
-
: this.options.storeResolver?.(binding);
|
|
366
|
-
const resolvedBackend = substrateMode === "minimal"
|
|
367
|
-
? (shouldAttachMinimalDeepAgentBackend(binding) ? this.options.backendResolver?.(binding) : undefined)
|
|
368
|
-
: this.options.backendResolver?.(binding);
|
|
357
|
+
const resolvedCheckpointer = shouldAttachDeepAgentCheckpointer(binding, resolvedInterruptOn)
|
|
358
|
+
? resolveRunnableCheckpointer(this.options, binding)
|
|
359
|
+
: undefined;
|
|
360
|
+
const resolvedStore = shouldAttachDeepAgentStore(binding) ? this.options.storeResolver?.(binding) : undefined;
|
|
361
|
+
const resolvedBackend = shouldAttachDeepAgentBackend(binding) ? this.options.backendResolver?.(binding) : undefined;
|
|
369
362
|
const resolvedSkills = resolveDeepAgentSkillSourcePaths({
|
|
370
363
|
workspaceRoot: binding.harnessRuntime.workspaceRoot,
|
|
371
364
|
runtimeRoot: binding.harnessRuntime.runtimeRoot,
|
|
@@ -384,24 +377,6 @@ export class AgentRuntimeAdapter {
|
|
|
384
377
|
resolvedInterruptOn,
|
|
385
378
|
resolvedSkills,
|
|
386
379
|
});
|
|
387
|
-
if (shouldUseMinimalDeepAgentAssembly({
|
|
388
|
-
binding,
|
|
389
|
-
resolvedMiddleware,
|
|
390
|
-
resolvedSubagents,
|
|
391
|
-
resolvedInterruptOn,
|
|
392
|
-
resolvedSkills,
|
|
393
|
-
resolvedBackend,
|
|
394
|
-
})) {
|
|
395
|
-
const minimalDeepAgentConfig = buildMinimalDeepAgentCreateParams({
|
|
396
|
-
binding,
|
|
397
|
-
resolvedModel,
|
|
398
|
-
resolvedTools: [...resolvedTools, ...builtinMiddlewareTools],
|
|
399
|
-
resolvedCheckpointer,
|
|
400
|
-
resolvedStore,
|
|
401
|
-
resolvedBackend,
|
|
402
|
-
});
|
|
403
|
-
return createAgent(minimalDeepAgentConfig);
|
|
404
|
-
}
|
|
405
380
|
return createDeepAgent(deepAgentConfig);
|
|
406
381
|
}
|
|
407
382
|
buildRunnableCacheKey(binding, sessionId) {
|
|
@@ -559,7 +534,11 @@ export class AgentRuntimeAdapter {
|
|
|
559
534
|
isLangChainBinding,
|
|
560
535
|
isDeepAgentBinding,
|
|
561
536
|
countConfiguredTools: getBindingToolCount,
|
|
537
|
+
countConfiguredToolsForAgentId: (agentId) => {
|
|
538
|
+
const resolved = this.options.bindingResolver?.(agentId);
|
|
539
|
+
return resolved ? getBindingToolCount(resolved) : 0;
|
|
540
|
+
},
|
|
562
541
|
});
|
|
563
542
|
}
|
|
564
543
|
}
|
|
565
|
-
export { AgentRuntimeAdapter as RuntimeAdapter, AGENT_INTERRUPT_SENTINEL_PREFIX, AGENT_INTERRUPT_SENTINEL_PREFIX as INTERRUPT_SENTINEL_PREFIX, buildDeepAgentCreateParams, buildLangChainCreateParams,
|
|
544
|
+
export { AgentRuntimeAdapter as RuntimeAdapter, AGENT_INTERRUPT_SENTINEL_PREFIX, AGENT_INTERRUPT_SENTINEL_PREFIX as INTERRUPT_SENTINEL_PREFIX, buildDeepAgentCreateParams, buildLangChainCreateParams, materializeModelExposedBuiltinMiddlewareTools, resolveLangChainInvocationConfig, resolveRunnableCheckpointer, resolveRunnableInterruptOn, RuntimeOperationTimeoutError, };
|
|
@@ -42,26 +42,8 @@ export declare function buildDeepAgentCreateParams(input: {
|
|
|
42
42
|
}>;
|
|
43
43
|
resolvedSkills: string[];
|
|
44
44
|
}): Record<string, unknown>;
|
|
45
|
-
export declare function
|
|
46
|
-
binding: CompiledAgentBinding;
|
|
47
|
-
resolvedMiddleware: unknown[];
|
|
48
|
-
resolvedSubagents: Array<UpstreamSubagentConfig | CompiledAsyncSubAgent>;
|
|
49
|
-
resolvedInterruptOn?: Record<string, {
|
|
50
|
-
allowedDecisions: Array<"approve" | "edit" | "reject">;
|
|
51
|
-
}>;
|
|
52
|
-
resolvedSkills: string[];
|
|
53
|
-
resolvedBackend?: unknown;
|
|
54
|
-
}): boolean;
|
|
55
|
-
export declare function buildMinimalDeepAgentCreateParams(input: {
|
|
56
|
-
binding: CompiledAgentBinding;
|
|
57
|
-
resolvedModel: unknown;
|
|
58
|
-
resolvedTools: unknown[];
|
|
59
|
-
resolvedCheckpointer?: unknown;
|
|
60
|
-
resolvedStore?: unknown;
|
|
61
|
-
resolvedBackend: unknown;
|
|
62
|
-
}): Record<string, unknown>;
|
|
63
|
-
export declare function shouldAttachMinimalDeepAgentCheckpointer(binding: CompiledAgentBinding, resolvedInterruptOn?: Record<string, {
|
|
45
|
+
export declare function shouldAttachDeepAgentCheckpointer(binding: CompiledAgentBinding, resolvedInterruptOn?: Record<string, {
|
|
64
46
|
allowedDecisions: Array<"approve" | "edit" | "reject">;
|
|
65
47
|
}>): boolean;
|
|
66
|
-
export declare function
|
|
67
|
-
export declare function
|
|
48
|
+
export declare function shouldAttachDeepAgentStore(binding: CompiledAgentBinding): boolean;
|
|
49
|
+
export declare function shouldAttachDeepAgentBackend(binding: CompiledAgentBinding): boolean;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { MemorySaver } from "@langchain/langgraph";
|
|
2
|
-
import { createFilesystemMiddleware, createPatchToolCallsMiddleware } from "deepagents";
|
|
3
|
-
import { todoListMiddleware } from "langchain";
|
|
4
2
|
import { UPSTREAM_REQUEST_CONFIG_KEY, UPSTREAM_SESSION_CONFIG_KEY } from "./adapter/upstream-configurable-keys.js";
|
|
5
3
|
import { asStructuredExecutableTool } from "./adapter/tool/resolved-tool.js";
|
|
6
4
|
import { compileInterruptOn } from "./adapter/tool/interrupt-policy.js";
|
|
7
|
-
import { getBindingBackendConfig,
|
|
5
|
+
import { getBindingBackendConfig, getBindingExecutionKind, getBindingExecutionParams, getBindingInterruptCompatibilityRules, getBindingMemorySources, getBindingMiddlewareConfigs, getBindingPrimaryTools, getBindingSkills, getBindingStoreConfig, } from "./support/compiled-binding.js";
|
|
8
6
|
export const AGENT_INTERRUPT_SENTINEL_PREFIX = "__agent_harness_interrupt__:";
|
|
9
7
|
const BUILTIN_MIDDLEWARE_ALIAS_TOOL_NAMES = new Set([
|
|
10
8
|
"list_files",
|
|
11
9
|
"search_files",
|
|
12
10
|
"run_command",
|
|
13
|
-
"delegate_task",
|
|
14
11
|
]);
|
|
15
12
|
const MODEL_EXPOSED_BUILTIN_MIDDLEWARE_TOOL_NAMES = new Set([
|
|
16
13
|
"fetch_url",
|
|
@@ -145,65 +142,16 @@ export function buildDeepAgentCreateParams(input) {
|
|
|
145
142
|
...(input.resolvedBackend !== undefined ? { backend: input.resolvedBackend } : {}),
|
|
146
143
|
};
|
|
147
144
|
}
|
|
148
|
-
export function
|
|
149
|
-
const executionKind = getBindingExecutionKind(input.binding);
|
|
150
|
-
if (executionKind !== "deepagent") {
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
if (input.resolvedBackend === undefined) {
|
|
154
|
-
return false;
|
|
155
|
-
}
|
|
156
|
-
if (input.resolvedSkills.length > 0) {
|
|
157
|
-
return false;
|
|
158
|
-
}
|
|
159
|
-
if (input.resolvedSubagents.length > 0 || getBindingDeepAgentSubagents(input.binding).length > 0) {
|
|
160
|
-
return false;
|
|
161
|
-
}
|
|
162
|
-
if (getBindingMemorySources(input.binding).length > 0) {
|
|
163
|
-
return false;
|
|
164
|
-
}
|
|
165
|
-
if (input.resolvedMiddleware.length > 0 || (getBindingMiddlewareConfigs(input.binding)?.length ?? 0) > 0) {
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
return input.resolvedInterruptOn === undefined || Object.keys(input.resolvedInterruptOn).length === 0;
|
|
169
|
-
}
|
|
170
|
-
export function buildMinimalDeepAgentCreateParams(input) {
|
|
171
|
-
const executionKind = getBindingExecutionKind(input.binding);
|
|
172
|
-
if (executionKind !== "deepagent" || !getBindingExecutionParams(input.binding)) {
|
|
173
|
-
throw new Error(`Agent ${input.binding.agent.id} has no runnable params`);
|
|
174
|
-
}
|
|
175
|
-
const upstreamParams = buildUpstreamCreateBaseParams(input.binding, [
|
|
176
|
-
"systemPrompt",
|
|
177
|
-
"contextSchema",
|
|
178
|
-
"responseFormat",
|
|
179
|
-
"name",
|
|
180
|
-
"description",
|
|
181
|
-
"includeAgentName",
|
|
182
|
-
"version",
|
|
183
|
-
]);
|
|
184
|
-
return {
|
|
185
|
-
...upstreamParams,
|
|
186
|
-
model: input.resolvedModel,
|
|
187
|
-
tools: input.resolvedTools,
|
|
188
|
-
middleware: [
|
|
189
|
-
todoListMiddleware(),
|
|
190
|
-
createFilesystemMiddleware({ backend: input.resolvedBackend }),
|
|
191
|
-
createPatchToolCallsMiddleware(),
|
|
192
|
-
],
|
|
193
|
-
...(input.resolvedCheckpointer !== undefined ? { checkpointer: input.resolvedCheckpointer } : {}),
|
|
194
|
-
...(input.resolvedStore !== undefined ? { store: input.resolvedStore } : {}),
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
export function shouldAttachMinimalDeepAgentCheckpointer(binding, resolvedInterruptOn) {
|
|
145
|
+
export function shouldAttachDeepAgentCheckpointer(binding, resolvedInterruptOn) {
|
|
198
146
|
if (binding.harnessRuntime.checkpointer !== undefined) {
|
|
199
147
|
return true;
|
|
200
148
|
}
|
|
201
149
|
return resolvedInterruptOn !== undefined && Object.keys(resolvedInterruptOn).length > 0;
|
|
202
150
|
}
|
|
203
|
-
export function
|
|
151
|
+
export function shouldAttachDeepAgentStore(binding) {
|
|
204
152
|
return getBindingStoreConfig(binding) !== undefined || getBindingMemorySources(binding).length > 0;
|
|
205
153
|
}
|
|
206
|
-
export function
|
|
154
|
+
export function shouldAttachDeepAgentBackend(binding) {
|
|
207
155
|
return (getBindingBackendConfig(binding) !== undefined ||
|
|
208
156
|
getBindingMemorySources(binding).length > 0 ||
|
|
209
157
|
getBindingSkills(binding).length > 0 ||
|
|
@@ -26,6 +26,16 @@ function isTaskDelegationCompletionEvent(event) {
|
|
|
26
26
|
return ((eventName === "on_tool_end" && name === "task")
|
|
27
27
|
|| (eventName === "on_chain_end" && runType === "tool" && name === "task"));
|
|
28
28
|
}
|
|
29
|
+
function isTaskDelegationFailureEvent(event) {
|
|
30
|
+
const eventName = typeof event.event === "string" ? event.event : "";
|
|
31
|
+
const name = typeof event.name === "string" ? event.name : "";
|
|
32
|
+
const runType = typeof event.run_type === "string" ? event.run_type : "";
|
|
33
|
+
return ((eventName === "on_tool_error" && name === "task")
|
|
34
|
+
|| (eventName === "on_chain_error" && runType === "tool" && name === "task"));
|
|
35
|
+
}
|
|
36
|
+
function isTaskDelegationTerminalEvent(event) {
|
|
37
|
+
return isTaskDelegationCompletionEvent(event) || isTaskDelegationFailureEvent(event);
|
|
38
|
+
}
|
|
29
39
|
function readTracingConfig(binding) {
|
|
30
40
|
const deepAgentTracing = asObject(binding.harnessRuntime?.deepagent?.passthrough)?.tracing;
|
|
31
41
|
const langchainTracing = asObject(binding.harnessRuntime?.langchain?.passthrough)?.tracing;
|
|
@@ -152,9 +162,7 @@ function extractSubagentFromTaskToolEvent(event) {
|
|
|
152
162
|
const input = asObject(data?.input);
|
|
153
163
|
const subagentType = typeof input?.subagent_type === "string"
|
|
154
164
|
? input.subagent_type
|
|
155
|
-
:
|
|
156
|
-
? input.subagentType
|
|
157
|
-
: null;
|
|
165
|
+
: null;
|
|
158
166
|
return subagentType && subagentType.trim().length > 0 ? subagentType.trim() : null;
|
|
159
167
|
}
|
|
160
168
|
function extractKnownSubagentFromEvent(event, knownSubagentIds) {
|
|
@@ -175,6 +183,14 @@ export function consumeRunInspectionUpstreamEvent(input) {
|
|
|
175
183
|
}
|
|
176
184
|
const knownSubagentIds = new Set(getBindingSubagents(input.binding).map((subagent) => subagent.name));
|
|
177
185
|
const delegatedAgentId = extractSubagentFromTaskToolEvent(typed) ?? extractKnownSubagentFromEvent(typed, knownSubagentIds);
|
|
186
|
+
if (isTaskDelegationTerminalEvent(typed) && input.delegationChain.length > 1) {
|
|
187
|
+
const nextDelegationChain = input.delegationChain.slice(0, -1);
|
|
188
|
+
const nextAgentId = nextDelegationChain.at(-1) ?? input.currentAgentId;
|
|
189
|
+
return {
|
|
190
|
+
currentAgentId: nextAgentId,
|
|
191
|
+
delegationChain: nextDelegationChain,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
178
194
|
if (!delegatedAgentId) {
|
|
179
195
|
return {
|
|
180
196
|
currentAgentId: input.currentAgentId,
|
|
@@ -299,7 +315,7 @@ export function projectRuntimeSurfaceFromSingleUpstreamEvent(input) {
|
|
|
299
315
|
},
|
|
300
316
|
});
|
|
301
317
|
}
|
|
302
|
-
if (
|
|
318
|
+
if (isTaskDelegationTerminalEvent(typed) && previousDelegationChain.length > 1) {
|
|
303
319
|
const delegatedAgentId = previousDelegationChain.at(-1);
|
|
304
320
|
const ownerAgentId = previousDelegationChain.at(-2);
|
|
305
321
|
const delegatedAgentName = formatAgentName(delegatedAgentId);
|
|
@@ -308,7 +324,7 @@ export function projectRuntimeSurfaceFromSingleUpstreamEvent(input) {
|
|
|
308
324
|
id: buildSurfaceId("agent", delegatedAgentId),
|
|
309
325
|
name: delegatedAgentName,
|
|
310
326
|
action: "handoff",
|
|
311
|
-
status: "completed",
|
|
327
|
+
status: isTaskDelegationFailureEvent(typed) ? "failed" : "completed",
|
|
312
328
|
agentId: delegatedAgentId,
|
|
313
329
|
agentName: delegatedAgentName,
|
|
314
330
|
...(ownerAgentId ? { ownerAgentId, ownerAgentName: formatAgentName(ownerAgentId) } : {}),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { describeRuntimeError } from "../../support/harness-support.js";
|
|
1
2
|
import { isTerminalRequestState } from "./helpers.js";
|
|
2
3
|
async function finalizeIfCancellationRequested(input) {
|
|
3
4
|
const cancellation = await input.getRequestCancellation(input.requestId);
|
|
@@ -200,7 +201,7 @@ export async function executeQueuedRequestOperation(runtime, input) {
|
|
|
200
201
|
await runtime.emitSyntheticFallback(sessionId, requestId, agentId, error);
|
|
201
202
|
await runtime.setRequestStateAndEmit(sessionId, requestId, 104, "failed", {
|
|
202
203
|
previousState: continuationState,
|
|
203
|
-
error:
|
|
204
|
+
error: describeRuntimeError(error),
|
|
204
205
|
});
|
|
205
206
|
return {
|
|
206
207
|
sessionId: sessionId,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CompiledAgentBinding, HarnessEvent, MemoryRecord, MessageContent, RequestResult, RequestExecutionStep, RuntimeSnapshot, TranscriptMessage } from "../../../contracts/types.js";
|
|
1
|
+
import type { CompiledAgentBinding, HarnessEvent, MemoryRecord, MessageContent, RequestPlanState, RequestResult, RequestExecutionStep, RuntimeSnapshot, TranscriptMessage } from "../../../contracts/types.js";
|
|
2
2
|
import { type InternalHarnessStreamItem } from "../events/streaming.js";
|
|
3
3
|
type RuntimeStreamChunk = {
|
|
4
4
|
kind: "commentary";
|
|
@@ -65,6 +65,8 @@ type StreamRunOptions = {
|
|
|
65
65
|
runtimeSnapshot?: RuntimeSnapshot | null;
|
|
66
66
|
}) => Promise<void>;
|
|
67
67
|
appendRequestTraceItem: (sessionId: string, requestId: string, item: unknown) => Promise<void>;
|
|
68
|
+
loadRequestPlanState?: (sessionId: string, requestId: string) => Promise<RequestPlanState | null>;
|
|
69
|
+
saveRequestPlanState?: (sessionId: string, requestId: string, planState: RequestPlanState) => Promise<void>;
|
|
68
70
|
emitSyntheticFallback: (sessionId: string, requestId: string, selectedAgentId: string, error: unknown) => Promise<void>;
|
|
69
71
|
};
|
|
70
72
|
export declare function streamHarnessRun(options: StreamRunOptions): AsyncGenerator<InternalHarnessStreamItem>;
|