@botbotgo/agent-harness 0.0.107 → 0.0.108
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/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -1
- package/dist/runtime/adapter/deepagent-runnable-config.d.ts +1 -18
- package/dist/runtime/adapter/deepagent-runnable-config.js +26 -19
- package/dist/runtime/adapter/execution-context.d.ts +27 -0
- package/dist/runtime/adapter/execution-context.js +45 -0
- package/dist/runtime/adapter/langchain-runnable-config.d.ts +1 -15
- package/dist/runtime/adapter/langchain-runnable-config.js +21 -16
- package/dist/runtime/adapter/middleware-assembly.js +27 -12
- package/dist/runtime/adapter/runnable-config.d.ts +13 -0
- package/dist/runtime/adapter/runnable-config.js +13 -0
- package/dist/runtime/adapter/runtime-adapter-support.js +4 -4
- package/dist/runtime/agent-runtime-adapter.js +28 -32
- package/dist/runtime/harness/background-runtime.d.ts +13 -0
- package/dist/runtime/harness/background-runtime.js +8 -0
- package/dist/runtime/harness/bindings.d.ts +14 -0
- package/dist/runtime/harness/bindings.js +23 -0
- package/dist/runtime/harness.d.ts +1 -3
- package/dist/runtime/harness.js +30 -68
- package/dist/runtime/support/compiled-binding.d.ts +14 -0
- package/dist/runtime/support/compiled-binding.js +14 -10
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AGENT_HARNESS_VERSION = "0.0.
|
|
1
|
+
export declare const AGENT_HARNESS_VERSION = "0.0.107";
|
package/dist/package-version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const AGENT_HARNESS_VERSION = "0.0.
|
|
1
|
+
export const AGENT_HARNESS_VERSION = "0.0.107";
|
|
@@ -10,21 +10,4 @@ export declare function buildDeepAgentRunnableConfig(params: {
|
|
|
10
10
|
resolvedBackend: unknown;
|
|
11
11
|
resolvedInterruptOn: unknown;
|
|
12
12
|
resolvedSkills: string[];
|
|
13
|
-
}):
|
|
14
|
-
model: never;
|
|
15
|
-
tools: never;
|
|
16
|
-
systemPrompt: string | undefined;
|
|
17
|
-
responseFormat: never;
|
|
18
|
-
contextSchema: never;
|
|
19
|
-
middleware: never;
|
|
20
|
-
subagents: never;
|
|
21
|
-
checkpointer: never;
|
|
22
|
-
store: never;
|
|
23
|
-
backend: never;
|
|
24
|
-
interruptOn: never;
|
|
25
|
-
name: string;
|
|
26
|
-
memory: string[];
|
|
27
|
-
skills: string[];
|
|
28
|
-
generalPurposeAgent: boolean | undefined;
|
|
29
|
-
taskDescription: string | undefined;
|
|
30
|
-
};
|
|
13
|
+
}): Record<string, unknown>;
|
|
@@ -1,22 +1,29 @@
|
|
|
1
|
+
import { buildResolvedRunnableConfig } from "./runnable-config.js";
|
|
1
2
|
export function buildDeepAgentRunnableConfig(params) {
|
|
2
3
|
const { compatibleParams, resolvedModel, resolvedTools, resolvedMiddleware, resolvedSubagents, resolvedCheckpointer, resolvedStore, resolvedBackend, resolvedInterruptOn, resolvedSkills, } = params;
|
|
3
|
-
return {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
4
|
+
return buildResolvedRunnableConfig({
|
|
5
|
+
passthrough: compatibleParams.passthrough ?? {},
|
|
6
|
+
staticConfig: {
|
|
7
|
+
systemPrompt: compatibleParams.systemPrompt,
|
|
8
|
+
responseFormat: compatibleParams.responseFormat,
|
|
9
|
+
contextSchema: compatibleParams.contextSchema,
|
|
10
|
+
name: compatibleParams.name,
|
|
11
|
+
memory: compatibleParams.memory,
|
|
12
|
+
skills: resolvedSkills,
|
|
13
|
+
generalPurposeAgent: compatibleParams.generalPurposeAgent,
|
|
14
|
+
taskDescription: compatibleParams.taskDescription,
|
|
15
|
+
},
|
|
16
|
+
resolved: {
|
|
17
|
+
resolvedModel: resolvedModel,
|
|
18
|
+
resolvedTools: resolvedTools,
|
|
19
|
+
resolvedMiddleware: resolvedMiddleware,
|
|
20
|
+
resolvedCheckpointer: resolvedCheckpointer,
|
|
21
|
+
resolvedStore: resolvedStore,
|
|
22
|
+
},
|
|
23
|
+
extraConfig: {
|
|
24
|
+
subagents: resolvedSubagents,
|
|
25
|
+
backend: resolvedBackend,
|
|
26
|
+
interruptOn: resolvedInterruptOn,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
22
29
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CompiledAgentBinding, CompiledTool } from "../../contracts/types.js";
|
|
2
|
+
import type { ToolNameMapping } from "./tool/tool-name-mapping.js";
|
|
3
|
+
import { getBindingPrimaryModel } from "../support/compiled-binding.js";
|
|
4
|
+
export declare function buildBindingToolExecutionContext(input: {
|
|
5
|
+
binding: CompiledAgentBinding;
|
|
6
|
+
resolveTools: (tools: CompiledTool[], binding?: CompiledAgentBinding) => unknown[];
|
|
7
|
+
getToolNameMapping: (binding: CompiledAgentBinding) => ToolNameMapping;
|
|
8
|
+
context?: Record<string, unknown>;
|
|
9
|
+
}): {
|
|
10
|
+
primaryTools: CompiledTool[];
|
|
11
|
+
resolvedTools: unknown[];
|
|
12
|
+
toolNameMapping: ToolNameMapping;
|
|
13
|
+
executableTools: Map<string, import("./invoke-runtime.js").ExecutableTool>;
|
|
14
|
+
defersToUpstreamHitlExecution: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare function resolveLangChainStreamContext(input: {
|
|
17
|
+
binding: CompiledAgentBinding;
|
|
18
|
+
resolveModel: (model: NonNullable<ReturnType<typeof getBindingPrimaryModel>>) => Promise<unknown>;
|
|
19
|
+
resolveTools: (tools: CompiledTool[], binding?: CompiledAgentBinding) => unknown[];
|
|
20
|
+
}): Promise<{
|
|
21
|
+
primaryTools: CompiledTool[];
|
|
22
|
+
forceInvokeFallback: boolean;
|
|
23
|
+
canUseDirectModelStream: boolean;
|
|
24
|
+
langChainStreamModel: {
|
|
25
|
+
stream?: (input: unknown) => Promise<AsyncIterable<unknown>>;
|
|
26
|
+
} | undefined;
|
|
27
|
+
}>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { buildExecutableToolMap } from "./tool-resolution.js";
|
|
2
|
+
import { getBindingLangChainParams, getBindingPrimaryModel, getBindingPrimaryTools, isLangChainBinding } from "../support/compiled-binding.js";
|
|
3
|
+
export function buildBindingToolExecutionContext(input) {
|
|
4
|
+
const primaryTools = getBindingPrimaryTools(input.binding);
|
|
5
|
+
const resolvedTools = input.resolveTools(primaryTools, input.binding);
|
|
6
|
+
const toolNameMapping = input.getToolNameMapping(input.binding);
|
|
7
|
+
const executableTools = buildExecutableToolMap({
|
|
8
|
+
primaryTools,
|
|
9
|
+
resolvedTools,
|
|
10
|
+
toolNameMapping,
|
|
11
|
+
context: input.context,
|
|
12
|
+
});
|
|
13
|
+
return {
|
|
14
|
+
primaryTools,
|
|
15
|
+
resolvedTools,
|
|
16
|
+
toolNameMapping,
|
|
17
|
+
executableTools,
|
|
18
|
+
defersToUpstreamHitlExecution: primaryTools.some((tool) => tool.hitl?.enabled === true),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export async function resolveLangChainStreamContext(input) {
|
|
22
|
+
const primaryTools = getBindingPrimaryTools(input.binding);
|
|
23
|
+
const primaryModel = getBindingPrimaryModel(input.binding);
|
|
24
|
+
const forceInvokeFallback = isLangChainBinding(input.binding) &&
|
|
25
|
+
primaryTools.length > 0 &&
|
|
26
|
+
primaryModel?.provider === "openai-compatible";
|
|
27
|
+
const langchainParams = isLangChainBinding(input.binding) ? getBindingLangChainParams(input.binding) : undefined;
|
|
28
|
+
const resolvedLangChainModel = langchainParams
|
|
29
|
+
? (await input.resolveModel(langchainParams.model))
|
|
30
|
+
: undefined;
|
|
31
|
+
const resolvedLangChainTools = langchainParams ? input.resolveTools(langchainParams.tools, input.binding) : [];
|
|
32
|
+
const canUseDirectModelStream = !!resolvedLangChainModel &&
|
|
33
|
+
(resolvedLangChainTools.length === 0 || typeof resolvedLangChainModel.bindTools !== "function");
|
|
34
|
+
const langChainStreamModel = resolvedLangChainModel && canUseDirectModelStream
|
|
35
|
+
? resolvedLangChainModel
|
|
36
|
+
: resolvedLangChainModel && typeof resolvedLangChainModel.bindTools === "function" && resolvedLangChainTools.length > 0
|
|
37
|
+
? resolvedLangChainModel.bindTools(resolvedLangChainTools)
|
|
38
|
+
: undefined;
|
|
39
|
+
return {
|
|
40
|
+
primaryTools,
|
|
41
|
+
forceInvokeFallback,
|
|
42
|
+
canUseDirectModelStream,
|
|
43
|
+
langChainStreamModel,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -8,18 +8,4 @@ export declare function buildLangChainRunnableConfig(params: {
|
|
|
8
8
|
resolvedStore: unknown;
|
|
9
9
|
passthroughOverride?: Record<string, unknown>;
|
|
10
10
|
systemPromptOverride?: string;
|
|
11
|
-
}):
|
|
12
|
-
model: never;
|
|
13
|
-
tools: never;
|
|
14
|
-
systemPrompt: string | undefined;
|
|
15
|
-
stateSchema: never;
|
|
16
|
-
responseFormat: never;
|
|
17
|
-
contextSchema: never;
|
|
18
|
-
middleware: never;
|
|
19
|
-
checkpointer: never;
|
|
20
|
-
store: never;
|
|
21
|
-
includeAgentName: "inline" | undefined;
|
|
22
|
-
version: "v1" | "v2" | undefined;
|
|
23
|
-
name: string | undefined;
|
|
24
|
-
description: string;
|
|
25
|
-
};
|
|
11
|
+
}): Record<string, unknown>;
|
|
@@ -1,19 +1,24 @@
|
|
|
1
|
+
import { buildResolvedRunnableConfig } from "./runnable-config.js";
|
|
1
2
|
export function buildLangChainRunnableConfig(params) {
|
|
2
3
|
const { langchainParams, resolvedModel, resolvedTools, resolvedMiddleware, resolvedCheckpointer, resolvedStore, passthroughOverride, systemPromptOverride, } = params;
|
|
3
|
-
return {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
4
|
+
return buildResolvedRunnableConfig({
|
|
5
|
+
passthrough: (passthroughOverride ?? langchainParams.passthrough ?? {}),
|
|
6
|
+
staticConfig: {
|
|
7
|
+
systemPrompt: systemPromptOverride ?? langchainParams.systemPrompt,
|
|
8
|
+
stateSchema: langchainParams.stateSchema,
|
|
9
|
+
responseFormat: langchainParams.responseFormat,
|
|
10
|
+
contextSchema: langchainParams.contextSchema,
|
|
11
|
+
includeAgentName: langchainParams.includeAgentName,
|
|
12
|
+
version: langchainParams.version,
|
|
13
|
+
name: langchainParams.name,
|
|
14
|
+
description: langchainParams.description,
|
|
15
|
+
},
|
|
16
|
+
resolved: {
|
|
17
|
+
resolvedModel: resolvedModel,
|
|
18
|
+
resolvedTools: resolvedTools,
|
|
19
|
+
resolvedMiddleware: resolvedMiddleware,
|
|
20
|
+
resolvedCheckpointer: resolvedCheckpointer,
|
|
21
|
+
resolvedStore: resolvedStore,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
19
24
|
}
|
|
@@ -8,6 +8,28 @@ import { hasConfiguredMiddlewareKind, hasConfiguredSubagentSupport, isObject, is
|
|
|
8
8
|
import { resolveDeclaredMiddleware } from "./tool/declared-middleware.js";
|
|
9
9
|
import { getBindingDeepAgentParams, getBindingInterruptCompatibilityRules, getBindingLangChainParams, getBindingMiddlewareConfigs, getBindingPrimaryModel, isDeepAgentBinding, isLangChainBinding, } from "../support/compiled-binding.js";
|
|
10
10
|
import { applyDeepAgentDelegationPromptCompatibility, materializeDeepAgentSkillSourcePaths } from "./compat/deepagent-compat.js";
|
|
11
|
+
function buildLangChainContextMiddleware(params) {
|
|
12
|
+
const middleware = [];
|
|
13
|
+
const hasSkills = (params.compatibleParams.skills?.length ?? 0) > 0;
|
|
14
|
+
const hasMemory = (params.compatibleParams.memory?.length ?? 0) > 0;
|
|
15
|
+
if (!hasSkills && !hasMemory) {
|
|
16
|
+
return middleware;
|
|
17
|
+
}
|
|
18
|
+
const backend = params.resolveFilesystemBackend(params.binding);
|
|
19
|
+
if (hasSkills) {
|
|
20
|
+
middleware.push(createSkillsMiddleware({
|
|
21
|
+
backend,
|
|
22
|
+
sources: params.compatibleParams.skills,
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
if (hasMemory) {
|
|
26
|
+
middleware.push(createMemoryMiddleware({
|
|
27
|
+
backend,
|
|
28
|
+
sources: params.compatibleParams.memory,
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
return middleware;
|
|
32
|
+
}
|
|
11
33
|
export function resolveBuiltinMiddlewareBackend(input) {
|
|
12
34
|
const runtimeState = {
|
|
13
35
|
...(input.options?.state ?? {}),
|
|
@@ -134,18 +156,11 @@ export async function resolveLangChainAutomaticMiddleware(input) {
|
|
|
134
156
|
const automaticMiddleware = [];
|
|
135
157
|
automaticMiddleware.push(createPatchToolCallsMiddleware());
|
|
136
158
|
automaticMiddleware.push(...(await input.resolveAutomaticSummarizationMiddleware(input.binding)));
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
if ((compatibleParams.memory?.length ?? 0) > 0) {
|
|
144
|
-
automaticMiddleware.push(createMemoryMiddleware({
|
|
145
|
-
backend: input.resolveFilesystemBackend(input.binding),
|
|
146
|
-
sources: compatibleParams.memory,
|
|
147
|
-
}));
|
|
148
|
-
}
|
|
159
|
+
automaticMiddleware.push(...buildLangChainContextMiddleware({
|
|
160
|
+
binding: input.binding,
|
|
161
|
+
compatibleParams,
|
|
162
|
+
resolveFilesystemBackend: input.resolveFilesystemBackend,
|
|
163
|
+
}));
|
|
149
164
|
if (hasConfiguredSubagentSupport(input.binding)) {
|
|
150
165
|
automaticMiddleware.push(createSubAgentMiddleware({
|
|
151
166
|
defaultModel: (await input.resolveModel(compatibleParams.model)),
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type ResolvedRunnableDependencies = {
|
|
2
|
+
resolvedModel: unknown;
|
|
3
|
+
resolvedTools: unknown[];
|
|
4
|
+
resolvedMiddleware: unknown[];
|
|
5
|
+
resolvedCheckpointer: unknown;
|
|
6
|
+
resolvedStore: unknown;
|
|
7
|
+
};
|
|
8
|
+
export declare function buildResolvedRunnableConfig(params: {
|
|
9
|
+
passthrough?: Record<string, unknown>;
|
|
10
|
+
staticConfig?: Record<string, unknown>;
|
|
11
|
+
resolved: ResolvedRunnableDependencies;
|
|
12
|
+
extraConfig?: Record<string, unknown>;
|
|
13
|
+
}): Record<string, unknown>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function buildResolvedRunnableConfig(params) {
|
|
2
|
+
const { passthrough, staticConfig, resolved, extraConfig } = params;
|
|
3
|
+
return {
|
|
4
|
+
...(passthrough ?? {}),
|
|
5
|
+
...(staticConfig ?? {}),
|
|
6
|
+
model: resolved.resolvedModel,
|
|
7
|
+
tools: resolved.resolvedTools,
|
|
8
|
+
middleware: resolved.resolvedMiddleware,
|
|
9
|
+
checkpointer: resolved.resolvedCheckpointer,
|
|
10
|
+
store: resolved.resolvedStore,
|
|
11
|
+
...(extraConfig ?? {}),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getBindingExecutionView } from "../support/compiled-binding.js";
|
|
2
2
|
export function countConfiguredTools(binding) {
|
|
3
|
-
return
|
|
3
|
+
return getBindingExecutionView(binding).primaryTools.length;
|
|
4
4
|
}
|
|
5
5
|
export function asObject(value) {
|
|
6
6
|
return typeof value === "object" && value ? value : undefined;
|
|
@@ -9,14 +9,14 @@ export function sleep(ms) {
|
|
|
9
9
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
10
10
|
}
|
|
11
11
|
export function hasConfiguredSubagentSupport(binding) {
|
|
12
|
-
const params =
|
|
12
|
+
const params = getBindingExecutionView(binding).langchainParams;
|
|
13
13
|
if (!params) {
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
16
|
return (params.subagents?.length ?? 0) > 0 || params.generalPurposeAgent === true || Boolean(params.taskDescription?.trim());
|
|
17
17
|
}
|
|
18
18
|
export function hasConfiguredMiddlewareKind(binding, kind) {
|
|
19
|
-
return
|
|
19
|
+
return getBindingExecutionView(binding).middlewareConfigs?.some((entry) => entry.kind === kind) ?? false;
|
|
20
20
|
}
|
|
21
21
|
export function isRecord(value) {
|
|
22
22
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -17,12 +17,13 @@ import { createResolvedModel } from "./adapter/model/model-providers.js";
|
|
|
17
17
|
import { buildInvocationRequest, } from "./adapter/model/invocation-request.js";
|
|
18
18
|
import { compileInterruptOn } from "./adapter/tool/interrupt-policy.js";
|
|
19
19
|
import { countConfiguredTools, } from "./adapter/runtime-adapter-support.js";
|
|
20
|
-
import {
|
|
20
|
+
import { resolveAdapterTools } from "./adapter/tool-resolution.js";
|
|
21
|
+
import { buildBindingToolExecutionContext, resolveLangChainStreamContext } from "./adapter/execution-context.js";
|
|
21
22
|
export { applyDeepAgentDelegationPromptCompatibility, materializeDeepAgentSkillSourcePaths, relativizeDeepAgentSkillSourcePaths, shouldRelaxDeepAgentDelegationPrompt, } from "./adapter/compat/deepagent-compat.js";
|
|
22
23
|
export { buildAuthOmittingFetch, normalizeOpenAICompatibleInit } from "./adapter/compat/openai-compatible.js";
|
|
23
24
|
export { buildToolNameMapping, createModelFacingToolNameCandidates, createModelFacingToolNameLookupCandidates, resolveModelFacingToolName, sanitizeToolNameForModel, } from "./adapter/tool/tool-name-mapping.js";
|
|
24
25
|
export { computeRemainingTimeoutMs, isRetryableProviderError, resolveBindingTimeout, resolveProviderRetryPolicy, resolveStreamIdleTimeout, resolveTimeoutMs, } from "./adapter/resilience.js";
|
|
25
|
-
import { getBindingAdapterKind, getBindingDeepAgentParams, getBindingInterruptCompatibilityRules, getBindingLangChainParams,
|
|
26
|
+
import { getBindingAdapterKind, getBindingDeepAgentParams, getBindingInterruptCompatibilityRules, getBindingLangChainParams, getBindingPrimaryTools, getBindingSystemPrompt, isDeepAgentBinding, isLangChainBinding, } from "./support/compiled-binding.js";
|
|
26
27
|
const AGENT_INTERRUPT_SENTINEL_PREFIX = "__agent_harness_interrupt__:";
|
|
27
28
|
const UPSTREAM_BUILTIN_MIDDLEWARE_TOOL_NAMES = Object.freeze([
|
|
28
29
|
"write_todos",
|
|
@@ -35,6 +36,12 @@ const UPSTREAM_BUILTIN_MIDDLEWARE_TOOL_NAMES = Object.freeze([
|
|
|
35
36
|
"execute",
|
|
36
37
|
"task",
|
|
37
38
|
]);
|
|
39
|
+
function resolveBindingCheckpointer(options, binding) {
|
|
40
|
+
return options.checkpointerResolver ? options.checkpointerResolver(binding) : new MemorySaver();
|
|
41
|
+
}
|
|
42
|
+
function resolveBindingInterruptOn(binding) {
|
|
43
|
+
return compileInterruptOn(getBindingPrimaryTools(binding), getBindingInterruptCompatibilityRules(binding));
|
|
44
|
+
}
|
|
38
45
|
export class AgentRuntimeAdapter {
|
|
39
46
|
options;
|
|
40
47
|
modelCache = new Map();
|
|
@@ -198,7 +205,7 @@ export class AgentRuntimeAdapter {
|
|
|
198
205
|
}
|
|
199
206
|
async createLangChainRunnable(binding, options = {}) {
|
|
200
207
|
const params = getBindingLangChainParams(binding);
|
|
201
|
-
const interruptOn =
|
|
208
|
+
const interruptOn = resolveBindingInterruptOn(binding);
|
|
202
209
|
const model = (await this.resolveModel(params.model));
|
|
203
210
|
const tools = this.resolveTools(params.tools, binding);
|
|
204
211
|
if (tools.length > 0 && typeof model.bindTools !== "function") {
|
|
@@ -209,7 +216,7 @@ export class AgentRuntimeAdapter {
|
|
|
209
216
|
resolvedModel: model,
|
|
210
217
|
resolvedTools: tools,
|
|
211
218
|
resolvedMiddleware: await this.resolveMiddleware(binding, interruptOn),
|
|
212
|
-
resolvedCheckpointer: this.options
|
|
219
|
+
resolvedCheckpointer: resolveBindingCheckpointer(this.options, binding),
|
|
213
220
|
resolvedStore: this.options.storeResolver?.(binding),
|
|
214
221
|
passthroughOverride: options.passthroughOverride,
|
|
215
222
|
systemPromptOverride: options.systemPromptOverride,
|
|
@@ -236,10 +243,10 @@ export class AgentRuntimeAdapter {
|
|
|
236
243
|
resolvedTools: this.resolveTools(compatibleParams.tools, binding),
|
|
237
244
|
resolvedMiddleware: await this.resolveMiddleware(binding),
|
|
238
245
|
resolvedSubagents: await this.resolveSubagents(compatibleParams.subagents, binding),
|
|
239
|
-
resolvedCheckpointer: this.options
|
|
246
|
+
resolvedCheckpointer: resolveBindingCheckpointer(this.options, binding),
|
|
240
247
|
resolvedStore: this.options.storeResolver?.(binding),
|
|
241
248
|
resolvedBackend: this.options.backendResolver?.(binding),
|
|
242
|
-
resolvedInterruptOn:
|
|
249
|
+
resolvedInterruptOn: resolveBindingInterruptOn(binding),
|
|
243
250
|
resolvedSkills: (await materializeDeepAgentSkillSourcePaths({
|
|
244
251
|
workspaceRoot: binding.harnessRuntime.workspaceRoot,
|
|
245
252
|
runRoot: binding.harnessRuntime.runRoot,
|
|
@@ -282,13 +289,10 @@ export class AgentRuntimeAdapter {
|
|
|
282
289
|
callRuntime,
|
|
283
290
|
});
|
|
284
291
|
};
|
|
285
|
-
const primaryTools =
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
primaryTools,
|
|
290
|
-
resolvedTools,
|
|
291
|
-
toolNameMapping,
|
|
292
|
+
const { primaryTools, toolNameMapping, executableTools, defersToUpstreamHitlExecution, } = buildBindingToolExecutionContext({
|
|
293
|
+
binding,
|
|
294
|
+
resolveTools: (tools, currentBinding) => this.resolveTools(tools, currentBinding),
|
|
295
|
+
getToolNameMapping: (currentBinding) => this.getToolNameMapping(currentBinding),
|
|
292
296
|
context: options.context,
|
|
293
297
|
});
|
|
294
298
|
const builtinExecutableTools = await this.resolveBuiltinMiddlewareTools(binding, options);
|
|
@@ -297,7 +301,7 @@ export class AgentRuntimeAdapter {
|
|
|
297
301
|
request,
|
|
298
302
|
resumePayload,
|
|
299
303
|
primaryTools,
|
|
300
|
-
defersToUpstreamHitlExecution
|
|
304
|
+
defersToUpstreamHitlExecution,
|
|
301
305
|
toolNameMapping,
|
|
302
306
|
executableTools,
|
|
303
307
|
builtinExecutableTools: builtinExecutableTools,
|
|
@@ -320,24 +324,16 @@ export class AgentRuntimeAdapter {
|
|
|
320
324
|
const invokeTimeoutMs = resolveBindingTimeout(binding);
|
|
321
325
|
const streamIdleTimeoutMs = resolveStreamIdleTimeout(binding);
|
|
322
326
|
const streamDeadlineAt = invokeTimeoutMs ? Date.now() + invokeTimeoutMs : undefined;
|
|
323
|
-
const primaryTools =
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const resolvedLangChainTools = langchainParams ? this.resolveTools(langchainParams.tools, binding) : [];
|
|
334
|
-
const canUseDirectModelStream = !!resolvedLangChainModel &&
|
|
335
|
-
(resolvedLangChainTools.length === 0 || typeof resolvedLangChainModel.bindTools !== "function");
|
|
336
|
-
const langChainStreamModel = resolvedLangChainModel && canUseDirectModelStream
|
|
337
|
-
? resolvedLangChainModel
|
|
338
|
-
: resolvedLangChainModel && typeof resolvedLangChainModel.bindTools === "function" && resolvedLangChainTools.length > 0
|
|
339
|
-
? resolvedLangChainModel.bindTools(resolvedLangChainTools)
|
|
340
|
-
: undefined;
|
|
327
|
+
const { primaryTools, toolNameMapping } = buildBindingToolExecutionContext({
|
|
328
|
+
binding,
|
|
329
|
+
resolveTools: (tools, currentBinding) => this.resolveTools(tools, currentBinding),
|
|
330
|
+
getToolNameMapping: (currentBinding) => this.getToolNameMapping(currentBinding),
|
|
331
|
+
});
|
|
332
|
+
const { forceInvokeFallback, canUseDirectModelStream, langChainStreamModel, } = await resolveLangChainStreamContext({
|
|
333
|
+
binding,
|
|
334
|
+
resolveModel: (model) => this.resolveModel(model),
|
|
335
|
+
resolveTools: (tools, currentBinding) => this.resolveTools(tools, currentBinding),
|
|
336
|
+
});
|
|
341
337
|
yield* streamRuntimeExecution({
|
|
342
338
|
binding,
|
|
343
339
|
input,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HarnessEvent } from "../../contracts/types.js";
|
|
2
|
+
import type { RuntimePersistence } from "../../persistence/types.js";
|
|
3
|
+
export declare function createBackgroundEventRuntime(input: {
|
|
4
|
+
persistence: RuntimePersistence;
|
|
5
|
+
publishEvent: (event: HarnessEvent) => void;
|
|
6
|
+
trackBackgroundTask: (task: Promise<void>) => void;
|
|
7
|
+
backgroundEventTypes: ReadonlySet<HarnessEvent["eventType"]>;
|
|
8
|
+
}): {
|
|
9
|
+
persistence: RuntimePersistence;
|
|
10
|
+
publishEvent: (event: HarnessEvent) => void;
|
|
11
|
+
trackBackgroundTask: (task: Promise<void>) => void;
|
|
12
|
+
backgroundEventTypes: ReadonlySet<import("../../contracts/runtime.js").HarnessEventType>;
|
|
13
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CompiledTool, RuntimeAdapterOptions, WorkspaceBundle } from "../../contracts/types.js";
|
|
2
|
+
type Binding = WorkspaceBundle["bindings"] extends Map<any, infer T> ? T : never;
|
|
3
|
+
export declare function getWorkspaceBinding(workspace: WorkspaceBundle, agentId: string): Binding | undefined;
|
|
4
|
+
export declare function getRequiredWorkspaceBinding(workspace: WorkspaceBundle, agentId: string): Binding;
|
|
5
|
+
export declare function resolveWorkspaceAgentTools(input: {
|
|
6
|
+
workspace: WorkspaceBundle;
|
|
7
|
+
agentId: string;
|
|
8
|
+
toolResolver?: RuntimeAdapterOptions["toolResolver"];
|
|
9
|
+
}): Array<{
|
|
10
|
+
compiledTool: CompiledTool;
|
|
11
|
+
resolvedTool: unknown;
|
|
12
|
+
}>;
|
|
13
|
+
export declare function bindingSupportsRunningReplay(binding: Binding): boolean;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { getBindingPrimaryTools } from "../support/compiled-binding.js";
|
|
2
|
+
export function getWorkspaceBinding(workspace, agentId) {
|
|
3
|
+
return workspace.bindings.get(agentId);
|
|
4
|
+
}
|
|
5
|
+
export function getRequiredWorkspaceBinding(workspace, agentId) {
|
|
6
|
+
const binding = getWorkspaceBinding(workspace, agentId);
|
|
7
|
+
if (!binding) {
|
|
8
|
+
throw new Error(`Unknown agent ${agentId}`);
|
|
9
|
+
}
|
|
10
|
+
return binding;
|
|
11
|
+
}
|
|
12
|
+
export function resolveWorkspaceAgentTools(input) {
|
|
13
|
+
const binding = getRequiredWorkspaceBinding(input.workspace, input.agentId);
|
|
14
|
+
const compiledTools = getBindingPrimaryTools(binding);
|
|
15
|
+
const resolvedTools = input.toolResolver ? input.toolResolver(compiledTools.map((tool) => tool.id), binding) : [];
|
|
16
|
+
return compiledTools.map((compiledTool, index) => ({
|
|
17
|
+
compiledTool,
|
|
18
|
+
resolvedTool: resolvedTools[index],
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
export function bindingSupportsRunningReplay(binding) {
|
|
22
|
+
return getBindingPrimaryTools(binding).every((tool) => tool.retryable === true);
|
|
23
|
+
}
|
|
@@ -33,6 +33,7 @@ export declare class AgentHarnessRuntime {
|
|
|
33
33
|
private pendingRunInsertionOrder;
|
|
34
34
|
private readonly pendingRunSlots;
|
|
35
35
|
private runtimeEventSequence;
|
|
36
|
+
private readonly backgroundEventRuntime;
|
|
36
37
|
private defaultRunRoot;
|
|
37
38
|
private getDefaultHostAgentId;
|
|
38
39
|
private resolveSelectedAgentId;
|
|
@@ -43,8 +44,6 @@ export declare class AgentHarnessRuntime {
|
|
|
43
44
|
initialize(): Promise<void>;
|
|
44
45
|
subscribe(listener: (event: HarnessEvent) => void): () => void;
|
|
45
46
|
getHealth(): Promise<RuntimeHealthSnapshot>;
|
|
46
|
-
private resolveAgentTools;
|
|
47
|
-
private supportsRunningReplay;
|
|
48
47
|
listThreads(filter?: {
|
|
49
48
|
agentId?: string;
|
|
50
49
|
}): Promise<ThreadSummary[]>;
|
|
@@ -91,7 +90,6 @@ export declare class AgentHarnessRuntime {
|
|
|
91
90
|
private isDecisionRun;
|
|
92
91
|
private notifyListener;
|
|
93
92
|
private prepareRunStart;
|
|
94
|
-
private createStartupRecoveryContext;
|
|
95
93
|
private acquireRunSlot;
|
|
96
94
|
private dropPendingRunSlot;
|
|
97
95
|
private dispatchRunListeners;
|
package/dist/runtime/harness.js
CHANGED
|
@@ -4,6 +4,7 @@ import { createPersistentId } from "../utils/id.js";
|
|
|
4
4
|
import { AgentRuntimeAdapter } from "./agent-runtime-adapter.js";
|
|
5
5
|
import { createResourceBackendResolver, createResourceToolResolver } from "../resource/resource.js";
|
|
6
6
|
import { EventBus } from "./harness/events/event-bus.js";
|
|
7
|
+
import { createBackgroundEventRuntime } from "./harness/background-runtime.js";
|
|
7
8
|
import { PolicyEngine } from "./harness/system/policy-engine.js";
|
|
8
9
|
import { getConcurrencyConfig, getRecoveryConfig, getRoutingDefaultAgentId, getRoutingRules, matchRoutingRule, } from "../workspace/support/workspace-ref-utils.js";
|
|
9
10
|
import { createHarnessEvent, inferRoutingBindings, renderRuntimeFailure, } from "./support/harness-support.js";
|
|
@@ -22,7 +23,8 @@ import { dropPendingRunSlot, enqueuePendingRunSlot } from "./harness/run/run-que
|
|
|
22
23
|
import { getDefaultHostAgentId, resolveSelectedAgentId } from "./harness/run/routing.js";
|
|
23
24
|
import { resolveCheckpointer, resolveEmbeddingModel, resolveStore, resolveStoreFromConfig, resolveVectorStore, } from "./harness/run/resources.js";
|
|
24
25
|
import { createToolMcpServerFromTools, serveToolsOverStdioFromHarness } from "../mcp.js";
|
|
25
|
-
import { getBindingAdapterKind,
|
|
26
|
+
import { getBindingAdapterKind, getBindingStoreConfig } from "./support/compiled-binding.js";
|
|
27
|
+
import { getRequiredWorkspaceBinding, getWorkspaceBinding, resolveWorkspaceAgentTools, } from "./harness/bindings.js";
|
|
26
28
|
import { describeWorkspaceInventory, listAgentSkills as listWorkspaceAgentSkills, } from "./harness/system/inventory.js";
|
|
27
29
|
import { createDefaultHealthSnapshot, isInventoryEnabled, isThreadMemorySyncEnabled, } from "./harness/runtime-defaults.js";
|
|
28
30
|
import { initializeHarnessRuntime, isStaleRunningRun as isHarnessStaleRunningRun, } from "./harness/run/startup-runtime.js";
|
|
@@ -65,6 +67,7 @@ export class AgentHarnessRuntime {
|
|
|
65
67
|
pendingRunInsertionOrder = 0;
|
|
66
68
|
pendingRunSlots = [];
|
|
67
69
|
runtimeEventSequence = 0;
|
|
70
|
+
backgroundEventRuntime;
|
|
68
71
|
defaultRunRoot() {
|
|
69
72
|
return this.defaultRunRootValue;
|
|
70
73
|
}
|
|
@@ -112,6 +115,12 @@ export class AgentHarnessRuntime {
|
|
|
112
115
|
((binding) => createResourceBackendResolver(workspace)(binding)),
|
|
113
116
|
};
|
|
114
117
|
this.runtimeAdapter = new AgentRuntimeAdapter(this.resolvedRuntimeAdapterOptions);
|
|
118
|
+
this.backgroundEventRuntime = createBackgroundEventRuntime({
|
|
119
|
+
persistence: this.persistence,
|
|
120
|
+
publishEvent: (event) => this.eventBus.publish(event),
|
|
121
|
+
trackBackgroundTask: (task) => this.trackBackgroundTask(task),
|
|
122
|
+
backgroundEventTypes: AgentHarnessRuntime.BACKGROUND_EVENT_TYPES,
|
|
123
|
+
});
|
|
115
124
|
this.routingRules = getRoutingRules(workspace.refs);
|
|
116
125
|
this.routingDefaultAgentId = getRoutingDefaultAgentId(workspace.refs);
|
|
117
126
|
if (isThreadMemorySyncEnabled(workspace)) {
|
|
@@ -161,23 +170,6 @@ export class AgentHarnessRuntime {
|
|
|
161
170
|
}
|
|
162
171
|
return createDefaultHealthSnapshot(this.activeRunSlots, this.pendingRunSlots.length);
|
|
163
172
|
}
|
|
164
|
-
resolveAgentTools(agentId) {
|
|
165
|
-
const binding = this.workspace.bindings.get(agentId);
|
|
166
|
-
if (!binding) {
|
|
167
|
-
throw new Error(`Unknown agent ${agentId}`);
|
|
168
|
-
}
|
|
169
|
-
const compiledTools = getBindingPrimaryTools(binding);
|
|
170
|
-
const resolver = this.resolvedRuntimeAdapterOptions.toolResolver;
|
|
171
|
-
const resolvedTools = resolver ? resolver(compiledTools.map((tool) => tool.id), binding) : [];
|
|
172
|
-
return compiledTools.map((compiledTool, index) => ({
|
|
173
|
-
compiledTool,
|
|
174
|
-
resolvedTool: resolvedTools[index],
|
|
175
|
-
}));
|
|
176
|
-
}
|
|
177
|
-
supportsRunningReplay(binding) {
|
|
178
|
-
const tools = getBindingPrimaryTools(binding);
|
|
179
|
-
return tools.every((tool) => tool.retryable === true);
|
|
180
|
-
}
|
|
181
173
|
async listThreads(filter) {
|
|
182
174
|
return this.persistence.listSessions(filter);
|
|
183
175
|
}
|
|
@@ -244,7 +236,11 @@ export class AgentHarnessRuntime {
|
|
|
244
236
|
}, threadId);
|
|
245
237
|
}
|
|
246
238
|
async createToolMcpServer(options) {
|
|
247
|
-
const tools =
|
|
239
|
+
const tools = resolveWorkspaceAgentTools({
|
|
240
|
+
workspace: this.workspace,
|
|
241
|
+
agentId: options.agentId,
|
|
242
|
+
toolResolver: this.resolvedRuntimeAdapterOptions.toolResolver,
|
|
243
|
+
}).map(({ compiledTool, resolvedTool }) => ({
|
|
248
244
|
compiledTool,
|
|
249
245
|
resolvedTool,
|
|
250
246
|
sourceTool: this.workspace.tools.get(compiledTool.id),
|
|
@@ -252,7 +248,11 @@ export class AgentHarnessRuntime {
|
|
|
252
248
|
return createToolMcpServerFromTools(tools, options);
|
|
253
249
|
}
|
|
254
250
|
async serveToolsOverStdio(options) {
|
|
255
|
-
const tools =
|
|
251
|
+
const tools = resolveWorkspaceAgentTools({
|
|
252
|
+
workspace: this.workspace,
|
|
253
|
+
agentId: options.agentId,
|
|
254
|
+
toolResolver: this.resolvedRuntimeAdapterOptions.toolResolver,
|
|
255
|
+
}).map(({ compiledTool, resolvedTool }) => ({
|
|
256
256
|
compiledTool,
|
|
257
257
|
resolvedTool,
|
|
258
258
|
sourceTool: this.workspace.tools.get(compiledTool.id),
|
|
@@ -263,13 +263,13 @@ export class AgentHarnessRuntime {
|
|
|
263
263
|
const rawInput = extractMessageText(input);
|
|
264
264
|
const configuredRule = this.routingRules.find((rule) => matchRoutingRule(rawInput, rule, options));
|
|
265
265
|
if (configuredRule) {
|
|
266
|
-
const configuredBinding = this.workspace
|
|
266
|
+
const configuredBinding = getWorkspaceBinding(this.workspace, configuredRule.agentId);
|
|
267
267
|
if (configuredBinding) {
|
|
268
268
|
return configuredBinding.agent.id;
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
const defaultBinding = this.routingDefaultAgentId
|
|
272
|
-
? this.workspace
|
|
272
|
+
? getWorkspaceBinding(this.workspace, this.routingDefaultAgentId)
|
|
273
273
|
: undefined;
|
|
274
274
|
if (defaultBinding) {
|
|
275
275
|
return defaultBinding.agent.id;
|
|
@@ -432,10 +432,7 @@ export class AgentHarnessRuntime {
|
|
|
432
432
|
}
|
|
433
433
|
catch (error) {
|
|
434
434
|
await emitSyntheticFallbackEvent({
|
|
435
|
-
|
|
436
|
-
publishEvent: (event) => this.eventBus.publish(event),
|
|
437
|
-
trackBackgroundTask: (task) => this.trackBackgroundTask(task),
|
|
438
|
-
backgroundEventTypes: AgentHarnessRuntime.BACKGROUND_EVENT_TYPES,
|
|
435
|
+
...this.backgroundEventRuntime,
|
|
439
436
|
}, threadId, runId, agentId, error, 103);
|
|
440
437
|
await this.setRunStateAndEmit(threadId, runId, 104, "failed", {
|
|
441
438
|
previousState: previousState === "queued" ? "running" : previousState,
|
|
@@ -463,18 +460,12 @@ export class AgentHarnessRuntime {
|
|
|
463
460
|
}
|
|
464
461
|
async setRunStateAndEmit(threadId, runId, sequence, state, options) {
|
|
465
462
|
return setRunStateAndEmitEvent({
|
|
466
|
-
|
|
467
|
-
publishEvent: (event) => this.eventBus.publish(event),
|
|
468
|
-
trackBackgroundTask: (task) => this.trackBackgroundTask(task),
|
|
469
|
-
backgroundEventTypes: AgentHarnessRuntime.BACKGROUND_EVENT_TYPES,
|
|
463
|
+
...this.backgroundEventRuntime,
|
|
470
464
|
}, threadId, runId, sequence, state, options);
|
|
471
465
|
}
|
|
472
466
|
async requestApprovalAndEmit(threadId, runId, input, interruptContent, checkpointRef, sequence) {
|
|
473
467
|
return requestApprovalAndEmitEvent({
|
|
474
|
-
|
|
475
|
-
publishEvent: (event) => this.eventBus.publish(event),
|
|
476
|
-
trackBackgroundTask: (task) => this.trackBackgroundTask(task),
|
|
477
|
-
backgroundEventTypes: AgentHarnessRuntime.BACKGROUND_EVENT_TYPES,
|
|
468
|
+
...this.backgroundEventRuntime,
|
|
478
469
|
}, threadId, runId, input, interruptContent, checkpointRef, sequence);
|
|
479
470
|
}
|
|
480
471
|
isDecisionRun(options) {
|
|
@@ -488,10 +479,7 @@ export class AgentHarnessRuntime {
|
|
|
488
479
|
}
|
|
489
480
|
async prepareRunStart(options, invocation, runCreatedPayload) {
|
|
490
481
|
const selectedAgentId = await this.resolveSelectedAgentId(options.input, options.agentId, options.threadId);
|
|
491
|
-
const binding = this.workspace
|
|
492
|
-
if (!binding) {
|
|
493
|
-
throw new Error(`Unknown agent ${selectedAgentId}`);
|
|
494
|
-
}
|
|
482
|
+
const binding = getRequiredWorkspaceBinding(this.workspace, selectedAgentId);
|
|
495
483
|
const policyDecision = this.policyEngine.evaluate(binding);
|
|
496
484
|
if (!policyDecision.allowed) {
|
|
497
485
|
throw new Error(`Policy evaluation blocked agent ${selectedAgentId}: ${policyDecision.reasons.join(", ")}`);
|
|
@@ -507,34 +495,11 @@ export class AgentHarnessRuntime {
|
|
|
507
495
|
runId,
|
|
508
496
|
isNewThread,
|
|
509
497
|
runCreatedEventPromise: emitRunCreatedEvent({
|
|
510
|
-
|
|
511
|
-
publishEvent: (event) => this.eventBus.publish(event),
|
|
512
|
-
trackBackgroundTask: (task) => this.trackBackgroundTask(task),
|
|
513
|
-
backgroundEventTypes: AgentHarnessRuntime.BACKGROUND_EVENT_TYPES,
|
|
498
|
+
...this.backgroundEventRuntime,
|
|
514
499
|
}, threadId, runId, runCreatedPayload(binding, selectedAgentId)),
|
|
515
500
|
releaseRunSlotPromise: this.acquireRunSlot(threadId, runId, "running", priority),
|
|
516
501
|
};
|
|
517
502
|
}
|
|
518
|
-
createStartupRecoveryContext() {
|
|
519
|
-
return {
|
|
520
|
-
persistence: this.persistence,
|
|
521
|
-
workspace: this.workspace,
|
|
522
|
-
runtimeAdapter: this.runtimeAdapter,
|
|
523
|
-
recoveryConfig: this.recoveryConfig,
|
|
524
|
-
concurrencyConfig: this.concurrencyConfig,
|
|
525
|
-
getBinding: (agentId) => this.workspace.bindings.get(agentId),
|
|
526
|
-
acquireRunSlot: (threadId, runId, activeState = "running", priority = 0) => this.acquireRunSlot(threadId, runId, activeState, priority),
|
|
527
|
-
executeQueuedRun: (binding, input, threadId, runId, agentId, options = {}) => this.executeQueuedRun(binding, input, threadId, runId, agentId, options),
|
|
528
|
-
setRunStateAndEmit: (threadId, runId, sequence, state, options) => this.setRunStateAndEmit(threadId, runId, sequence, state, options),
|
|
529
|
-
emit: (threadId, runId, sequence, eventType, payload) => this.emit(threadId, runId, sequence, eventType, payload),
|
|
530
|
-
loadRunInput: (threadId, runId) => this.loadRunInput(threadId, runId),
|
|
531
|
-
finalizeContinuedRun: (binding, threadId, runId, input, actual, options) => this.finalizeContinuedRun(binding, threadId, runId, input, actual, options),
|
|
532
|
-
supportsRunningReplay: (binding) => this.supportsRunningReplay(binding),
|
|
533
|
-
isStaleRunningRun: (thread, nowMs = Date.now()) => this.isStaleRunningRun(thread, nowMs),
|
|
534
|
-
recordLlmSuccess: (startedAt) => this.recordLlmSuccess(startedAt),
|
|
535
|
-
recordLlmFailure: (startedAt) => this.recordLlmFailure(startedAt),
|
|
536
|
-
};
|
|
537
|
-
}
|
|
538
503
|
async acquireRunSlot(threadId, runId, activeState = "running", priority = 0) {
|
|
539
504
|
return acquireHarnessRunSlot({
|
|
540
505
|
persistence: this.persistence,
|
|
@@ -606,7 +571,7 @@ export class AgentHarnessRuntime {
|
|
|
606
571
|
async *streamEvents(options) {
|
|
607
572
|
const invocation = normalizeInvocationEnvelope(options);
|
|
608
573
|
const selectedAgentId = await this.resolveSelectedAgentId(options.input, options.agentId, options.threadId);
|
|
609
|
-
const binding = this.workspace
|
|
574
|
+
const binding = getWorkspaceBinding(this.workspace, selectedAgentId);
|
|
610
575
|
if (!binding) {
|
|
611
576
|
const result = await this.run(options);
|
|
612
577
|
for (const line of result.output.split("\n")) {
|
|
@@ -646,10 +611,7 @@ export class AgentHarnessRuntime {
|
|
|
646
611
|
appendAssistantMessage: (currentThreadId, currentRunId, content) => appendLifecycleAssistantMessage(this.persistence, currentThreadId, currentRunId, content),
|
|
647
612
|
clearRunRequest: (currentThreadId, currentRunId) => this.persistence.clearRunRequest(currentThreadId, currentRunId),
|
|
648
613
|
emitSyntheticFallback: (currentThreadId, currentRunId, currentSelectedAgentId, error) => emitSyntheticFallbackEvent({
|
|
649
|
-
|
|
650
|
-
publishEvent: (event) => this.eventBus.publish(event),
|
|
651
|
-
trackBackgroundTask: (task) => this.trackBackgroundTask(task),
|
|
652
|
-
backgroundEventTypes: AgentHarnessRuntime.BACKGROUND_EVENT_TYPES,
|
|
614
|
+
...this.backgroundEventRuntime,
|
|
653
615
|
}, currentThreadId, currentRunId, currentSelectedAgentId, error),
|
|
654
616
|
});
|
|
655
617
|
}
|
|
@@ -658,7 +620,7 @@ export class AgentHarnessRuntime {
|
|
|
658
620
|
getApprovalById: (approvalId) => this.persistence.getApproval(approvalId),
|
|
659
621
|
getSession: (threadId) => this.getSession(threadId),
|
|
660
622
|
resolveApprovalRecord: (resumeOptions, thread) => resolveHarnessApprovalRecord(this.persistence, resumeOptions, thread),
|
|
661
|
-
getBinding: (agentId) => this.workspace
|
|
623
|
+
getBinding: (agentId) => getWorkspaceBinding(this.workspace, agentId),
|
|
662
624
|
buildResumePayload: (binding, approval, resumeOptions) => buildHarnessResumePayload(binding, approval, resumeOptions),
|
|
663
625
|
getRunCancellation: (runId) => this.getRunCancellation(runId),
|
|
664
626
|
finalizeCancelledRun: (threadId, runId, previousState, reason) => this.finalizeCancelledRun(threadId, runId, previousState, reason),
|
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
import type { CompiledAgentBinding, CompiledModel, CompiledTool, DeepAgentParams, LangChainAgentParams, RuntimeModelSlot } from "../../contracts/types.js";
|
|
2
|
+
export type BindingExecutionView = {
|
|
3
|
+
adapterKind: string;
|
|
4
|
+
adapterConfig: Record<string, unknown>;
|
|
5
|
+
langchainParams?: LangChainAgentParams;
|
|
6
|
+
deepAgentParams?: DeepAgentParams;
|
|
7
|
+
executionParams?: LangChainAgentParams | DeepAgentParams;
|
|
8
|
+
primaryTools: CompiledTool[];
|
|
9
|
+
primaryModel?: CompiledModel;
|
|
10
|
+
systemPrompt?: string;
|
|
11
|
+
middlewareConfigs?: Array<Record<string, unknown>>;
|
|
12
|
+
interruptCompatibilityRules?: Record<string, boolean | object>;
|
|
13
|
+
storeConfig?: Record<string, unknown>;
|
|
14
|
+
};
|
|
15
|
+
export declare function getBindingExecutionView(binding: CompiledAgentBinding): BindingExecutionView;
|
|
2
16
|
export declare function getBindingAdapterKind(binding: CompiledAgentBinding): string;
|
|
3
17
|
export declare function getBindingAdapterConfig(binding: CompiledAgentBinding): Record<string, unknown>;
|
|
4
18
|
export declare function getBindingLangChainParams(binding: CompiledAgentBinding): LangChainAgentParams | undefined;
|
|
@@ -24,6 +24,7 @@ function deriveBindingExecutionView(binding) {
|
|
|
24
24
|
adapterConfig,
|
|
25
25
|
langchainParams,
|
|
26
26
|
deepAgentParams,
|
|
27
|
+
executionParams: langchainParams ?? deepAgentParams,
|
|
27
28
|
primaryTools,
|
|
28
29
|
primaryModel: langchainParams?.model ?? deepAgentParams?.model,
|
|
29
30
|
systemPrompt: langchainParams?.systemPrompt ?? deepAgentParams?.systemPrompt,
|
|
@@ -35,17 +36,20 @@ function deriveBindingExecutionView(binding) {
|
|
|
35
36
|
bindingExecutionViewCache.set(binding, view);
|
|
36
37
|
return view;
|
|
37
38
|
}
|
|
39
|
+
export function getBindingExecutionView(binding) {
|
|
40
|
+
return deriveBindingExecutionView(binding);
|
|
41
|
+
}
|
|
38
42
|
export function getBindingAdapterKind(binding) {
|
|
39
|
-
return
|
|
43
|
+
return getBindingExecutionView(binding).adapterKind;
|
|
40
44
|
}
|
|
41
45
|
export function getBindingAdapterConfig(binding) {
|
|
42
|
-
return
|
|
46
|
+
return getBindingExecutionView(binding).adapterConfig;
|
|
43
47
|
}
|
|
44
48
|
export function getBindingLangChainParams(binding) {
|
|
45
|
-
return
|
|
49
|
+
return getBindingExecutionView(binding).langchainParams;
|
|
46
50
|
}
|
|
47
51
|
export function getBindingDeepAgentParams(binding) {
|
|
48
|
-
return
|
|
52
|
+
return getBindingExecutionView(binding).deepAgentParams;
|
|
49
53
|
}
|
|
50
54
|
export function isLangChainBinding(binding) {
|
|
51
55
|
return getBindingAdapterKind(binding) === "langchain-v1" || Boolean(binding.langchainAgentParams);
|
|
@@ -54,28 +58,28 @@ export function isDeepAgentBinding(binding) {
|
|
|
54
58
|
return getBindingAdapterKind(binding) === "deepagent" || Boolean(binding.deepAgentParams);
|
|
55
59
|
}
|
|
56
60
|
export function getBindingPrimaryTools(binding) {
|
|
57
|
-
return
|
|
61
|
+
return getBindingExecutionView(binding).primaryTools;
|
|
58
62
|
}
|
|
59
63
|
export function getBindingPrimaryModel(binding) {
|
|
60
|
-
return
|
|
64
|
+
return getBindingExecutionView(binding).primaryModel;
|
|
61
65
|
}
|
|
62
66
|
export function getBindingRuntimeModel(binding, slot) {
|
|
63
67
|
return binding.harnessRuntime.models?.[slot];
|
|
64
68
|
}
|
|
65
69
|
export function getBindingSystemPrompt(binding) {
|
|
66
|
-
return
|
|
70
|
+
return getBindingExecutionView(binding).systemPrompt;
|
|
67
71
|
}
|
|
68
72
|
export function getBindingMiddlewareConfigs(binding) {
|
|
69
|
-
return
|
|
73
|
+
return getBindingExecutionView(binding).middlewareConfigs;
|
|
70
74
|
}
|
|
71
75
|
export function getBindingInterruptCompatibilityRules(binding) {
|
|
72
|
-
return
|
|
76
|
+
return getBindingExecutionView(binding).interruptCompatibilityRules;
|
|
73
77
|
}
|
|
74
78
|
export function getBindingModelInit(binding) {
|
|
75
79
|
return getBindingPrimaryModel(binding)?.init;
|
|
76
80
|
}
|
|
77
81
|
export function getBindingStoreConfig(binding) {
|
|
78
|
-
return
|
|
82
|
+
return getBindingExecutionView(binding).storeConfig;
|
|
79
83
|
}
|
|
80
84
|
export function bindingHasSubagents(binding) {
|
|
81
85
|
return (getBindingDeepAgentParams(binding)?.subagents.length ?? 0) > 0;
|