@botbotgo/agent-harness 0.0.361 → 0.0.363

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.
@@ -362,17 +362,32 @@ export async function invokeBuiltinTaskTool(input) {
362
362
  const typedInput = isRecord(input.toolInput) ? input.toolInput : {};
363
363
  const description = typeof typedInput.description === "string"
364
364
  ? typedInput.description
365
- : "";
365
+ : typeof typedInput.instruction === "string"
366
+ ? typedInput.instruction
367
+ : typeof typedInput.task === "string"
368
+ ? typedInput.task
369
+ : typeof typedInput.prompt === "string"
370
+ ? typedInput.prompt
371
+ : "";
366
372
  const subagentType = typeof typedInput.subagent_type === "string"
367
373
  ? typedInput.subagent_type
368
- : "";
374
+ : typeof typedInput.agentId === "string"
375
+ ? typedInput.agentId
376
+ : typeof typedInput.agent_id === "string"
377
+ ? typedInput.agent_id
378
+ : typeof typedInput.subagent === "string"
379
+ ? typedInput.subagent
380
+ : "";
369
381
  const builtinBackend = input.resolveBuiltinMiddlewareBackend(input.binding, input.options);
370
382
  const resolvedSubagents = await input.resolveSubagents(compiledSubagents, input.binding);
371
383
  const selectedSubagent = resolvedSubagents.find((subagent) => subagent.name === subagentType);
372
384
  const selectedCompiledSubagent = compiledSubagents.find((subagent) => subagent.name === subagentType);
373
385
  if (!selectedSubagent) {
374
386
  const allowed = resolvedSubagents.map((subagent) => subagent.name);
375
- throw new Error(`Error: invoked agent of type ${subagentType}, the only allowed types are ${allowed.map((name) => `\`${name}\``).join(", ")}`);
387
+ const available = resolvedSubagents
388
+ .map((subagent) => `- ${subagent.name}: ${subagent.description}`)
389
+ .join("\n");
390
+ throw new Error(`Error: invoked agent of type ${subagentType}, the only allowed types are ${allowed.map((name) => `\`${name}\``).join(", ")}.${available ? `\nAvailable subagents:\n${available}` : ""}`);
376
391
  }
377
392
  const resolvedHostModel = selectedSubagent.model ? undefined : await input.resolveModel(primaryModel);
378
393
  const summarizationModel = selectedSubagent.model ?? resolvedHostModel;
@@ -446,8 +461,15 @@ export async function resolveBuiltinMiddlewareTools(input) {
446
461
  ...(input.binding.agent.asyncSubagents ?? []),
447
462
  ];
448
463
  const includeTaskTool = configuredSubagents.length > 0;
464
+ const taskSubagents = getBindingDeepAgentSubagents(input.binding)
465
+ .filter((subagent) => !("graphId" in subagent))
466
+ .map((subagent) => ({
467
+ name: subagent.name,
468
+ description: subagent.description,
469
+ }));
449
470
  const tools = (await createBuiltinMiddlewareTools(backend, {
450
471
  includeTaskTool,
472
+ taskSubagents,
451
473
  workspaceRoot: input.binding.harnessRuntime.workspaceRoot,
452
474
  toolRuntimeContext: input.options?.toolRuntimeContext,
453
475
  invokeTaskTool: includeTaskTool
@@ -188,6 +188,10 @@ export type BuiltinExecutableTool = {
188
188
  schema: unknown;
189
189
  invoke: (input: unknown, config?: Record<string, unknown>) => Promise<unknown>;
190
190
  };
191
+ export type BuiltinTaskSubagentDescriptor = {
192
+ name: string;
193
+ description: string;
194
+ };
191
195
  export declare const BUILTIN_MIDDLEWARE_TOOL_DESCRIPTORS: readonly [{
192
196
  readonly name: "write_todos";
193
197
  readonly description: "Create and update the runtime todo board for multi-step work.";
@@ -254,6 +258,7 @@ export declare function filterBuiltinMiddlewareToolDescriptors(options?: {
254
258
  export declare function createBuiltinMiddlewareTools(backend: BuiltinMiddlewareBackend, options: {
255
259
  includeTaskTool: boolean;
256
260
  invokeTaskTool?: (input: unknown) => Promise<unknown>;
261
+ taskSubagents?: BuiltinTaskSubagentDescriptor[];
257
262
  workspaceRoot?: string;
258
263
  toolRuntimeContext?: Record<string, unknown>;
259
264
  }): Promise<Map<string, BuiltinExecutableTool>>;
@@ -4,10 +4,33 @@ import { isSandboxBackend } from "deepagents";
4
4
  import { isRecord } from "../../../utils/object.js";
5
5
  import { formatBuiltinTodoSnapshot, isLowSignalTodoContent, summarizeBuiltinWriteTodosArgs, truncateLines } from "../runtime-adapter-support.js";
6
6
  import { maybePersistLargeToolOutput, resolveToolRuntimeContext } from "./tool-output-artifacts.js";
7
- const taskToolSchema = z.object({
8
- description: z.string(),
9
- subagent_type: z.string(),
10
- }).passthrough();
7
+ function buildTaskToolDescription(subagents) {
8
+ const lines = [
9
+ "Delegate a bounded task to the subagent whose declared description best matches the task.",
10
+ "Use this only when a subagent is a better fit than the current agent. Set subagent_type to exactly one listed subagent name.",
11
+ ];
12
+ const available = (subagents ?? [])
13
+ .filter((subagent) => subagent.name.trim().length > 0)
14
+ .map((subagent) => {
15
+ const description = subagent.description.trim() || "No description provided.";
16
+ return `- ${subagent.name}: ${description}`;
17
+ });
18
+ return available.length > 0
19
+ ? [...lines, "", "Available subagents:", ...available].join("\n")
20
+ : lines.join(" ");
21
+ }
22
+ function buildTaskToolSchema(subagents) {
23
+ const names = (subagents ?? [])
24
+ .map((subagent) => subagent.name.trim())
25
+ .filter((name) => name.length > 0);
26
+ const subagentTypeSchema = names.length > 0
27
+ ? z.enum(names)
28
+ : z.string();
29
+ return z.object({
30
+ description: z.string().describe("Concrete bounded task for the selected subagent to perform."),
31
+ subagent_type: subagentTypeSchema.describe("Exact name of the selected subagent."),
32
+ }).passthrough();
33
+ }
11
34
  export const BUILTIN_MIDDLEWARE_TOOL_DESCRIPTORS = [
12
35
  { name: "write_todos", description: "Create and update the runtime todo board for multi-step work." },
13
36
  { name: "read_todos", description: "Read the current runtime todo board." },
@@ -638,10 +661,11 @@ export async function createBuiltinMiddlewareTools(backend, options) {
638
661
  },
639
662
  });
640
663
  if (options.includeTaskTool && options.invokeTaskTool) {
664
+ const description = buildTaskToolDescription(options.taskSubagents);
641
665
  tools.set("task", {
642
666
  name: "task",
643
- description: "Delegate a bounded task to a subagent.",
644
- schema: taskToolSchema,
667
+ description,
668
+ schema: buildTaskToolSchema(options.taskSubagents),
645
669
  invoke: async (input) => options.invokeTaskTool(input),
646
670
  });
647
671
  }
@@ -58,6 +58,7 @@ export declare class AgentRuntimeAdapter {
58
58
  memoryContext?: string;
59
59
  }): Promise<RequestResult>;
60
60
  private tryDelegateWithCompactRouter;
61
+ private buildCompactDelegationReport;
61
62
  stream(binding: CompiledAgentBinding, input: MessageContent, sessionId: string, history?: TranscriptMessage[], options?: {
62
63
  context?: Record<string, unknown>;
63
64
  state?: Record<string, unknown>;
@@ -112,6 +112,15 @@ function parseCompactRouterSelection(value, subagentNames) {
112
112
  if (subagentNames.has(trimmed)) {
113
113
  return { subagentType: trimmed };
114
114
  }
115
+ const lowered = trimmed.toLowerCase();
116
+ const relaxedMatch = Array.from(subagentNames).find((name) => {
117
+ const lowerName = name.toLowerCase();
118
+ return lowerName.length > 0
119
+ && (trimmed === name || lowered.includes(lowerName));
120
+ });
121
+ if (relaxedMatch) {
122
+ return { subagentType: relaxedMatch };
123
+ }
115
124
  const parsed = parseFirstJsonObject(trimmed);
116
125
  const toolCall = salvageJsonToolCalls(trimmed).at(0);
117
126
  const payload = typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)
@@ -333,6 +342,9 @@ export class AgentRuntimeAdapter {
333
342
  };
334
343
  }
335
344
  async tryHandleDirectWorkspaceListing(binding, input, options = {}) {
345
+ if (binding.agent.executionMode !== "deepagent") {
346
+ return undefined;
347
+ }
336
348
  if (!shouldDirectlyListWorkspaceFiles(input)) {
337
349
  return undefined;
338
350
  }
@@ -714,9 +726,10 @@ export class AgentRuntimeAdapter {
714
726
  requestId,
715
727
  });
716
728
  if (compactDelegation) {
717
- const output = typeof compactDelegation.toolOutput === "string"
729
+ const compactReport = this.buildCompactDelegationReport(compactDelegation);
730
+ const output = JSON.stringify(compactDelegation.delegatedSubagentType === null
718
731
  ? compactDelegation.toolOutput
719
- : JSON.stringify(compactDelegation.toolOutput);
732
+ : compactReport);
720
733
  const delegatedToolResults = Array.isArray(compactDelegation.delegatedResult?.metadata?.executedToolResults)
721
734
  ? compactDelegation.delegatedResult.metadata.executedToolResults
722
735
  : [];
@@ -813,10 +826,13 @@ export class AgentRuntimeAdapter {
813
826
  const subagentCatalog = subagents
814
827
  .map((subagent) => `- ${subagent.name}: ${subagent.description}`)
815
828
  .join("\n");
829
+ const routingPolicy = getBindingSystemPrompt(binding);
816
830
  const prompt = [
817
831
  primaryModel.init?.think === false ? "/no_think" : "",
818
832
  "You are selecting a subagent for a delegation-only agent.",
819
833
  "Choose exactly one listed subagent when it can responsibly handle the request.",
834
+ routingPolicy ? "Agent routing policy:" : "",
835
+ routingPolicy ?? "",
820
836
  "Return only JSON with this shape:",
821
837
  "{\"subagent_type\":\"<listed subagent name>\"}",
822
838
  "If no listed subagent can handle the request, return only:",
@@ -881,6 +897,7 @@ export class AgentRuntimeAdapter {
881
897
  if (selection?.refusedReason) {
882
898
  return {
883
899
  toolOutput: selection.refusedReason,
900
+ delegatedSubagentType: null,
884
901
  delegatedResult: {
885
902
  sessionId,
886
903
  requestId,
@@ -891,7 +908,16 @@ export class AgentRuntimeAdapter {
891
908
  },
892
909
  };
893
910
  }
894
- const subagentType = selection?.subagentType ?? "";
911
+ let subagentType = selection?.subagentType ?? "";
912
+ if (!subagentNames.has(subagentType)) {
913
+ const fallbackSubagent = subagentNames.values().next().value;
914
+ if (typeof fallbackSubagent === "string" && fallbackSubagent) {
915
+ subagentType = fallbackSubagent;
916
+ }
917
+ else {
918
+ return null;
919
+ }
920
+ }
895
921
  if (!subagentNames.has(subagentType)) {
896
922
  return null;
897
923
  }
@@ -905,15 +931,49 @@ export class AgentRuntimeAdapter {
905
931
  files: options.files,
906
932
  memoryContext: options.memoryContext,
907
933
  });
908
- let delegatedResult = await runDelegatedRequest(requestText);
934
+ let delegatedResult;
935
+ try {
936
+ delegatedResult = await runDelegatedRequest(requestText);
937
+ }
938
+ catch (error) {
939
+ const output = error instanceof Error ? error.message : String(error);
940
+ return {
941
+ toolOutput: output,
942
+ delegatedSubagentType: subagentType,
943
+ delegatedResult: {
944
+ sessionId,
945
+ requestId,
946
+ agentId: selectedBinding.agent.id,
947
+ state: "failed",
948
+ output,
949
+ finalMessageText: output,
950
+ },
951
+ };
952
+ }
909
953
  const targetRequiresExecutionToolEvidence = getBindingPrimaryTools(selectedBinding).length > 0;
910
954
  if (targetRequiresExecutionToolEvidence && !hasDelegatedExecutionToolEvidence(delegatedResult)) {
911
- delegatedResult = await runDelegatedRequest([requestText, EXECUTION_WITH_TOOL_EVIDENCE_RETRY_INSTRUCTION].filter(Boolean).join("\n\n"), ":tool-evidence-retry");
955
+ try {
956
+ delegatedResult = await runDelegatedRequest([requestText, EXECUTION_WITH_TOOL_EVIDENCE_RETRY_INSTRUCTION].filter(Boolean).join("\n\n"), ":tool-evidence-retry");
957
+ }
958
+ catch (error) {
959
+ const output = error instanceof Error ? error.message : String(error);
960
+ return {
961
+ toolOutput: output,
962
+ delegatedSubagentType: subagentType,
963
+ delegatedResult: {
964
+ ...delegatedResult,
965
+ state: "failed",
966
+ output,
967
+ finalMessageText: output,
968
+ },
969
+ };
970
+ }
912
971
  }
913
972
  if (targetRequiresExecutionToolEvidence && !hasDelegatedExecutionToolEvidence(delegatedResult)) {
914
973
  const output = `runtime_error=Delegated agent ${selectedBinding.agent.id} completed without tool execution evidence.`;
915
974
  return {
916
975
  toolOutput: output,
976
+ delegatedSubagentType: subagentType,
917
977
  delegatedResult: {
918
978
  ...delegatedResult,
919
979
  state: "failed",
@@ -928,6 +988,7 @@ export class AgentRuntimeAdapter {
928
988
  const output = "runtime_error=Delegated agent ended before producing required plan evidence.";
929
989
  return {
930
990
  toolOutput: output,
991
+ delegatedSubagentType: subagentType,
931
992
  delegatedResult: {
932
993
  ...delegatedResult,
933
994
  state: "failed",
@@ -936,7 +997,48 @@ export class AgentRuntimeAdapter {
936
997
  },
937
998
  };
938
999
  }
939
- return { toolOutput: resolveDelegatedResultOutput(delegatedResult), delegatedResult };
1000
+ return {
1001
+ toolOutput: resolveDelegatedResultOutput(delegatedResult),
1002
+ delegatedSubagentType: subagentType,
1003
+ delegatedResult,
1004
+ };
1005
+ }
1006
+ buildCompactDelegationReport(compactDelegation) {
1007
+ const delegatedSubagentType = compactDelegation.delegatedSubagentType ?? "unknown";
1008
+ const delegatedOutput = typeof compactDelegation.toolOutput === "string"
1009
+ ? [compactDelegation.toolOutput]
1010
+ : [];
1011
+ const delegatedToolNames = Array.isArray(compactDelegation.delegatedResult?.metadata?.executedToolResults)
1012
+ ? compactDelegation.delegatedResult.metadata.executedToolResults
1013
+ .filter((toolResult) => toolResult?.toolName)
1014
+ .map((toolResult) => toolResult.toolName)
1015
+ : [];
1016
+ const state = compactDelegation.delegatedResult?.state === "failed" ? "failed" : "completed";
1017
+ return {
1018
+ status: state,
1019
+ routing: [
1020
+ `1) 路由判断: 已选择 sub-agent = ${delegatedSubagentType}(基于请求语义)。`,
1021
+ ],
1022
+ plan: [
1023
+ "1) 选择具备匹配能力的子代理并创建委托任务。",
1024
+ "2) 执行子代理的原生工作流并收集委托工具输出。",
1025
+ "3) 合成汇总报告并返回给用户。",
1026
+ ],
1027
+ execution: [
1028
+ `1) 调用 task 工具,目标子代理:${delegatedSubagentType}`,
1029
+ delegatedToolNames.length > 0
1030
+ ? `2) 子代理返回工具证据:${[...new Set(delegatedToolNames)].join(", ")}`
1031
+ : "2) 子代理返回文本结果。",
1032
+ "3) 产出主编排汇总并返回结构化结果。",
1033
+ ],
1034
+ summary: [
1035
+ `已完成子代理 ${delegatedSubagentType} 委托执行。`,
1036
+ ],
1037
+ findings: delegatedOutput.length > 0 ? delegatedOutput.slice(0, 3) : ["none"],
1038
+ blockers: state === "failed" ? ["子代理执行未能完成。"] : ["none"],
1039
+ nextActions: ["如需更深入,可继续追问该次委托的细节。"],
1040
+ report: delegatedOutput.join("\n") || "委托已完成,未返回附加报告。",
1041
+ };
940
1042
  }
941
1043
  async *stream(binding, input, sessionId, history = [], options = {}) {
942
1044
  const directListing = await this.tryHandleDirectWorkspaceListing(binding, input, {
@@ -968,25 +1070,17 @@ export class AgentRuntimeAdapter {
968
1070
  requestId: options.requestId,
969
1071
  });
970
1072
  if (compactDelegation) {
971
- const delegatedToolResults = selectDelegatedToolResultsForVisibleProgress(compactDelegation.delegatedResult);
1073
+ const compactReport = this.buildCompactDelegationReport(compactDelegation);
972
1074
  yield {
973
1075
  kind: "tool-result",
974
1076
  toolName: "task",
975
1077
  output: compactDelegation.toolOutput,
976
1078
  };
977
- for (const toolResult of delegatedToolResults) {
978
- yield {
979
- kind: "tool-result",
980
- toolName: toolResult.toolName,
981
- output: toolResult.output,
982
- isError: toolResult.isError,
983
- };
984
- }
985
1079
  yield {
986
1080
  kind: "content",
987
- content: typeof compactDelegation.toolOutput === "string"
1081
+ content: JSON.stringify(compactDelegation.delegatedSubagentType === null
988
1082
  ? compactDelegation.toolOutput
989
- : JSON.stringify(compactDelegation.toolOutput),
1083
+ : compactReport),
990
1084
  };
991
1085
  return;
992
1086
  }
@@ -1,5 +1,5 @@
1
1
  import { createFallbackRequestResultFromLatestEvent, mergeRequestResultOutput } from "../run/helpers.js";
2
- import { applyRequestStreamItemToSnapshot, createInitialRequestEventSnapshot, toRequestDataEvent, } from "../../../projections/request-events.js";
2
+ import { applyRequestStreamItemToSnapshot, createInitialRequestEventSnapshot, toRequestDataEvents, } from "../../../projections/request-events.js";
3
3
  export async function emitOutputDeltaAndCreateItem(emit, sessionId, requestId, agentId, content) {
4
4
  await emit(sessionId, requestId, 3, "output.delta", {
5
5
  content,
@@ -71,8 +71,7 @@ export async function dispatchRequestListeners(stream, listeners, options) {
71
71
  else if (item.type === "content") {
72
72
  output += item.content;
73
73
  }
74
- const dataEvent = toRequestDataEvent(item);
75
- if (dataEvent) {
74
+ for (const dataEvent of toRequestDataEvents(item)) {
76
75
  await notifyIfPresent(listeners.dataListener, dataEvent);
77
76
  }
78
77
  await notifyIfPresent(listeners.eventListener, snapshot);
@@ -5,7 +5,7 @@ import { compileModel, compileTool } from "./resource-compilers.js";
5
5
  import { inferAgentCapabilities } from "./support/agent-capabilities.js";
6
6
  import { getAgentExecutionConfigValue, getAgentExecutionObject, getAgentExecutionString } from "./support/agent-execution-config.js";
7
7
  import { discoverSkillPaths } from "./support/discovery.js";
8
- import { compileAgentMemories, getProceduralMemoryDefaults, getResilienceConfig, getRuntimeDefaults, getRuntimeMemoryDefaults, getRuntimeStorageRoots, getWorkspaceObject, resolvePromptValue, resolveRefId, } from "./support/workspace-ref-utils.js";
8
+ import { compileAgentMemories, getProceduralMemoryDefaults, getResilienceConfig, getRuntimeAgentDefaults, getRuntimeDefaults, getRuntimeMemoryDefaults, getRuntimeStorageRoots, getWorkspaceObject, resolvePromptValue, resolveRefId, } from "./support/workspace-ref-utils.js";
9
9
  import { WORKSPACE_BOUNDARY_GUIDANCE } from "../runtime/prompts/runtime-prompts.js";
10
10
  function requireSkills(pathEntries, workspaceRoot) {
11
11
  return Array.from(new Set(discoverSkillPaths(pathEntries, workspaceRoot)));
@@ -166,8 +166,8 @@ export function requireTools(tools, bindings, ownerId) {
166
166
  }
167
167
  return Array.from(deduped.values());
168
168
  }
169
- function buildSubagent(agent, workspaceRoot, models, tools, parentSkills, parentModel) {
170
- const execution = compileExecutionCore(agent, workspaceRoot, models, tools);
169
+ function buildSubagent(agent, workspaceRoot, refs, models, tools, parentSkills, parentModel) {
170
+ const execution = compileExecutionCore(agent, workspaceRoot, refs, models, tools);
171
171
  return {
172
172
  agentId: agent.id,
173
173
  name: resolveAgentRuntimeName(agent),
@@ -196,6 +196,84 @@ function resolveInterruptOn(agent) {
196
196
  function resolveResponseFormat(agent) {
197
197
  return getAgentExecutionConfigValue(agent, "responseFormat");
198
198
  }
199
+ function normalizeResponseFormatRef(ref) {
200
+ return ref.startsWith("response-format/") ? ref : `response-format/${ref}`;
201
+ }
202
+ function resolveResponseFormatObject(refs, ref, ownerLabel) {
203
+ if (!ref) {
204
+ return undefined;
205
+ }
206
+ const object = getWorkspaceObject(refs, normalizeResponseFormatRef(ref));
207
+ if (!object) {
208
+ throw new Error(`${ownerLabel} responseFormatRef references missing object ${ref}`);
209
+ }
210
+ if (object.kind !== "response-format") {
211
+ throw new Error(`${ownerLabel} responseFormatRef references ${ref}, but expected response-format`);
212
+ }
213
+ if (!("format" in object.value)) {
214
+ throw new Error(`${ownerLabel} responseFormatRef ${ref} must define format`);
215
+ }
216
+ return object.value.format;
217
+ }
218
+ function mergeResponseFormats(base, override) {
219
+ if (override === undefined) {
220
+ return base;
221
+ }
222
+ if (typeof base === "object" &&
223
+ base &&
224
+ typeof override === "object" &&
225
+ override &&
226
+ !Array.isArray(base) &&
227
+ !Array.isArray(override)) {
228
+ const merged = { ...base };
229
+ for (const [key, value] of Object.entries(override)) {
230
+ if (key === "required" && Array.isArray(merged.required) && Array.isArray(value)) {
231
+ merged.required = Array.from(new Set([...merged.required, ...value]));
232
+ continue;
233
+ }
234
+ if (key === "properties" &&
235
+ typeof merged.properties === "object" &&
236
+ merged.properties &&
237
+ !Array.isArray(merged.properties) &&
238
+ typeof value === "object" &&
239
+ value &&
240
+ !Array.isArray(value)) {
241
+ merged.properties = {
242
+ ...merged.properties,
243
+ ...value,
244
+ };
245
+ continue;
246
+ }
247
+ merged[key] = key in merged ? mergeResponseFormats(merged[key], value) : value;
248
+ }
249
+ return merged;
250
+ }
251
+ return override;
252
+ }
253
+ function resolveInheritedResponseFormat(agent, refs) {
254
+ const defaults = getRuntimeAgentDefaults(refs);
255
+ if (defaults && "responseFormat" in defaults) {
256
+ return defaults.responseFormat === null ? undefined : defaults.responseFormat;
257
+ }
258
+ const defaultRef = typeof defaults?.responseFormatRef === "string" ? defaults.responseFormatRef.trim() : "";
259
+ if (defaultRef) {
260
+ return resolveResponseFormatObject(refs, defaultRef, "Runtime defaults.agent.config");
261
+ }
262
+ return undefined;
263
+ }
264
+ function resolveEffectiveResponseFormat(agent, refs) {
265
+ const explicitResponseFormat = resolveResponseFormat(agent);
266
+ if (explicitResponseFormat !== undefined) {
267
+ return explicitResponseFormat === null
268
+ ? undefined
269
+ : mergeResponseFormats(resolveInheritedResponseFormat(agent, refs), explicitResponseFormat);
270
+ }
271
+ const explicitRef = getAgentExecutionConfigValue(agent, "responseFormatRef");
272
+ if (typeof explicitRef === "string" && explicitRef.trim().length > 0) {
273
+ return resolveResponseFormatObject(refs, explicitRef.trim(), `Agent ${agent.id}`);
274
+ }
275
+ return resolveInheritedResponseFormat(agent, refs);
276
+ }
199
277
  function resolveContextSchema(agent) {
200
278
  return getAgentExecutionConfigValue(agent, "contextSchema");
201
279
  }
@@ -216,13 +294,13 @@ function resolvePassthrough(agent) {
216
294
  const passthrough = getAgentExecutionObject(agent, "passthrough");
217
295
  return passthrough ? { ...passthrough } : undefined;
218
296
  }
219
- function compileSubagents(agent, agents, workspaceRoot, models, tools, compiledAgentSkills, compiledAgentModel) {
297
+ function compileSubagents(agent, agents, workspaceRoot, refs, models, tools, compiledAgentSkills, compiledAgentModel) {
220
298
  return agent.subagentRefs.map((ref) => {
221
299
  const subagent = agents.get(resolveRefId(ref));
222
300
  if (!subagent) {
223
301
  throw new Error(`Missing subagent ${ref} for agent ${agent.id}`);
224
302
  }
225
- return buildSubagent(subagent, workspaceRoot, models, tools, compiledAgentSkills, compiledAgentModel);
303
+ return buildSubagent(subagent, workspaceRoot, refs, models, tools, compiledAgentSkills, compiledAgentModel);
226
304
  });
227
305
  }
228
306
  function compileAsyncSubagents(agent) {
@@ -234,18 +312,18 @@ function compileAsyncSubagents(agent) {
234
312
  ...(subagent.headers ? { headers: { ...subagent.headers } } : {}),
235
313
  }));
236
314
  }
237
- function compileDeepAgentSubagents(agent, agents, workspaceRoot, models, tools, compiledAgentSkills, compiledAgentModel) {
315
+ function compileDeepAgentSubagents(agent, agents, workspaceRoot, refs, models, tools, compiledAgentSkills, compiledAgentModel) {
238
316
  return [
239
- ...compileSubagents(agent, agents, workspaceRoot, models, tools, compiledAgentSkills, compiledAgentModel),
317
+ ...compileSubagents(agent, agents, workspaceRoot, refs, models, tools, compiledAgentSkills, compiledAgentModel),
240
318
  ...compileAsyncSubagents(agent),
241
319
  ];
242
320
  }
243
- function compileExecutionCore(agent, workspaceRoot, models, tools) {
321
+ function compileExecutionCore(agent, workspaceRoot, refs, models, tools) {
244
322
  return {
245
323
  model: requireModel(models, agent.modelRef, agent.id),
246
324
  tools: requireTools(tools, getAgentToolBindings(agent), agent.id),
247
325
  systemPrompt: resolveSystemPrompt(agent, workspaceRoot),
248
- responseFormat: resolveResponseFormat(agent),
326
+ responseFormat: resolveEffectiveResponseFormat(agent, refs),
249
327
  contextSchema: resolveContextSchema(agent),
250
328
  middleware: resolveCompiledMiddleware(agent, models),
251
329
  };
@@ -395,7 +473,7 @@ export function compileBinding(workspaceRoot, agent, agents, referencedSubagentI
395
473
  const executionCore = compileExecutionCore({
396
474
  ...agent,
397
475
  modelRef: agent.modelRef || (internalSubagent ? "model/default" : ""),
398
- }, workspaceRoot, models, tools);
476
+ }, workspaceRoot, refs, models, tools);
399
477
  const passthrough = resolvePassthrough(agent);
400
478
  const compiledAgentModel = executionCore.model;
401
479
  const backend = resolveBackendConfig(agent, refs);
@@ -442,7 +520,7 @@ export function compileBinding(workspaceRoot, agent, agents, referencedSubagentI
442
520
  passthrough,
443
521
  interruptOn: resolveInterruptOn(agent),
444
522
  filesystem: compiledFilesystemConfig,
445
- subagents: compileSubagents(agent, agents, workspaceRoot, models, tools, compiledAgentSkills, compiledAgentModel),
523
+ subagents: compileSubagents(agent, agents, workspaceRoot, refs, models, tools, compiledAgentSkills, compiledAgentModel),
446
524
  memory: compiledAgentMemory,
447
525
  skills: compiledAgentSkills,
448
526
  generalPurposeAgent: getAgentExecutionConfigValue(agent, "generalPurposeAgent", { executionMode: "langchain-v1" }),
@@ -491,7 +569,7 @@ export function compileBinding(workspaceRoot, agent, agents, referencedSubagentI
491
569
  responseFormat: executionCore.responseFormat,
492
570
  contextSchema: executionCore.contextSchema,
493
571
  middleware: executionCore.middleware,
494
- subagents: compileDeepAgentSubagents(agent, agents, workspaceRoot, models, tools, compiledAgentSkills, compiledAgentModel),
572
+ subagents: compileDeepAgentSubagents(agent, agents, workspaceRoot, refs, models, tools, compiledAgentSkills, compiledAgentModel),
495
573
  interruptOn: resolveInterruptOn(agent),
496
574
  ...(backend ? { backend: backend.config } : {}),
497
575
  ...(store ? { store: store.config } : {}),
@@ -425,6 +425,7 @@ export async function loadWorkspace(workspaceRoot, options = {}) {
425
425
  tools,
426
426
  skillRegistry,
427
427
  ownedRoots: contractOwnedRoots,
428
+ refs: loaded.refs,
428
429
  mode: frameworkContractValidation,
429
430
  });
430
431
  }, {
@@ -1,4 +1,4 @@
1
- import type { ParsedAgentObject, ParsedToolObject } from "../contracts/types.js";
1
+ import type { ParsedAgentObject, ParsedToolObject, WorkspaceObject } from "../contracts/types.js";
2
2
  export type FrameworkContractValidationMode = "off" | "warn" | "error";
3
3
  export declare function resolveFrameworkContractValidationMode(mode: FrameworkContractValidationMode | undefined): FrameworkContractValidationMode;
4
4
  export declare function validateFrameworkContracts(input: {
@@ -6,5 +6,6 @@ export declare function validateFrameworkContracts(input: {
6
6
  tools: Map<string, ParsedToolObject>;
7
7
  skillRegistry: Map<string, string>;
8
8
  ownedRoots: string[];
9
+ refs?: Map<string, WorkspaceObject | ParsedAgentObject>;
9
10
  mode?: FrameworkContractValidationMode;
10
11
  }): void;