@botbotgo/agent-harness 0.0.111 → 0.0.113
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/README.md +0 -2
- package/README.zh.md +0 -2
- package/dist/config/agents/direct.yaml +58 -59
- package/dist/config/agents/orchestra.yaml +68 -70
- package/dist/contracts/core.d.ts +0 -2
- package/dist/contracts/runtime.d.ts +0 -17
- package/dist/contracts/workspace.d.ts +2 -11
- package/dist/init-project.js +10 -8
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -1
- package/dist/persistence/file-store.d.ts +1 -5
- package/dist/persistence/file-store.js +1 -34
- package/dist/runtime/adapter/compat/deepagent-compat.d.ts +6 -0
- package/dist/runtime/adapter/compat/deepagent-compat.js +3 -0
- package/dist/runtime/adapter/{execution-context.d.ts → flow/execution-context.d.ts} +17 -3
- package/dist/runtime/adapter/{execution-context.js → flow/execution-context.js} +20 -2
- package/dist/runtime/adapter/flow/invocation-flow.d.ts +24 -0
- package/dist/runtime/adapter/flow/invocation-flow.js +42 -0
- package/dist/runtime/adapter/{invoke-runtime.d.ts → flow/invoke-runtime.d.ts} +3 -3
- package/dist/runtime/adapter/{invoke-runtime.js → flow/invoke-runtime.js} +1 -1
- package/dist/runtime/adapter/flow/runnable-assembly.d.ts +51 -0
- package/dist/runtime/adapter/flow/runnable-assembly.js +52 -0
- package/dist/runtime/adapter/{stream-runtime.d.ts → flow/stream-runtime.d.ts} +3 -3
- package/dist/runtime/adapter/{stream-runtime.js → flow/stream-runtime.js} +6 -6
- package/dist/runtime/adapter/middleware-assembly.d.ts +12 -1
- package/dist/runtime/adapter/middleware-assembly.js +72 -54
- package/dist/runtime/adapter/runnable-config.d.ts +0 -3
- package/dist/runtime/adapter/runnable-config.js +0 -3
- package/dist/runtime/adapter/runtime-adapter-support.d.ts +0 -7
- package/dist/runtime/adapter/runtime-adapter-support.js +1 -20
- package/dist/runtime/adapter/runtime-shell.js +1 -1
- package/dist/runtime/adapter/tool/builtin-middleware-tools.js +10 -9
- package/dist/runtime/adapter/tool-resolution.d.ts +1 -1
- package/dist/runtime/agent-runtime-adapter.d.ts +1 -1
- package/dist/runtime/agent-runtime-adapter.js +52 -81
- package/dist/runtime/harness/system/inventory.d.ts +2 -2
- package/dist/runtime/harness/system/inventory.js +5 -6
- package/dist/runtime/parsing/stream-event-parsing.js +2 -2
- package/dist/runtime/support/compiled-binding.d.ts +1 -2
- package/dist/runtime/support/compiled-binding.js +0 -3
- package/dist/workspace/agent-binding-compiler.js +7 -32
- package/dist/workspace/object-loader.js +94 -23
- package/dist/workspace/support/workspace-ref-utils.d.ts +1 -2
- package/dist/workspace/support/workspace-ref-utils.js +0 -12
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { buildExecutableToolMap } from "
|
|
2
|
-
import { getBindingLangChainParams, getBindingPrimaryModel, getBindingPrimaryTools, isLangChainBinding } from "
|
|
1
|
+
import { buildExecutableToolMap } from "../tool-resolution.js";
|
|
2
|
+
import { getBindingLangChainParams, getBindingPrimaryModel, getBindingPrimaryTools, isLangChainBinding } from "../../support/compiled-binding.js";
|
|
3
3
|
export function buildBindingToolCatalog(input) {
|
|
4
4
|
const primaryTools = getBindingPrimaryTools(input.binding);
|
|
5
5
|
const toolNameMapping = input.getToolNameMapping(input.binding);
|
|
@@ -50,3 +50,21 @@ export async function resolveLangChainStreamContext(input) {
|
|
|
50
50
|
langChainStreamModel,
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
+
export async function resolveRuntimeStreamExecutionContext(input) {
|
|
54
|
+
const { primaryTools, toolNameMapping } = buildBindingToolCatalog({
|
|
55
|
+
binding: input.binding,
|
|
56
|
+
getToolNameMapping: input.getToolNameMapping,
|
|
57
|
+
});
|
|
58
|
+
const { forceInvokeFallback, canUseDirectModelStream, langChainStreamModel, } = await resolveLangChainStreamContext({
|
|
59
|
+
binding: input.binding,
|
|
60
|
+
resolveModel: input.resolveModel,
|
|
61
|
+
resolveTools: input.resolveTools,
|
|
62
|
+
});
|
|
63
|
+
return {
|
|
64
|
+
primaryTools,
|
|
65
|
+
toolNameMapping,
|
|
66
|
+
forceInvokeFallback,
|
|
67
|
+
canUseDirectModelStream,
|
|
68
|
+
langChainStreamModel,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CompiledAgentBinding, CompiledTool, MessageContent, RunResult, TranscriptMessage } from "../../../contracts/types.js";
|
|
2
|
+
import { type ExecutableTool } from "./invoke-runtime.js";
|
|
3
|
+
import type { ToolNameMapping } from "../tool/tool-name-mapping.js";
|
|
4
|
+
export declare function executeRuntimeInvocation(options: {
|
|
5
|
+
binding: CompiledAgentBinding;
|
|
6
|
+
input: MessageContent;
|
|
7
|
+
threadId: string;
|
|
8
|
+
runId: string;
|
|
9
|
+
resumePayload?: unknown;
|
|
10
|
+
history?: TranscriptMessage[];
|
|
11
|
+
invokeOptions?: {
|
|
12
|
+
context?: Record<string, unknown>;
|
|
13
|
+
state?: Record<string, unknown>;
|
|
14
|
+
files?: Record<string, unknown>;
|
|
15
|
+
};
|
|
16
|
+
resolveTools: (tools: CompiledTool[], binding?: CompiledAgentBinding) => unknown[];
|
|
17
|
+
getToolNameMapping: (binding: CompiledAgentBinding) => ToolNameMapping;
|
|
18
|
+
resolveBuiltinMiddlewareTools: (binding: CompiledAgentBinding, options?: {
|
|
19
|
+
context?: Record<string, unknown>;
|
|
20
|
+
state?: Record<string, unknown>;
|
|
21
|
+
files?: Record<string, unknown>;
|
|
22
|
+
}) => Promise<Map<string, ExecutableTool>>;
|
|
23
|
+
callRuntimeWithToolParseRecovery: (request: unknown) => Promise<Record<string, unknown>>;
|
|
24
|
+
}): Promise<RunResult>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Command } from "@langchain/langgraph";
|
|
2
|
+
import { buildBindingToolExecutionContext } from "./execution-context.js";
|
|
3
|
+
import { finalizeInvocationResult } from "../invocation-result.js";
|
|
4
|
+
import { invokeRuntimeWithLocalTools } from "./invoke-runtime.js";
|
|
5
|
+
import { buildInvocationRequest } from "../model/invocation-request.js";
|
|
6
|
+
export async function executeRuntimeInvocation(options) {
|
|
7
|
+
const history = options.history ?? [];
|
|
8
|
+
const invokeOptions = options.invokeOptions ?? {};
|
|
9
|
+
const request = options.resumePayload === undefined
|
|
10
|
+
? buildInvocationRequest(options.binding, history, options.input, invokeOptions)
|
|
11
|
+
: new Command({ resume: options.resumePayload });
|
|
12
|
+
const { primaryTools, toolNameMapping, executableTools, defersToUpstreamHitlExecution, } = buildBindingToolExecutionContext({
|
|
13
|
+
binding: options.binding,
|
|
14
|
+
resolveTools: options.resolveTools,
|
|
15
|
+
getToolNameMapping: options.getToolNameMapping,
|
|
16
|
+
context: invokeOptions.context,
|
|
17
|
+
});
|
|
18
|
+
const builtinExecutableTools = await options.resolveBuiltinMiddlewareTools(options.binding, invokeOptions);
|
|
19
|
+
const localOrUpstreamInvocation = await invokeRuntimeWithLocalTools({
|
|
20
|
+
binding: options.binding,
|
|
21
|
+
request,
|
|
22
|
+
resumePayload: options.resumePayload,
|
|
23
|
+
primaryTools,
|
|
24
|
+
defersToUpstreamHitlExecution,
|
|
25
|
+
toolNameMapping,
|
|
26
|
+
executableTools,
|
|
27
|
+
builtinExecutableTools: builtinExecutableTools,
|
|
28
|
+
callRuntimeWithToolParseRecovery: options.callRuntimeWithToolParseRecovery,
|
|
29
|
+
});
|
|
30
|
+
const result = localOrUpstreamInvocation.result;
|
|
31
|
+
const executedToolResults = [...localOrUpstreamInvocation.executedToolResults];
|
|
32
|
+
if (!result) {
|
|
33
|
+
throw new Error("Agent invocation returned no result");
|
|
34
|
+
}
|
|
35
|
+
return finalizeInvocationResult({
|
|
36
|
+
bindingAgentId: options.binding.agent.id,
|
|
37
|
+
threadId: options.threadId,
|
|
38
|
+
runId: options.runId,
|
|
39
|
+
result,
|
|
40
|
+
executedToolResults,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { CompiledAgentBinding, CompiledTool } from "
|
|
2
|
-
import type { ExecutedToolResult } from "
|
|
3
|
-
import type { ToolNameMapping } from "
|
|
1
|
+
import type { CompiledAgentBinding, CompiledTool } from "../../../contracts/types.js";
|
|
2
|
+
import type { ExecutedToolResult } from "../invocation-result.js";
|
|
3
|
+
import type { ToolNameMapping } from "../tool/tool-name-mapping.js";
|
|
4
4
|
export type ExecutableTool = {
|
|
5
5
|
name: string;
|
|
6
6
|
schema: unknown;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { runLocalToolInvocationLoop } from "
|
|
1
|
+
import { runLocalToolInvocationLoop } from "../local-tool-invocation.js";
|
|
2
2
|
export async function invokeRuntimeWithLocalTools(options) {
|
|
3
3
|
if (options.resumePayload !== undefined || options.defersToUpstreamHitlExecution) {
|
|
4
4
|
return {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { CompiledAgentBinding, CompiledModel, CompiledSubAgent, CompiledTool, DeepAgentParams, LangChainAgentParams, RuntimeAdapterOptions } from "../../../contracts/types.js";
|
|
2
|
+
export declare function resolveRunnableCheckpointer(options: RuntimeAdapterOptions, binding: CompiledAgentBinding): unknown;
|
|
3
|
+
export declare function resolveRunnableInterruptOn(binding: CompiledAgentBinding): Record<string, {
|
|
4
|
+
allowedDecisions: import("../tool/interrupt-policy.js").InterruptDecision[];
|
|
5
|
+
}> | undefined;
|
|
6
|
+
export declare function assembleLangChainRunnable(input: {
|
|
7
|
+
binding: CompiledAgentBinding;
|
|
8
|
+
runtimeAdapterOptions: RuntimeAdapterOptions;
|
|
9
|
+
passthroughOverride?: Record<string, unknown>;
|
|
10
|
+
systemPromptOverride?: string;
|
|
11
|
+
resolveModel: (model: CompiledModel) => Promise<unknown>;
|
|
12
|
+
resolveTools: (tools: CompiledTool[], binding?: CompiledAgentBinding) => unknown[];
|
|
13
|
+
resolveMiddleware: (binding: CompiledAgentBinding, interruptOn?: Record<string, {
|
|
14
|
+
allowedDecisions: Array<"approve" | "edit" | "reject">;
|
|
15
|
+
}>) => Promise<unknown[]>;
|
|
16
|
+
}): Promise<{
|
|
17
|
+
langchainParams: LangChainAgentParams;
|
|
18
|
+
interruptOn?: Record<string, {
|
|
19
|
+
allowedDecisions: Array<"approve" | "edit" | "reject">;
|
|
20
|
+
}>;
|
|
21
|
+
resolvedModel: unknown;
|
|
22
|
+
resolvedTools: unknown[];
|
|
23
|
+
resolvedMiddleware: unknown[];
|
|
24
|
+
resolvedCheckpointer: unknown;
|
|
25
|
+
resolvedStore: unknown;
|
|
26
|
+
passthroughOverride?: Record<string, unknown>;
|
|
27
|
+
systemPromptOverride?: string;
|
|
28
|
+
}>;
|
|
29
|
+
export declare function assembleDeepAgentRunnable(input: {
|
|
30
|
+
binding: CompiledAgentBinding;
|
|
31
|
+
runtimeAdapterOptions: RuntimeAdapterOptions;
|
|
32
|
+
resolveModel: (model: CompiledModel) => Promise<unknown>;
|
|
33
|
+
resolveTools: (tools: CompiledTool[], binding?: CompiledAgentBinding) => unknown[];
|
|
34
|
+
resolveMiddleware: (binding: CompiledAgentBinding, interruptOn?: Record<string, {
|
|
35
|
+
allowedDecisions: Array<"approve" | "edit" | "reject">;
|
|
36
|
+
}>) => Promise<unknown[]>;
|
|
37
|
+
resolveSubagents: (subagents: CompiledSubAgent[], binding?: CompiledAgentBinding) => Promise<CompiledSubAgent[]>;
|
|
38
|
+
}): Promise<{
|
|
39
|
+
compatibleParams: DeepAgentParams;
|
|
40
|
+
resolvedModel: unknown;
|
|
41
|
+
resolvedTools: unknown[];
|
|
42
|
+
resolvedMiddleware: unknown[];
|
|
43
|
+
resolvedSubagents: CompiledSubAgent[];
|
|
44
|
+
resolvedCheckpointer: unknown;
|
|
45
|
+
resolvedStore: unknown;
|
|
46
|
+
resolvedBackend: unknown;
|
|
47
|
+
resolvedInterruptOn?: Record<string, {
|
|
48
|
+
allowedDecisions: Array<"approve" | "edit" | "reject">;
|
|
49
|
+
}>;
|
|
50
|
+
resolvedSkills: string[];
|
|
51
|
+
}>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { MemorySaver } from "@langchain/langgraph";
|
|
2
|
+
import { applyDeepAgentDelegationPromptCompatibility, resolveDeepAgentSkillSourcePaths, } from "../compat/deepagent-compat.js";
|
|
3
|
+
import { compileInterruptOn } from "../tool/interrupt-policy.js";
|
|
4
|
+
import { getBindingDeepAgentParams, getBindingInterruptCompatibilityRules, getBindingLangChainParams, getBindingPrimaryTools, } from "../../support/compiled-binding.js";
|
|
5
|
+
export function resolveRunnableCheckpointer(options, binding) {
|
|
6
|
+
return options.checkpointerResolver ? options.checkpointerResolver(binding) : new MemorySaver();
|
|
7
|
+
}
|
|
8
|
+
export function resolveRunnableInterruptOn(binding) {
|
|
9
|
+
return compileInterruptOn(getBindingPrimaryTools(binding), getBindingInterruptCompatibilityRules(binding));
|
|
10
|
+
}
|
|
11
|
+
export async function assembleLangChainRunnable(input) {
|
|
12
|
+
const langchainParams = getBindingLangChainParams(input.binding);
|
|
13
|
+
if (!langchainParams) {
|
|
14
|
+
throw new Error(`Agent ${input.binding.agent.id} has no langchain params`);
|
|
15
|
+
}
|
|
16
|
+
const interruptOn = resolveRunnableInterruptOn(input.binding);
|
|
17
|
+
return {
|
|
18
|
+
langchainParams,
|
|
19
|
+
interruptOn,
|
|
20
|
+
resolvedModel: await input.resolveModel(langchainParams.model),
|
|
21
|
+
resolvedTools: input.resolveTools(langchainParams.tools, input.binding),
|
|
22
|
+
resolvedMiddleware: await input.resolveMiddleware(input.binding, interruptOn),
|
|
23
|
+
resolvedCheckpointer: resolveRunnableCheckpointer(input.runtimeAdapterOptions, input.binding),
|
|
24
|
+
resolvedStore: input.runtimeAdapterOptions.storeResolver?.(input.binding),
|
|
25
|
+
passthroughOverride: input.passthroughOverride,
|
|
26
|
+
systemPromptOverride: input.systemPromptOverride,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export async function assembleDeepAgentRunnable(input) {
|
|
30
|
+
const deepAgentParams = getBindingDeepAgentParams(input.binding);
|
|
31
|
+
if (!deepAgentParams) {
|
|
32
|
+
throw new Error(`Agent ${input.binding.agent.id} has no runnable params`);
|
|
33
|
+
}
|
|
34
|
+
const compatibleParams = applyDeepAgentDelegationPromptCompatibility(deepAgentParams.model, deepAgentParams);
|
|
35
|
+
return {
|
|
36
|
+
compatibleParams,
|
|
37
|
+
resolvedModel: await input.resolveModel(compatibleParams.model),
|
|
38
|
+
resolvedTools: input.resolveTools(compatibleParams.tools, input.binding),
|
|
39
|
+
resolvedMiddleware: await input.resolveMiddleware(input.binding),
|
|
40
|
+
resolvedSubagents: await input.resolveSubagents(compatibleParams.subagents, input.binding),
|
|
41
|
+
resolvedCheckpointer: resolveRunnableCheckpointer(input.runtimeAdapterOptions, input.binding),
|
|
42
|
+
resolvedStore: input.runtimeAdapterOptions.storeResolver?.(input.binding),
|
|
43
|
+
resolvedBackend: input.runtimeAdapterOptions.backendResolver?.(input.binding),
|
|
44
|
+
resolvedInterruptOn: resolveRunnableInterruptOn(input.binding),
|
|
45
|
+
resolvedSkills: resolveDeepAgentSkillSourcePaths({
|
|
46
|
+
workspaceRoot: input.binding.harnessRuntime.workspaceRoot,
|
|
47
|
+
runRoot: input.binding.harnessRuntime.runRoot,
|
|
48
|
+
ownerId: input.binding.agent.id,
|
|
49
|
+
skillPaths: compatibleParams.skills,
|
|
50
|
+
}) ?? [],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { CompiledAgentBinding, CompiledTool, MessageContent, TranscriptMessage } from "
|
|
2
|
-
import type { RuntimeStreamChunk } from "
|
|
3
|
-
import type { ToolNameMapping } from "
|
|
1
|
+
import type { CompiledAgentBinding, CompiledTool, MessageContent, TranscriptMessage } from "../../../contracts/types.js";
|
|
2
|
+
import type { RuntimeStreamChunk } from "../../parsing/stream-event-parsing.js";
|
|
3
|
+
import type { ToolNameMapping } from "../tool/tool-name-mapping.js";
|
|
4
4
|
type RunnableLike = {
|
|
5
5
|
stream?: (input: unknown, config?: Record<string, unknown>) => Promise<AsyncIterable<unknown>>;
|
|
6
6
|
streamEvents?: (input: unknown, config?: Record<string, unknown>) => Promise<AsyncIterable<unknown>>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { isToolCallParseFailure, sanitizeVisibleText, } from "
|
|
2
|
-
import { buildInvocationRequest } from "
|
|
3
|
-
import { buildRawModelMessages } from "
|
|
4
|
-
import { projectRuntimeStreamEvent, createStreamEventProjectionState } from "
|
|
5
|
-
import { projectTextStreamChunks } from "
|
|
6
|
-
import { computeRemainingTimeoutMs } from "
|
|
1
|
+
import { isToolCallParseFailure, sanitizeVisibleText, } from "../../parsing/output-parsing.js";
|
|
2
|
+
import { buildInvocationRequest } from "../model/invocation-request.js";
|
|
3
|
+
import { buildRawModelMessages } from "../model/message-assembly.js";
|
|
4
|
+
import { projectRuntimeStreamEvent, createStreamEventProjectionState } from "../stream-event-projection.js";
|
|
5
|
+
import { projectTextStreamChunks } from "../stream-text-consumption.js";
|
|
6
|
+
import { computeRemainingTimeoutMs } from "../resilience.js";
|
|
7
7
|
export async function* streamRuntimeExecution(options) {
|
|
8
8
|
const request = buildInvocationRequest(options.binding, options.history, options.input, options.runtimeOptions);
|
|
9
9
|
try {
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { FilesystemBackend } from "deepagents";
|
|
2
2
|
import type { CompiledAgentBinding, CompiledModel, CompiledSubAgent, DeepAgentParams, RuntimeAdapterOptions } from "../../contracts/types.js";
|
|
3
|
-
import type { ExecutableTool } from "./invoke-runtime.js";
|
|
3
|
+
import type { ExecutableTool } from "./flow/invoke-runtime.js";
|
|
4
|
+
export declare function buildBuiltinTaskSubagentRunnableConfig(input: {
|
|
5
|
+
selectedSubagent: CompiledSubAgent;
|
|
6
|
+
defaultModel: unknown;
|
|
7
|
+
defaultTools: unknown[];
|
|
8
|
+
middleware: unknown[];
|
|
9
|
+
}): Record<string, unknown>;
|
|
10
|
+
export declare function buildBuiltinTaskSubagentMiddleware(input: {
|
|
11
|
+
selectedSubagent: CompiledSubAgent;
|
|
12
|
+
builtinBackend: unknown;
|
|
13
|
+
summarizationModel: unknown;
|
|
14
|
+
}): unknown[];
|
|
4
15
|
export declare function resolveBuiltinMiddlewareBackend(input: {
|
|
5
16
|
binding: CompiledAgentBinding;
|
|
6
17
|
runtimeAdapterOptions: RuntimeAdapterOptions;
|
|
@@ -4,10 +4,47 @@ import { createAgent, humanInTheLoopMiddleware } from "langchain";
|
|
|
4
4
|
import { createBuiltinMiddlewareTools } from "./tool/builtin-middleware-tools.js";
|
|
5
5
|
import { compileInterruptOn } from "./tool/interrupt-policy.js";
|
|
6
6
|
import { extractToolFallbackContext, extractVisibleOutput } from "../parsing/output-parsing.js";
|
|
7
|
-
import {
|
|
7
|
+
import { isRecord } from "../../utils/object.js";
|
|
8
8
|
import { resolveDeclaredMiddleware } from "./tool/declared-middleware.js";
|
|
9
|
-
import { getBindingDeepAgentParams, getBindingInterruptCompatibilityRules, getBindingLangChainParams, getBindingMiddlewareConfigs, getBindingPrimaryModel, isDeepAgentBinding, isLangChainBinding, } from "../support/compiled-binding.js";
|
|
9
|
+
import { bindingHasLangChainSubagentSupport, bindingHasMiddlewareKind, getBindingDeepAgentParams, getBindingInterruptCompatibilityRules, getBindingLangChainParams, getBindingMiddlewareConfigs, getBindingPrimaryModel, isDeepAgentBinding, isLangChainBinding, } from "../support/compiled-binding.js";
|
|
10
10
|
import { applyDeepAgentDelegationPromptCompatibility, materializeDeepAgentSkillSourcePaths } from "./compat/deepagent-compat.js";
|
|
11
|
+
export function buildBuiltinTaskSubagentRunnableConfig(input) {
|
|
12
|
+
const { selectedSubagent, defaultModel, defaultTools, middleware } = input;
|
|
13
|
+
return {
|
|
14
|
+
model: (selectedSubagent.model ?? defaultModel),
|
|
15
|
+
tools: (selectedSubagent.tools ?? defaultTools),
|
|
16
|
+
systemPrompt: selectedSubagent.systemPrompt ?? DEFAULT_SUBAGENT_PROMPT,
|
|
17
|
+
middleware: middleware,
|
|
18
|
+
responseFormat: selectedSubagent.responseFormat,
|
|
19
|
+
name: selectedSubagent.name,
|
|
20
|
+
description: selectedSubagent.description,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function buildBuiltinTaskSubagentMiddleware(input) {
|
|
24
|
+
const { selectedSubagent, builtinBackend, summarizationModel } = input;
|
|
25
|
+
const defaultSubagentMiddleware = [
|
|
26
|
+
createPatchToolCallsMiddleware(),
|
|
27
|
+
createSummarizationMiddleware({
|
|
28
|
+
model: summarizationModel,
|
|
29
|
+
backend: builtinBackend,
|
|
30
|
+
}),
|
|
31
|
+
];
|
|
32
|
+
const subagentSkillsMiddleware = selectedSubagent.skills?.length
|
|
33
|
+
? [createSkillsMiddleware({ backend: builtinBackend, sources: selectedSubagent.skills })]
|
|
34
|
+
: [];
|
|
35
|
+
const subagentMiddleware = selectedSubagent.middleware ?? [];
|
|
36
|
+
const interruptMiddleware = selectedSubagent.interruptOn
|
|
37
|
+
? [humanInTheLoopMiddleware({
|
|
38
|
+
interruptOn: compileInterruptOn(selectedSubagent.tools ?? [], selectedSubagent.interruptOn),
|
|
39
|
+
})]
|
|
40
|
+
: [];
|
|
41
|
+
return [
|
|
42
|
+
...defaultSubagentMiddleware,
|
|
43
|
+
...subagentSkillsMiddleware,
|
|
44
|
+
...subagentMiddleware,
|
|
45
|
+
...interruptMiddleware,
|
|
46
|
+
];
|
|
47
|
+
}
|
|
11
48
|
function buildLangChainContextMiddleware(params) {
|
|
12
49
|
const middleware = [];
|
|
13
50
|
const hasSkills = (params.compatibleParams.skills?.length ?? 0) > 0;
|
|
@@ -51,22 +88,26 @@ export function resolveBuiltinMiddlewareBackend(input) {
|
|
|
51
88
|
return new StateBackend(runtimeLike);
|
|
52
89
|
}
|
|
53
90
|
export async function resolveSubagents(input) {
|
|
54
|
-
return Promise.all(input.subagents.map(async (subagent) =>
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
91
|
+
return Promise.all(input.subagents.map(async (subagent) => {
|
|
92
|
+
// Only pass DeepAgents-supported subagent fields through to upstream middleware.
|
|
93
|
+
// Harness-only extensions stay internal instead of becoming a second subagent dialect.
|
|
94
|
+
return {
|
|
95
|
+
name: subagent.name,
|
|
96
|
+
description: subagent.description,
|
|
97
|
+
systemPrompt: subagent.systemPrompt,
|
|
98
|
+
model: subagent.model ? (await input.resolveModel(subagent.model)) : undefined,
|
|
99
|
+
tools: subagent.tools ? input.resolveTools(subagent.tools, input.binding) : undefined,
|
|
100
|
+
skills: await materializeDeepAgentSkillSourcePaths({
|
|
101
|
+
workspaceRoot: input.binding?.harnessRuntime.workspaceRoot,
|
|
102
|
+
runRoot: input.binding?.harnessRuntime.runRoot,
|
|
103
|
+
ownerId: `${input.binding?.agent.id ?? "agent"}-${subagent.name}`,
|
|
104
|
+
skillPaths: subagent.skills,
|
|
105
|
+
}),
|
|
106
|
+
interruptOn: compileInterruptOn(subagent.tools ?? [], subagent.interruptOn),
|
|
107
|
+
responseFormat: subagent.responseFormat,
|
|
108
|
+
middleware: (await resolveDeclaredMiddleware(subagent.middleware, input.createDeclaredMiddlewareResolverOptions(input.binding))),
|
|
109
|
+
};
|
|
110
|
+
}));
|
|
70
111
|
}
|
|
71
112
|
export async function invokeBuiltinTaskTool(input) {
|
|
72
113
|
if (!isDeepAgentBinding(input.binding)) {
|
|
@@ -83,46 +124,23 @@ export async function invokeBuiltinTaskTool(input) {
|
|
|
83
124
|
const resolvedSubagents = await input.resolveSubagents(params.subagents, input.binding);
|
|
84
125
|
const selectedSubagent = resolvedSubagents.find((subagent) => subagent.name === subagentType);
|
|
85
126
|
if (!selectedSubagent) {
|
|
86
|
-
const allowed =
|
|
87
|
-
...resolvedSubagents.map((subagent) => subagent.name),
|
|
88
|
-
...(params.generalPurposeAgent ? ["general-purpose"] : []),
|
|
89
|
-
];
|
|
127
|
+
const allowed = resolvedSubagents.map((subagent) => subagent.name);
|
|
90
128
|
throw new Error(`Error: invoked agent of type ${subagentType}, the only allowed types are ${allowed.map((name) => `\`${name}\``).join(", ")}`);
|
|
91
129
|
}
|
|
92
130
|
const summarizationModel = selectedSubagent.model
|
|
93
131
|
? await input.resolveModel(selectedSubagent.model)
|
|
94
132
|
: await input.resolveModel(params.model);
|
|
95
|
-
const middleware =
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
...(selectedSubagent.memory?.length
|
|
100
|
-
? [createMemoryMiddleware({ backend: builtinBackend, sources: selectedSubagent.memory })]
|
|
101
|
-
: []),
|
|
102
|
-
...(selectedSubagent.middleware ??
|
|
103
|
-
[
|
|
104
|
-
createPatchToolCallsMiddleware(),
|
|
105
|
-
createSummarizationMiddleware({
|
|
106
|
-
model: summarizationModel,
|
|
107
|
-
backend: builtinBackend,
|
|
108
|
-
}),
|
|
109
|
-
]),
|
|
110
|
-
...(selectedSubagent.interruptOn
|
|
111
|
-
? [humanInTheLoopMiddleware({
|
|
112
|
-
interruptOn: compileInterruptOn(selectedSubagent.tools ?? [], selectedSubagent.interruptOn),
|
|
113
|
-
})]
|
|
114
|
-
: []),
|
|
115
|
-
];
|
|
116
|
-
const runnable = createAgent({
|
|
117
|
-
model: (selectedSubagent.model ?? (await input.resolveModel(params.model))),
|
|
118
|
-
tools: (selectedSubagent.tools ?? input.resolveTools(params.tools, input.binding)),
|
|
119
|
-
systemPrompt: selectedSubagent.systemPrompt ?? DEFAULT_SUBAGENT_PROMPT,
|
|
120
|
-
middleware: middleware,
|
|
121
|
-
responseFormat: selectedSubagent.responseFormat,
|
|
122
|
-
contextSchema: selectedSubagent.contextSchema,
|
|
123
|
-
name: selectedSubagent.name,
|
|
124
|
-
description: selectedSubagent.description,
|
|
133
|
+
const middleware = buildBuiltinTaskSubagentMiddleware({
|
|
134
|
+
selectedSubagent,
|
|
135
|
+
builtinBackend,
|
|
136
|
+
summarizationModel,
|
|
125
137
|
});
|
|
138
|
+
const runnable = createAgent(buildBuiltinTaskSubagentRunnableConfig({
|
|
139
|
+
selectedSubagent,
|
|
140
|
+
defaultModel: await input.resolveModel(params.model),
|
|
141
|
+
defaultTools: input.resolveTools(params.tools, input.binding),
|
|
142
|
+
middleware,
|
|
143
|
+
}));
|
|
126
144
|
const result = await runnable.invoke({ messages: [new HumanMessage({ content: description })] }, { configurable: { thread_id: `${input.binding.agent.id}:builtin-task` }, ...(input.options?.context ? { context: input.options.context } : {}) });
|
|
127
145
|
const visibleOutput = extractVisibleOutput(result);
|
|
128
146
|
const fallbackOutput = extractToolFallbackContext(result);
|
|
@@ -138,7 +156,7 @@ export async function resolveBuiltinMiddlewareTools(input) {
|
|
|
138
156
|
});
|
|
139
157
|
}
|
|
140
158
|
export async function resolveAutomaticSummarizationMiddleware(input) {
|
|
141
|
-
if (
|
|
159
|
+
if (bindingHasMiddlewareKind(input.binding, "summarization")) {
|
|
142
160
|
return [];
|
|
143
161
|
}
|
|
144
162
|
const primaryModel = getBindingPrimaryModel(input.binding);
|
|
@@ -161,7 +179,7 @@ export async function resolveLangChainAutomaticMiddleware(input) {
|
|
|
161
179
|
compatibleParams,
|
|
162
180
|
resolveFilesystemBackend: input.resolveFilesystemBackend,
|
|
163
181
|
}));
|
|
164
|
-
if (
|
|
182
|
+
if (bindingHasLangChainSubagentSupport(input.binding)) {
|
|
165
183
|
automaticMiddleware.push(createSubAgentMiddleware({
|
|
166
184
|
defaultModel: (await input.resolveModel(compatibleParams.model)),
|
|
167
185
|
defaultTools: input.resolveTools(compatibleParams.tools, input.binding),
|
|
@@ -27,14 +27,11 @@ type LangChainRunnableConfigParams = {
|
|
|
27
27
|
};
|
|
28
28
|
type DeepAgentRunnableConfigParams = {
|
|
29
29
|
compatibleParams: {
|
|
30
|
-
passthrough?: Record<string, unknown>;
|
|
31
30
|
systemPrompt?: string;
|
|
32
31
|
responseFormat?: unknown;
|
|
33
32
|
contextSchema?: unknown;
|
|
34
33
|
name?: unknown;
|
|
35
34
|
memory?: unknown;
|
|
36
|
-
generalPurposeAgent?: unknown;
|
|
37
|
-
taskDescription?: unknown;
|
|
38
35
|
};
|
|
39
36
|
resolvedModel: unknown;
|
|
40
37
|
resolvedTools: unknown[];
|
|
@@ -37,7 +37,6 @@ export function buildLangChainRunnableConfig(params) {
|
|
|
37
37
|
export function buildDeepAgentRunnableConfig(params) {
|
|
38
38
|
const { compatibleParams, resolvedModel, resolvedTools, resolvedMiddleware, resolvedSubagents, resolvedCheckpointer, resolvedStore, resolvedBackend, resolvedInterruptOn, resolvedSkills, } = params;
|
|
39
39
|
return buildResolvedRunnableConfig({
|
|
40
|
-
passthrough: compatibleParams.passthrough ?? {},
|
|
41
40
|
staticConfig: {
|
|
42
41
|
systemPrompt: compatibleParams.systemPrompt,
|
|
43
42
|
responseFormat: compatibleParams.responseFormat,
|
|
@@ -45,8 +44,6 @@ export function buildDeepAgentRunnableConfig(params) {
|
|
|
45
44
|
name: compatibleParams.name,
|
|
46
45
|
memory: compatibleParams.memory,
|
|
47
46
|
skills: resolvedSkills,
|
|
48
|
-
generalPurposeAgent: compatibleParams.generalPurposeAgent,
|
|
49
|
-
taskDescription: compatibleParams.taskDescription,
|
|
50
47
|
},
|
|
51
48
|
resolved: {
|
|
52
49
|
resolvedModel,
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import type { CompiledAgentBinding } from "../../contracts/types.js";
|
|
2
|
-
export declare function countConfiguredTools(binding: CompiledAgentBinding): number;
|
|
3
|
-
export declare function sleep(ms: number): Promise<void>;
|
|
4
|
-
export declare function hasConfiguredSubagentSupport(binding: CompiledAgentBinding): boolean;
|
|
5
|
-
export declare function hasConfiguredMiddlewareKind(binding: CompiledAgentBinding, kind: string): boolean;
|
|
6
|
-
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
7
|
-
export declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
8
1
|
export declare function truncateLines(lines: string[], maxChars?: number): string;
|
|
9
2
|
export declare function summarizeBuiltinWriteTodosArgs(args: Record<string, unknown>): {
|
|
10
3
|
total: number;
|
|
@@ -1,23 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isRecord as isRecordValue } from "../../utils/object.js";
|
|
3
|
-
export function countConfiguredTools(binding) {
|
|
4
|
-
return getBindingToolCount(binding);
|
|
5
|
-
}
|
|
6
|
-
export function sleep(ms) {
|
|
7
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
8
|
-
}
|
|
9
|
-
export function hasConfiguredSubagentSupport(binding) {
|
|
10
|
-
return bindingHasLangChainSubagentSupport(binding);
|
|
11
|
-
}
|
|
12
|
-
export function hasConfiguredMiddlewareKind(binding, kind) {
|
|
13
|
-
return bindingHasMiddlewareKind(binding, kind);
|
|
14
|
-
}
|
|
15
|
-
export function isRecord(value) {
|
|
16
|
-
return isRecordValue(value);
|
|
17
|
-
}
|
|
18
|
-
export function isObject(value) {
|
|
19
|
-
return isRecord(value);
|
|
20
|
-
}
|
|
1
|
+
import { isRecord } from "../../utils/object.js";
|
|
21
2
|
export function truncateLines(lines, maxChars = 12_000) {
|
|
22
3
|
const joined = lines.join("\n");
|
|
23
4
|
if (joined.length <= maxChars) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
1
2
|
import { extractVisibleOutput, isToolCallParseFailure, STRICT_TOOL_JSON_INSTRUCTION } from "../parsing/output-parsing.js";
|
|
2
3
|
import { readStreamDelta } from "../parsing/stream-event-parsing.js";
|
|
3
4
|
import { computeRemainingTimeoutMs, isRetryableProviderError, resolveProviderRetryPolicy } from "./resilience.js";
|
|
4
|
-
import { sleep } from "./runtime-adapter-support.js";
|
|
5
5
|
import { getBindingDeepAgentParams, getBindingLangChainParams, isDeepAgentBinding, isLangChainBinding, } from "../support/compiled-binding.js";
|
|
6
6
|
export class RuntimeOperationTimeoutError extends Error {
|
|
7
7
|
operation;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { isSandboxBackend } from "deepagents";
|
|
3
|
-
import {
|
|
3
|
+
import { isRecord } from "../../../utils/object.js";
|
|
4
|
+
import { summarizeBuiltinWriteTodosArgs, truncateLines } from "../runtime-adapter-support.js";
|
|
4
5
|
export async function createBuiltinMiddlewareTools(backend, options) {
|
|
5
6
|
const tools = new Map();
|
|
6
7
|
tools.set("write_todos", {
|
|
@@ -9,7 +10,7 @@ export async function createBuiltinMiddlewareTools(backend, options) {
|
|
|
9
10
|
todos: z.array(z.object({}).passthrough()).optional(),
|
|
10
11
|
}).passthrough(),
|
|
11
12
|
invoke: async (input) => {
|
|
12
|
-
const args =
|
|
13
|
+
const args = isRecord(input) ? input : {};
|
|
13
14
|
const summary = summarizeBuiltinWriteTodosArgs(args);
|
|
14
15
|
return {
|
|
15
16
|
ok: true,
|
|
@@ -23,7 +24,7 @@ export async function createBuiltinMiddlewareTools(backend, options) {
|
|
|
23
24
|
name: "ls",
|
|
24
25
|
schema: z.object({ path: z.string().optional().default("/") }).passthrough(),
|
|
25
26
|
invoke: async (input) => {
|
|
26
|
-
const targetPath =
|
|
27
|
+
const targetPath = isRecord(input) && typeof input.path === "string" ? input.path : "/";
|
|
27
28
|
const infos = (await Promise.resolve(backend.lsInfo?.(targetPath))) ?? [];
|
|
28
29
|
if (infos.length === 0) {
|
|
29
30
|
return `No files found in ${targetPath}`;
|
|
@@ -39,7 +40,7 @@ export async function createBuiltinMiddlewareTools(backend, options) {
|
|
|
39
40
|
limit: z.number().optional(),
|
|
40
41
|
}).passthrough(),
|
|
41
42
|
invoke: async (input) => {
|
|
42
|
-
const typed =
|
|
43
|
+
const typed = isRecord(input) ? input : {};
|
|
43
44
|
const filePath = typeof typed.file_path === "string" ? typed.file_path : "";
|
|
44
45
|
const offset = typeof typed.offset === "number" ? typed.offset : 0;
|
|
45
46
|
const limit = typeof typed.limit === "number" ? typed.limit : 500;
|
|
@@ -50,7 +51,7 @@ export async function createBuiltinMiddlewareTools(backend, options) {
|
|
|
50
51
|
name: "write_file",
|
|
51
52
|
schema: z.object({ file_path: z.string(), content: z.string().optional() }).passthrough(),
|
|
52
53
|
invoke: async (input) => {
|
|
53
|
-
const typed =
|
|
54
|
+
const typed = isRecord(input) ? input : {};
|
|
54
55
|
const result = await Promise.resolve(backend.write?.(typeof typed.file_path === "string" ? typed.file_path : "", typeof typed.content === "string" ? typed.content : ""));
|
|
55
56
|
return result?.error ?? `Successfully wrote to '${result?.path ?? (typed.file_path ?? "")}'`;
|
|
56
57
|
},
|
|
@@ -64,7 +65,7 @@ export async function createBuiltinMiddlewareTools(backend, options) {
|
|
|
64
65
|
replace_all: z.boolean().optional(),
|
|
65
66
|
}).passthrough(),
|
|
66
67
|
invoke: async (input) => {
|
|
67
|
-
const typed =
|
|
68
|
+
const typed = isRecord(input) ? input : {};
|
|
68
69
|
const result = await Promise.resolve(backend.edit?.(typeof typed.file_path === "string" ? typed.file_path : "", typeof typed.old_string === "string" ? typed.old_string : "", typeof typed.new_string === "string" ? typed.new_string : "", typed.replace_all === true));
|
|
69
70
|
return result?.error ?? `Successfully replaced ${result?.occurrences ?? 0} occurrence(s) in '${result?.path ?? (typed.file_path ?? "")}'`;
|
|
70
71
|
},
|
|
@@ -73,7 +74,7 @@ export async function createBuiltinMiddlewareTools(backend, options) {
|
|
|
73
74
|
name: "glob",
|
|
74
75
|
schema: z.object({ pattern: z.string(), path: z.string().optional().default("/") }).passthrough(),
|
|
75
76
|
invoke: async (input) => {
|
|
76
|
-
const typed =
|
|
77
|
+
const typed = isRecord(input) ? input : {};
|
|
77
78
|
const pattern = typeof typed.pattern === "string" ? typed.pattern : "";
|
|
78
79
|
const targetPath = typeof typed.path === "string" ? typed.path : "/";
|
|
79
80
|
const infos = (await Promise.resolve(backend.globInfo?.(pattern, targetPath))) ?? [];
|
|
@@ -91,7 +92,7 @@ export async function createBuiltinMiddlewareTools(backend, options) {
|
|
|
91
92
|
glob: z.string().nullable().optional(),
|
|
92
93
|
}).passthrough(),
|
|
93
94
|
invoke: async (input) => {
|
|
94
|
-
const typed =
|
|
95
|
+
const typed = isRecord(input) ? input : {};
|
|
95
96
|
const result = await Promise.resolve(backend.grepRaw?.(typeof typed.pattern === "string" ? typed.pattern : "", typeof typed.path === "string" ? typed.path : "/", typeof typed.glob === "string" ? typed.glob : null));
|
|
96
97
|
if (typeof result === "string") {
|
|
97
98
|
return result;
|
|
@@ -118,7 +119,7 @@ export async function createBuiltinMiddlewareTools(backend, options) {
|
|
|
118
119
|
if (!isSandboxBackend(backend) || typeof backend.execute !== "function") {
|
|
119
120
|
return "Error: Execution not available. This agent's backend does not support command execution (SandboxBackendProtocol).";
|
|
120
121
|
}
|
|
121
|
-
const typed =
|
|
122
|
+
const typed = isRecord(input) ? input : {};
|
|
122
123
|
const result = await Promise.resolve(backend.execute(typeof typed.command === "string" ? typed.command : ""));
|
|
123
124
|
const parts = [result.output];
|
|
124
125
|
if (result.exitCode !== null) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CompiledAgentBinding, CompiledTool } from "../../contracts/types.js";
|
|
2
2
|
import { type ToolNameMapping } from "./tool/tool-name-mapping.js";
|
|
3
|
-
import type { ExecutableTool } from "./invoke-runtime.js";
|
|
3
|
+
import type { ExecutableTool } from "./flow/invoke-runtime.js";
|
|
4
4
|
export declare function resolveAdapterTools(input: {
|
|
5
5
|
tools: Array<CompiledTool>;
|
|
6
6
|
binding?: CompiledAgentBinding;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CompiledAgentBinding, MessageContent, RunResult, RuntimeAdapterOptions, TranscriptMessage } from "../contracts/types.js";
|
|
2
2
|
import { type RuntimeStreamChunk } from "./parsing/stream-event-parsing.js";
|
|
3
3
|
import { RuntimeOperationTimeoutError } from "./adapter/runtime-shell.js";
|
|
4
|
-
export { applyDeepAgentDelegationPromptCompatibility, materializeDeepAgentSkillSourcePaths, relativizeDeepAgentSkillSourcePaths, shouldRelaxDeepAgentDelegationPrompt, } from "./adapter/compat/deepagent-compat.js";
|
|
4
|
+
export { applyDeepAgentDelegationPromptCompatibility, materializeDeepAgentSkillSourcePaths, resolveDeepAgentSkillSourcePaths, relativizeDeepAgentSkillSourcePaths, shouldRelaxDeepAgentDelegationPrompt, } from "./adapter/compat/deepagent-compat.js";
|
|
5
5
|
export { buildAuthOmittingFetch, normalizeOpenAICompatibleInit } from "./adapter/compat/openai-compatible.js";
|
|
6
6
|
export { buildToolNameMapping, createModelFacingToolNameCandidates, createModelFacingToolNameLookupCandidates, resolveModelFacingToolName, sanitizeToolNameForModel, } from "./adapter/tool/tool-name-mapping.js";
|
|
7
7
|
export { computeRemainingTimeoutMs, isRetryableProviderError, resolveBindingTimeout, resolveProviderRetryPolicy, resolveStreamIdleTimeout, resolveTimeoutMs, } from "./adapter/resilience.js";
|