@botbotgo/agent-harness 0.0.118 → 0.0.120
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/contracts/runtime.d.ts +4 -68
- package/dist/contracts/workspace.d.ts +43 -12
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -1
- package/dist/runtime/adapter/middleware-assembly.d.ts +28 -4
- package/dist/runtime/adapter/middleware-assembly.js +65 -30
- package/dist/runtime/adapter/stream-event-projection.js +104 -2
- package/dist/runtime/agent-runtime-adapter.d.ts +2 -2
- package/dist/runtime/agent-runtime-adapter.js +39 -29
- package/dist/runtime/harness/run/routing.d.ts +2 -0
- package/dist/runtime/harness/run/routing.js +7 -3
- package/dist/runtime/harness/run/start-run.js +3 -3
- package/dist/runtime/harness.d.ts +3 -3
- package/dist/runtime/harness.js +15 -15
- package/dist/runtime/parsing/index.d.ts +2 -1
- package/dist/runtime/parsing/index.js +1 -1
- package/dist/runtime/parsing/stream-event-parsing.d.ts +1 -2
- package/dist/runtime/parsing/stream-event-parsing.js +0 -99
- package/dist/runtime/parsing/stream-event-types.d.ts +62 -0
- package/dist/runtime/parsing/stream-event-types.js +1 -0
- package/dist/runtime/support/compiled-binding.d.ts +7 -5
- package/dist/runtime/support/compiled-binding.js +140 -47
- package/dist/runtime/support/harness-support.d.ts +1 -1
- package/dist/runtime/support/harness-support.js +5 -5
- package/dist/utils/compiled-binding.d.ts +3 -0
- package/dist/utils/compiled-binding.js +33 -0
- package/dist/workspace/agent-binding-compiler.js +66 -55
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { RunState } from "./core.js";
|
|
2
2
|
import type { CompiledAgentBinding, CompiledModel, CompiledTool, ParsedAgentObject, ParsedToolObject, WorkspaceBundle } from "./workspace.js";
|
|
3
|
+
import type { CompatibleStreamPart as InternalCompatibleStreamPart, NormalizedUpstreamEvent as InternalNormalizedUpstreamEvent, UpstreamRuntimeEvent as InternalUpstreamRuntimeEvent } from "../runtime/parsing/stream-event-types.js";
|
|
3
4
|
export type ThreadSummary = {
|
|
4
5
|
agentId: string;
|
|
5
6
|
threadId: string;
|
|
@@ -85,74 +86,9 @@ export type RunResult = {
|
|
|
85
86
|
artifacts?: ArtifactRecord[];
|
|
86
87
|
metadata?: Record<string, unknown>;
|
|
87
88
|
};
|
|
88
|
-
export type NormalizedUpstreamEvent =
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
text: string;
|
|
92
|
-
ns?: string[];
|
|
93
|
-
nodeName?: string;
|
|
94
|
-
} | {
|
|
95
|
-
kind: "reasoning-delta";
|
|
96
|
-
text: string;
|
|
97
|
-
ns?: string[];
|
|
98
|
-
nodeName?: string;
|
|
99
|
-
} | {
|
|
100
|
-
kind: "tool-start";
|
|
101
|
-
toolName: string;
|
|
102
|
-
input?: unknown;
|
|
103
|
-
ns?: string[];
|
|
104
|
-
nodeName?: string;
|
|
105
|
-
} | {
|
|
106
|
-
kind: "tool-end";
|
|
107
|
-
toolName: string;
|
|
108
|
-
output?: unknown;
|
|
109
|
-
isError?: boolean;
|
|
110
|
-
ns?: string[];
|
|
111
|
-
nodeName?: string;
|
|
112
|
-
} | {
|
|
113
|
-
kind: "agent-step";
|
|
114
|
-
label: string;
|
|
115
|
-
ns?: string[];
|
|
116
|
-
nodeName?: string;
|
|
117
|
-
} | {
|
|
118
|
-
kind: "interrupt";
|
|
119
|
-
interrupt: unknown;
|
|
120
|
-
ns?: string[];
|
|
121
|
-
nodeName?: string;
|
|
122
|
-
} | {
|
|
123
|
-
kind: "run-event";
|
|
124
|
-
eventName: string;
|
|
125
|
-
data?: Record<string, unknown>;
|
|
126
|
-
ns?: string[];
|
|
127
|
-
nodeName?: string;
|
|
128
|
-
};
|
|
129
|
-
export type CompatibleStreamPart = {
|
|
130
|
-
type: "messages";
|
|
131
|
-
ns: string[];
|
|
132
|
-
data: [unknown, Record<string, unknown>];
|
|
133
|
-
} | {
|
|
134
|
-
type: "updates";
|
|
135
|
-
ns: string[];
|
|
136
|
-
data: Record<string, unknown>;
|
|
137
|
-
} | {
|
|
138
|
-
type: "custom";
|
|
139
|
-
ns: string[];
|
|
140
|
-
data: unknown;
|
|
141
|
-
};
|
|
142
|
-
export type UpstreamRuntimeEvent = {
|
|
143
|
-
format: "langgraph-v2";
|
|
144
|
-
/** @deprecated Prefer streamPart plus raw/event/name/data/ns for upstream-aligned consumption. */
|
|
145
|
-
normalized: NormalizedUpstreamEvent;
|
|
146
|
-
streamPart: CompatibleStreamPart;
|
|
147
|
-
raw: unknown;
|
|
148
|
-
event?: string;
|
|
149
|
-
name?: string;
|
|
150
|
-
runType?: string;
|
|
151
|
-
data?: Record<string, unknown>;
|
|
152
|
-
metadata?: Record<string, unknown>;
|
|
153
|
-
tags?: string[];
|
|
154
|
-
ns?: string[];
|
|
155
|
-
};
|
|
89
|
+
export type NormalizedUpstreamEvent = InternalNormalizedUpstreamEvent;
|
|
90
|
+
export type CompatibleStreamPart = InternalCompatibleStreamPart;
|
|
91
|
+
export type UpstreamRuntimeEvent = InternalUpstreamRuntimeEvent;
|
|
156
92
|
export type RuntimeListeners = {
|
|
157
93
|
onEvent?: (event: HarnessEvent) => void | Promise<void>;
|
|
158
94
|
};
|
|
@@ -146,18 +146,10 @@ export type LangChainAgentParams = {
|
|
|
146
146
|
model: CompiledModel;
|
|
147
147
|
tools: CompiledTool[];
|
|
148
148
|
systemPrompt?: string;
|
|
149
|
-
interruptOn?: Record<string, boolean | object>;
|
|
150
149
|
stateSchema?: unknown;
|
|
151
150
|
responseFormat?: unknown;
|
|
152
151
|
contextSchema?: unknown;
|
|
153
|
-
filesystem?: Record<string, unknown>;
|
|
154
152
|
middleware?: Array<Record<string, unknown>>;
|
|
155
|
-
passthrough?: Record<string, unknown>;
|
|
156
|
-
subagents?: CompiledSubAgent[];
|
|
157
|
-
memory?: string[];
|
|
158
|
-
skills?: string[];
|
|
159
|
-
generalPurposeAgent?: boolean;
|
|
160
|
-
taskDescription?: string;
|
|
161
153
|
includeAgentName?: "inline";
|
|
162
154
|
version?: "v1" | "v2";
|
|
163
155
|
name?: string;
|
|
@@ -170,8 +162,6 @@ export type DeepAgentParams = {
|
|
|
170
162
|
responseFormat?: unknown;
|
|
171
163
|
contextSchema?: unknown;
|
|
172
164
|
middleware?: Array<Record<string, unknown>>;
|
|
173
|
-
passthrough?: Record<string, unknown>;
|
|
174
|
-
description: string;
|
|
175
165
|
subagents: CompiledSubAgent[];
|
|
176
166
|
interruptOn?: Record<string, boolean | object>;
|
|
177
167
|
backend?: Record<string, unknown>;
|
|
@@ -180,6 +170,20 @@ export type DeepAgentParams = {
|
|
|
180
170
|
memory: string[];
|
|
181
171
|
skills: string[];
|
|
182
172
|
};
|
|
173
|
+
export type LegacyLangChainAgentParams = LangChainAgentParams & {
|
|
174
|
+
passthrough?: Record<string, unknown>;
|
|
175
|
+
interruptOn?: Record<string, boolean | object>;
|
|
176
|
+
filesystem?: Record<string, unknown>;
|
|
177
|
+
subagents?: CompiledSubAgent[];
|
|
178
|
+
memory?: string[];
|
|
179
|
+
skills?: string[];
|
|
180
|
+
generalPurposeAgent?: boolean;
|
|
181
|
+
taskDescription?: string;
|
|
182
|
+
};
|
|
183
|
+
export type LegacyDeepAgentParams = DeepAgentParams & {
|
|
184
|
+
description?: string;
|
|
185
|
+
passthrough?: Record<string, unknown>;
|
|
186
|
+
};
|
|
183
187
|
export type CompiledExecutionBinding = {
|
|
184
188
|
kind: "langchain-v1";
|
|
185
189
|
params: LangChainAgentParams;
|
|
@@ -193,14 +197,41 @@ export type CompiledAgentBinding = {
|
|
|
193
197
|
kind: string;
|
|
194
198
|
config?: Record<string, unknown>;
|
|
195
199
|
};
|
|
200
|
+
/**
|
|
201
|
+
* Canonical execution binding compiled from workspace YAML.
|
|
202
|
+
* Runtime code should prefer this field and treat backend-specific aliases
|
|
203
|
+
* below as compatibility shims.
|
|
204
|
+
*/
|
|
196
205
|
execution?: CompiledExecutionBinding;
|
|
197
|
-
|
|
198
|
-
|
|
206
|
+
/**
|
|
207
|
+
* Compatibility alias for older tests and callers.
|
|
208
|
+
* Prefer `execution.kind === "langchain-v1"` and `execution.params`.
|
|
209
|
+
*/
|
|
210
|
+
langchainAgentParams?: LegacyLangChainAgentParams;
|
|
211
|
+
/**
|
|
212
|
+
* Compatibility alias for older tests and callers.
|
|
213
|
+
* Prefer `execution.kind === "deepagent"` and `execution.params`.
|
|
214
|
+
*/
|
|
215
|
+
deepAgentParams?: LegacyDeepAgentParams;
|
|
199
216
|
harnessRuntime: {
|
|
200
217
|
runRoot: string;
|
|
201
218
|
workspaceRoot?: string;
|
|
202
219
|
capabilities?: RuntimeCapabilities;
|
|
203
220
|
resilience?: Record<string, unknown>;
|
|
221
|
+
deepagent?: {
|
|
222
|
+
description?: string;
|
|
223
|
+
passthrough?: Record<string, unknown>;
|
|
224
|
+
};
|
|
225
|
+
langchain?: {
|
|
226
|
+
passthrough?: Record<string, unknown>;
|
|
227
|
+
interruptOn?: Record<string, boolean | object>;
|
|
228
|
+
filesystem?: Record<string, unknown>;
|
|
229
|
+
subagents?: CompiledSubAgent[];
|
|
230
|
+
memory?: string[];
|
|
231
|
+
skills?: string[];
|
|
232
|
+
generalPurposeAgent?: boolean;
|
|
233
|
+
taskDescription?: string;
|
|
234
|
+
};
|
|
204
235
|
checkpointer?: Record<string, unknown> | boolean;
|
|
205
236
|
store?: Record<string, unknown>;
|
|
206
237
|
runtimeMemory?: Record<string, unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AGENT_HARNESS_VERSION = "0.0.
|
|
1
|
+
export declare const AGENT_HARNESS_VERSION = "0.0.119";
|
package/dist/package-version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const AGENT_HARNESS_VERSION = "0.0.
|
|
1
|
+
export const AGENT_HARNESS_VERSION = "0.0.119";
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import { FilesystemBackend } from "deepagents";
|
|
2
2
|
import type { CompiledAgentBinding, CompiledModel, CompiledSubAgent, DeepAgentParams, RuntimeAdapterOptions } from "../../contracts/types.js";
|
|
3
3
|
import type { ExecutableTool } from "./flow/invoke-runtime.js";
|
|
4
|
+
export type LangChainRuntimeExtensionPlan = {
|
|
5
|
+
includePatchToolCalls: boolean;
|
|
6
|
+
includeAutomaticSummarization: boolean;
|
|
7
|
+
context: {
|
|
8
|
+
skills: string[];
|
|
9
|
+
memory: string[];
|
|
10
|
+
};
|
|
11
|
+
delegation?: {
|
|
12
|
+
subagents: CompiledSubAgent[];
|
|
13
|
+
generalPurposeAgent?: boolean;
|
|
14
|
+
taskDescription?: string;
|
|
15
|
+
interruptOn?: Record<string, boolean | object>;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
4
18
|
export type UpstreamSubagentConfig = {
|
|
5
19
|
name: string;
|
|
6
20
|
description: string;
|
|
@@ -19,6 +33,7 @@ export declare function buildBuiltinTaskSubagentMiddleware(input: {
|
|
|
19
33
|
builtinBackend: unknown;
|
|
20
34
|
summarizationModel: unknown;
|
|
21
35
|
}): unknown[];
|
|
36
|
+
export declare function planLangChainRuntimeExtensions(binding: CompiledAgentBinding): LangChainRuntimeExtensionPlan | undefined;
|
|
22
37
|
export declare function resolveBuiltinMiddlewareBackend(input: {
|
|
23
38
|
binding: CompiledAgentBinding;
|
|
24
39
|
runtimeAdapterOptions: RuntimeAdapterOptions;
|
|
@@ -70,13 +85,22 @@ export declare function resolveBuiltinMiddlewareTools(input: {
|
|
|
70
85
|
files?: Record<string, unknown>;
|
|
71
86
|
}) => Promise<unknown>;
|
|
72
87
|
}): Promise<Map<string, ExecutableTool>>;
|
|
73
|
-
export declare function
|
|
88
|
+
export declare function materializeAutomaticSummarizationMiddleware(input: {
|
|
74
89
|
binding: CompiledAgentBinding;
|
|
75
90
|
createDeclaredMiddlewareResolverOptions: (binding?: CompiledAgentBinding) => unknown;
|
|
76
91
|
}): Promise<unknown[]>;
|
|
77
|
-
export declare function
|
|
92
|
+
export declare function materializeLangChainRuntimeMiddleware(input: {
|
|
93
|
+
binding: CompiledAgentBinding;
|
|
94
|
+
plan: LangChainRuntimeExtensionPlan;
|
|
95
|
+
materializeAutomaticSummarizationMiddleware: (binding: CompiledAgentBinding) => Promise<unknown[]>;
|
|
96
|
+
resolveFilesystemBackend: (binding: CompiledAgentBinding) => FilesystemBackend;
|
|
97
|
+
resolveModel: (model: CompiledModel) => Promise<unknown>;
|
|
98
|
+
resolveTools: (tools: Parameters<DeepAgentParams["tools"]["slice"]>[0] extends never ? never : any, binding?: CompiledAgentBinding) => unknown[];
|
|
99
|
+
resolveSubagents: (subagents: CompiledSubAgent[], binding?: CompiledAgentBinding) => Promise<UpstreamSubagentConfig[]>;
|
|
100
|
+
}): Promise<unknown[]>;
|
|
101
|
+
export declare function resolveLangChainRuntimeExtensionMiddleware(input: {
|
|
78
102
|
binding: CompiledAgentBinding;
|
|
79
|
-
|
|
103
|
+
materializeAutomaticSummarizationMiddleware: (binding: CompiledAgentBinding) => Promise<unknown[]>;
|
|
80
104
|
resolveFilesystemBackend: (binding: CompiledAgentBinding) => FilesystemBackend;
|
|
81
105
|
resolveModel: (model: CompiledModel) => Promise<unknown>;
|
|
82
106
|
resolveTools: (tools: Parameters<DeepAgentParams["tools"]["slice"]>[0] extends never ? never : any, binding?: CompiledAgentBinding) => unknown[];
|
|
@@ -89,5 +113,5 @@ export declare function resolveMiddleware(input: {
|
|
|
89
113
|
}>;
|
|
90
114
|
runtimeAdapterOptions: RuntimeAdapterOptions;
|
|
91
115
|
createDeclaredMiddlewareResolverOptions: (binding?: CompiledAgentBinding) => unknown;
|
|
92
|
-
|
|
116
|
+
resolveLangChainRuntimeExtensionMiddleware: (binding: CompiledAgentBinding) => Promise<unknown[]>;
|
|
93
117
|
}): Promise<unknown[]>;
|
|
@@ -62,6 +62,36 @@ function resolveLangChainDelegationCompatibility(params) {
|
|
|
62
62
|
taskDescription: params.taskDescription,
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
|
+
export function planLangChainRuntimeExtensions(binding) {
|
|
66
|
+
const primaryModel = getBindingPrimaryModel(binding);
|
|
67
|
+
if (!isLangChainBinding(binding) || !primaryModel) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
const skills = getBindingSkills(binding);
|
|
71
|
+
const memory = getBindingMemorySources(binding);
|
|
72
|
+
const delegationCompatibility = resolveLangChainDelegationCompatibility({
|
|
73
|
+
model: primaryModel,
|
|
74
|
+
subagents: getBindingSubagents(binding),
|
|
75
|
+
generalPurposeAgent: getBindingGeneralPurposeAgent(binding),
|
|
76
|
+
taskDescription: getBindingTaskDescription(binding),
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
includePatchToolCalls: !bindingHasMiddlewareKind(binding, "patchToolCalls"),
|
|
80
|
+
includeAutomaticSummarization: !bindingHasMiddlewareKind(binding, "summarization"),
|
|
81
|
+
context: {
|
|
82
|
+
skills,
|
|
83
|
+
memory,
|
|
84
|
+
},
|
|
85
|
+
delegation: bindingHasLangChainSubagentSupport(binding)
|
|
86
|
+
? {
|
|
87
|
+
subagents: delegationCompatibility.subagents ?? [],
|
|
88
|
+
generalPurposeAgent: delegationCompatibility.generalPurposeAgent,
|
|
89
|
+
taskDescription: delegationCompatibility.taskDescription,
|
|
90
|
+
interruptOn: getBindingInterruptCompatibilityRules(binding),
|
|
91
|
+
}
|
|
92
|
+
: undefined,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
65
95
|
export function resolveBuiltinMiddlewareBackend(input) {
|
|
66
96
|
const runtimeState = {
|
|
67
97
|
...(input.options?.state ?? {}),
|
|
@@ -154,57 +184,62 @@ export async function resolveBuiltinMiddlewareTools(input) {
|
|
|
154
184
|
: undefined,
|
|
155
185
|
});
|
|
156
186
|
}
|
|
157
|
-
export async function
|
|
158
|
-
if (bindingHasMiddlewareKind(input.binding, "summarization")) {
|
|
159
|
-
return [];
|
|
160
|
-
}
|
|
187
|
+
export async function materializeAutomaticSummarizationMiddleware(input) {
|
|
161
188
|
const primaryModel = getBindingPrimaryModel(input.binding);
|
|
162
189
|
if (!primaryModel) {
|
|
163
190
|
return [];
|
|
164
191
|
}
|
|
165
192
|
return resolveDeclaredMiddleware([{ kind: "summarization", model: primaryModel }], input.createDeclaredMiddlewareResolverOptions(input.binding));
|
|
166
193
|
}
|
|
167
|
-
export async function
|
|
194
|
+
export async function materializeLangChainRuntimeMiddleware(input) {
|
|
168
195
|
const primaryModel = getBindingPrimaryModel(input.binding);
|
|
169
196
|
const primaryTools = getBindingPrimaryTools(input.binding);
|
|
170
|
-
if (!
|
|
197
|
+
if (!primaryModel) {
|
|
171
198
|
return [];
|
|
172
199
|
}
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
automaticMiddleware.push(...(await input.resolveAutomaticSummarizationMiddleware(input.binding)));
|
|
182
|
-
automaticMiddleware.push(...buildLangChainContextMiddleware({
|
|
200
|
+
const runtimeMiddleware = [];
|
|
201
|
+
if (input.plan.includePatchToolCalls) {
|
|
202
|
+
runtimeMiddleware.push(createPatchToolCallsMiddleware());
|
|
203
|
+
}
|
|
204
|
+
if (input.plan.includeAutomaticSummarization) {
|
|
205
|
+
runtimeMiddleware.push(...(await input.materializeAutomaticSummarizationMiddleware(input.binding)));
|
|
206
|
+
}
|
|
207
|
+
runtimeMiddleware.push(...buildLangChainContextMiddleware({
|
|
183
208
|
binding: input.binding,
|
|
184
|
-
skills:
|
|
185
|
-
memory:
|
|
209
|
+
skills: input.plan.context.skills,
|
|
210
|
+
memory: input.plan.context.memory,
|
|
186
211
|
resolveFilesystemBackend: input.resolveFilesystemBackend,
|
|
187
212
|
}));
|
|
188
|
-
if (
|
|
189
|
-
|
|
213
|
+
if (input.plan.delegation) {
|
|
214
|
+
runtimeMiddleware.push(createSubAgentMiddleware({
|
|
190
215
|
defaultModel: (await input.resolveModel(primaryModel)),
|
|
191
216
|
defaultTools: input.resolveTools(primaryTools, input.binding),
|
|
192
|
-
defaultInterruptOn:
|
|
193
|
-
subagents: (await input.resolveSubagents(
|
|
194
|
-
generalPurposeAgent:
|
|
195
|
-
taskDescription:
|
|
217
|
+
defaultInterruptOn: input.plan.delegation.interruptOn,
|
|
218
|
+
subagents: (await input.resolveSubagents(input.plan.delegation.subagents, input.binding)),
|
|
219
|
+
generalPurposeAgent: input.plan.delegation.generalPurposeAgent,
|
|
220
|
+
taskDescription: input.plan.delegation.taskDescription ?? null,
|
|
196
221
|
}));
|
|
197
222
|
}
|
|
198
|
-
return
|
|
223
|
+
return runtimeMiddleware;
|
|
224
|
+
}
|
|
225
|
+
export async function resolveLangChainRuntimeExtensionMiddleware(input) {
|
|
226
|
+
const plan = planLangChainRuntimeExtensions(input.binding);
|
|
227
|
+
if (!plan) {
|
|
228
|
+
return [];
|
|
229
|
+
}
|
|
230
|
+
return materializeLangChainRuntimeMiddleware({
|
|
231
|
+
...input,
|
|
232
|
+
plan,
|
|
233
|
+
});
|
|
199
234
|
}
|
|
200
235
|
export async function resolveMiddleware(input) {
|
|
201
|
-
const
|
|
202
|
-
const
|
|
203
|
-
? await input.
|
|
236
|
+
const declarativeUpstreamMiddleware = await resolveDeclaredMiddleware(getBindingMiddlewareConfigs(input.binding), input.createDeclaredMiddlewareResolverOptions(input.binding));
|
|
237
|
+
const runtimeExtensionMiddleware = isLangChainBinding(input.binding)
|
|
238
|
+
? await input.resolveLangChainRuntimeExtensionMiddleware(input.binding)
|
|
204
239
|
: [];
|
|
205
240
|
const middleware = [
|
|
206
|
-
...
|
|
207
|
-
...
|
|
241
|
+
...declarativeUpstreamMiddleware,
|
|
242
|
+
...runtimeExtensionMiddleware,
|
|
208
243
|
...(input.runtimeAdapterOptions.middlewareResolver ? input.runtimeAdapterOptions.middlewareResolver(input.binding) : []),
|
|
209
244
|
];
|
|
210
245
|
if (input.interruptOn && Object.keys(input.interruptOn).length > 0) {
|
|
@@ -1,6 +1,108 @@
|
|
|
1
1
|
import { sanitizeVisibleText } from "../parsing/output-parsing.js";
|
|
2
|
-
import { computeIncrementalOutput,
|
|
2
|
+
import { computeIncrementalOutput, extractInterruptPayload, extractReasoningStreamOutput, extractStateStreamOutput, extractTerminalStreamOutput, extractToolResult, extractVisibleStreamOutput, normalizeTerminalOutputKey, normalizeUpstreamRuntimeEvent, } from "../parsing/stream-event-parsing.js";
|
|
3
3
|
import { resolveModelFacingToolName } from "./tool/tool-name-mapping.js";
|
|
4
|
+
function formatStepValue(value, maxLength = 120) {
|
|
5
|
+
if (value == null)
|
|
6
|
+
return "";
|
|
7
|
+
const normalized = typeof value === "string"
|
|
8
|
+
? parseMaybeJson(value)
|
|
9
|
+
: value;
|
|
10
|
+
const summarized = summarizeStepValue(normalized);
|
|
11
|
+
const serialized = typeof summarized === "string"
|
|
12
|
+
? summarized
|
|
13
|
+
: (() => {
|
|
14
|
+
try {
|
|
15
|
+
return JSON.stringify(summarized);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return String(summarized);
|
|
19
|
+
}
|
|
20
|
+
})();
|
|
21
|
+
return serialized.length > maxLength ? serialized.slice(0, maxLength) + "…" : serialized;
|
|
22
|
+
}
|
|
23
|
+
function parseMaybeJson(value) {
|
|
24
|
+
const trimmed = value.trim();
|
|
25
|
+
if (!trimmed.startsWith("{") && !trimmed.startsWith("[")) {
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(trimmed);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function summarizeStepValue(value) {
|
|
36
|
+
if (typeof value !== "object" || !value) {
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
const record = value;
|
|
40
|
+
if (typeof record.url === "string" && typeof record.status === "number") {
|
|
41
|
+
const warnings = Array.isArray(record.warnings) ? record.warnings.filter((item) => typeof item === "string") : [];
|
|
42
|
+
return {
|
|
43
|
+
status: record.status,
|
|
44
|
+
ok: record.ok,
|
|
45
|
+
quality: record.quality,
|
|
46
|
+
source: record.source,
|
|
47
|
+
warnings,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
function humanizeEventName(name) {
|
|
53
|
+
return name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[._-]+/g, " ").replace(/\s+/g, " ").trim().toLowerCase();
|
|
54
|
+
}
|
|
55
|
+
function deriveAgentStep(event) {
|
|
56
|
+
if (typeof event !== "object" || !event)
|
|
57
|
+
return null;
|
|
58
|
+
const typed = event;
|
|
59
|
+
const name = typeof typed.name === "string" ? typed.name : "";
|
|
60
|
+
if (typed.event === "on_tool_start" || (typed.event === "on_chain_start" && typed.run_type === "tool")) {
|
|
61
|
+
const inputSummary = formatStepValue(typed.data?.input);
|
|
62
|
+
return inputSummary ? `tool ${name || "tool"} ${inputSummary}` : `tool ${name || "tool"}`;
|
|
63
|
+
}
|
|
64
|
+
if (typed.event === "on_tool_end" || (typed.event === "on_chain_end" && typed.run_type === "tool")) {
|
|
65
|
+
const outputSummary = formatStepValue(typed.data?.output, 80);
|
|
66
|
+
return outputSummary ? `tool ${name || "tool"} done ${outputSummary}` : `tool ${name || "tool"} done`;
|
|
67
|
+
}
|
|
68
|
+
if (typed.event === "on_tool_error" || (typed.event === "on_chain_error" && typed.run_type === "tool")) {
|
|
69
|
+
const errorSummary = formatStepValue(typed.data?.error ?? typed.data?.output, 80);
|
|
70
|
+
return errorSummary ? `tool ${name || "tool"} error ${errorSummary}` : `tool ${name || "tool"} error`;
|
|
71
|
+
}
|
|
72
|
+
if (typed.event === "on_chat_model_start") {
|
|
73
|
+
const inputTools = typed.data?.input?.tools;
|
|
74
|
+
const tools = typed.invocation_params?.tools ?? inputTools ?? [];
|
|
75
|
+
const toolNames = tools.map((tool) => tool.name ?? tool.function?.name).filter((toolName) => typeof toolName === "string").join(", ");
|
|
76
|
+
return toolNames ? `calling model tools: [${toolNames}]` : "calling model…";
|
|
77
|
+
}
|
|
78
|
+
if (typed.event === "on_chain_start") {
|
|
79
|
+
if (/SkillsMiddleware/i.test(name))
|
|
80
|
+
return "loading skills…";
|
|
81
|
+
if (/MemoryMiddleware/i.test(name))
|
|
82
|
+
return "loading memory…";
|
|
83
|
+
if (/patchToolCallsMiddleware/i.test(name))
|
|
84
|
+
return "normalizing tool calls…";
|
|
85
|
+
if (/HumanInTheLoopMiddleware/i.test(name))
|
|
86
|
+
return "checking approvals…";
|
|
87
|
+
if (/todoListMiddleware/i.test(name))
|
|
88
|
+
return "updating plan…";
|
|
89
|
+
if (/model_request/i.test(name))
|
|
90
|
+
return "preparing model request…";
|
|
91
|
+
if (/RunnableLambda/i.test(name) || /^__start__$/.test(name))
|
|
92
|
+
return null;
|
|
93
|
+
if (/(subagent|specialist)/i.test(name))
|
|
94
|
+
return `starting ${humanizeEventName(name)}…`;
|
|
95
|
+
if (/agent$/i.test(name))
|
|
96
|
+
return `running ${humanizeEventName(name)}…`;
|
|
97
|
+
}
|
|
98
|
+
if (typed.event === "on_chain_end") {
|
|
99
|
+
if (/(subagent|specialist)/i.test(name))
|
|
100
|
+
return `${humanizeEventName(name)} done`;
|
|
101
|
+
if (/agent$/i.test(name) && !/^__start__$/.test(name))
|
|
102
|
+
return `${humanizeEventName(name)} done`;
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
4
106
|
export function createStreamEventProjectionState() {
|
|
5
107
|
return {
|
|
6
108
|
emittedOutput: "",
|
|
@@ -45,7 +147,7 @@ export function projectRuntimeStreamEvent(params) {
|
|
|
45
147
|
}
|
|
46
148
|
}
|
|
47
149
|
}
|
|
48
|
-
const agentStep =
|
|
150
|
+
const agentStep = deriveAgentStep(event);
|
|
49
151
|
if (agentStep && agentStep !== state.lastStep) {
|
|
50
152
|
state.lastStep = agentStep;
|
|
51
153
|
chunks.push({ kind: "step", content: agentStep });
|
|
@@ -62,8 +62,8 @@ export declare class AgentRuntimeAdapter {
|
|
|
62
62
|
private createAssemblyResolvers;
|
|
63
63
|
private invokeBuiltinTaskTool;
|
|
64
64
|
private resolveBuiltinMiddlewareTools;
|
|
65
|
-
private
|
|
66
|
-
private
|
|
65
|
+
private materializeAutomaticSummarizationMiddleware;
|
|
66
|
+
private resolveLangChainRuntimeExtensionMiddleware;
|
|
67
67
|
private resolveMiddleware;
|
|
68
68
|
private resolveSubagents;
|
|
69
69
|
private createLangChainRunnable;
|
|
@@ -8,7 +8,7 @@ import { buildToolNameMapping, } from "./adapter/tool/tool-name-mapping.js";
|
|
|
8
8
|
import { executeRuntimeInvocation } from "./adapter/flow/invocation-flow.js";
|
|
9
9
|
import { streamRuntimeExecution } from "./adapter/flow/stream-runtime.js";
|
|
10
10
|
import { applyStrictToolJsonInstruction as applyStrictToolJsonInstructionHelper, callRuntimeWithToolParseRecovery as callRuntimeWithToolParseRecoveryHelper, createModelFallbackRunnable as createModelFallbackRunnableHelper, invokeWithProviderRetry as invokeWithProviderRetryHelper, iterateWithTimeout as iterateWithTimeoutHelper, materializeModelStream as materializeModelStreamHelper, RuntimeOperationTimeoutError, withRuntimeTimeout, } from "./adapter/runtime-shell.js";
|
|
11
|
-
import { invokeBuiltinTaskTool as invokeBuiltinTaskToolHelper,
|
|
11
|
+
import { invokeBuiltinTaskTool as invokeBuiltinTaskToolHelper, materializeAutomaticSummarizationMiddleware as materializeAutomaticSummarizationMiddlewareHelper, resolveBuiltinMiddlewareBackend as resolveBuiltinMiddlewareBackendHelper, resolveBuiltinMiddlewareTools as resolveBuiltinMiddlewareToolsHelper, resolveLangChainRuntimeExtensionMiddleware as resolveLangChainRuntimeExtensionMiddlewareHelper, resolveMiddleware as resolveMiddlewareHelper, resolveSubagents as resolveSubagentsHelper, } from "./adapter/middleware-assembly.js";
|
|
12
12
|
import { computeRemainingTimeoutMs, resolveBindingTimeout, resolveStreamIdleTimeout, } from "./adapter/resilience.js";
|
|
13
13
|
import { createResolvedModel } from "./adapter/model/model-providers.js";
|
|
14
14
|
import { compileInterruptOn } from "./adapter/tool/interrupt-policy.js";
|
|
@@ -37,20 +37,16 @@ export function resolveRunnableCheckpointer(options, binding) {
|
|
|
37
37
|
export function resolveRunnableInterruptOn(binding) {
|
|
38
38
|
return compileInterruptOn(getBindingPrimaryTools(binding), getBindingInterruptCompatibilityRules(binding));
|
|
39
39
|
}
|
|
40
|
-
function buildUpstreamCreateBaseParams(binding,
|
|
40
|
+
function buildUpstreamCreateBaseParams(binding, supportedFields) {
|
|
41
41
|
const executionParams = getBindingExecutionParams(binding);
|
|
42
42
|
if (!executionParams) {
|
|
43
43
|
throw new Error(`Agent ${binding.agent.id} has no compiled execution params`);
|
|
44
44
|
}
|
|
45
45
|
const source = executionParams;
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
...(passthrough ?? {}),
|
|
52
|
-
...stripped,
|
|
53
|
-
};
|
|
46
|
+
const upstreamParams = Object.fromEntries(supportedFields
|
|
47
|
+
.filter((key) => key in source && source[key] !== undefined)
|
|
48
|
+
.map((key) => [key, source[key]]));
|
|
49
|
+
return upstreamParams;
|
|
54
50
|
}
|
|
55
51
|
export function buildLangChainCreateParams(input) {
|
|
56
52
|
const executionKind = getBindingExecutionKind(input.binding);
|
|
@@ -61,17 +57,29 @@ export function buildLangChainCreateParams(input) {
|
|
|
61
57
|
const upstreamParams = buildUpstreamCreateBaseParams(input.binding, [
|
|
62
58
|
"model",
|
|
63
59
|
"tools",
|
|
60
|
+
"systemPrompt",
|
|
61
|
+
"stateSchema",
|
|
62
|
+
"contextSchema",
|
|
63
|
+
"checkpointer",
|
|
64
|
+
"store",
|
|
65
|
+
"responseFormat",
|
|
64
66
|
"middleware",
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"skills",
|
|
70
|
-
"generalPurposeAgent",
|
|
71
|
-
"taskDescription",
|
|
67
|
+
"name",
|
|
68
|
+
"description",
|
|
69
|
+
"includeAgentName",
|
|
70
|
+
"version",
|
|
72
71
|
]);
|
|
72
|
+
const legacyPassthrough = typeof input.binding.langchainAgentParams?.passthrough === "object" &&
|
|
73
|
+
input.binding.langchainAgentParams?.passthrough
|
|
74
|
+
? input.binding.langchainAgentParams.passthrough
|
|
75
|
+
: undefined;
|
|
76
|
+
const langchainPassthrough = typeof input.binding.harnessRuntime.langchain?.passthrough === "object" && input.binding.harnessRuntime.langchain?.passthrough
|
|
77
|
+
? input.binding.harnessRuntime.langchain.passthrough
|
|
78
|
+
: undefined;
|
|
73
79
|
return {
|
|
74
80
|
...upstreamParams,
|
|
81
|
+
...(legacyPassthrough ?? {}),
|
|
82
|
+
...(langchainPassthrough ?? {}),
|
|
75
83
|
...(input.passthroughOverride ?? {}),
|
|
76
84
|
systemPrompt: input.systemPromptOverride ?? executionParams.systemPrompt,
|
|
77
85
|
model: input.resolvedModel,
|
|
@@ -89,16 +97,18 @@ export function buildDeepAgentCreateParams(input) {
|
|
|
89
97
|
const upstreamParams = buildUpstreamCreateBaseParams(input.binding, [
|
|
90
98
|
"model",
|
|
91
99
|
"tools",
|
|
100
|
+
"systemPrompt",
|
|
92
101
|
"middleware",
|
|
93
102
|
"subagents",
|
|
103
|
+
"responseFormat",
|
|
104
|
+
"contextSchema",
|
|
105
|
+
"checkpointer",
|
|
106
|
+
"store",
|
|
107
|
+
"backend",
|
|
94
108
|
"interruptOn",
|
|
109
|
+
"name",
|
|
110
|
+
"memory",
|
|
95
111
|
"skills",
|
|
96
|
-
"backend",
|
|
97
|
-
"store",
|
|
98
|
-
// These do not belong to DeepAgents top-level create params even if
|
|
99
|
-
// compatibility fixtures stuff them into compiled deepagent params.
|
|
100
|
-
"generalPurposeAgent",
|
|
101
|
-
"taskDescription",
|
|
102
112
|
]);
|
|
103
113
|
return {
|
|
104
114
|
...upstreamParams,
|
|
@@ -255,18 +265,18 @@ export class AgentRuntimeAdapter {
|
|
|
255
265
|
invokeBuiltinTaskTool: assembly.invokeBuiltinTaskTool,
|
|
256
266
|
});
|
|
257
267
|
}
|
|
258
|
-
async
|
|
268
|
+
async materializeAutomaticSummarizationMiddleware(binding) {
|
|
259
269
|
const assembly = this.createAssemblyResolvers(binding);
|
|
260
|
-
return
|
|
270
|
+
return materializeAutomaticSummarizationMiddlewareHelper({
|
|
261
271
|
binding,
|
|
262
272
|
createDeclaredMiddlewareResolverOptions: assembly.createDeclaredMiddlewareResolverOptions,
|
|
263
273
|
});
|
|
264
274
|
}
|
|
265
|
-
async
|
|
275
|
+
async resolveLangChainRuntimeExtensionMiddleware(binding) {
|
|
266
276
|
const assembly = this.createAssemblyResolvers(binding);
|
|
267
|
-
return
|
|
277
|
+
return resolveLangChainRuntimeExtensionMiddlewareHelper({
|
|
268
278
|
binding,
|
|
269
|
-
|
|
279
|
+
materializeAutomaticSummarizationMiddleware: (currentBinding) => this.materializeAutomaticSummarizationMiddleware(currentBinding),
|
|
270
280
|
resolveFilesystemBackend: assembly.resolveFilesystemBackend,
|
|
271
281
|
resolveModel: assembly.resolveModel,
|
|
272
282
|
resolveTools: assembly.resolveTools,
|
|
@@ -280,7 +290,7 @@ export class AgentRuntimeAdapter {
|
|
|
280
290
|
interruptOn,
|
|
281
291
|
runtimeAdapterOptions: this.options,
|
|
282
292
|
createDeclaredMiddlewareResolverOptions: assembly.createDeclaredMiddlewareResolverOptions,
|
|
283
|
-
|
|
293
|
+
resolveLangChainRuntimeExtensionMiddleware: (currentBinding) => this.resolveLangChainRuntimeExtensionMiddleware(currentBinding),
|
|
284
294
|
});
|
|
285
295
|
}
|
|
286
296
|
async resolveSubagents(subagents, binding) {
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { type MessageContent, type ThreadSummary, type WorkspaceBundle } from "../../../contracts/types.js";
|
|
2
2
|
import type { RoutingRule } from "../../../workspace/support/workspace-ref-utils.js";
|
|
3
3
|
export declare function getDefaultHostAgentId(workspace: WorkspaceBundle, preferredHostAgentId?: string): string;
|
|
4
|
+
export declare function getDefaultRuntimeEntryAgentId(workspace: WorkspaceBundle, preferredRuntimeEntryAgentId?: string): string;
|
|
4
5
|
export declare function resolveSelectedAgentId(options: {
|
|
5
6
|
workspace: WorkspaceBundle;
|
|
6
7
|
input: MessageContent;
|
|
7
8
|
requestedAgentId?: string;
|
|
8
9
|
threadId?: string;
|
|
9
10
|
preferredHostAgentId?: string;
|
|
11
|
+
preferredRuntimeEntryAgentId?: string;
|
|
10
12
|
getThreadSummary: (threadId: string) => Promise<ThreadSummary | null>;
|
|
11
13
|
}): Promise<string>;
|
|
12
14
|
export declare function routeAgentId(options: {
|