@botbotgo/agent-harness 0.0.298 → 0.0.299

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.
Files changed (166) hide show
  1. package/README.md +77 -37
  2. package/README.zh.md +79 -30
  3. package/dist/acp.d.ts +3 -0
  4. package/dist/acp.js +10 -2
  5. package/dist/api.d.ts +14 -2
  6. package/dist/api.js +19 -3
  7. package/dist/cli.d.ts +18 -1
  8. package/dist/cli.js +1408 -319
  9. package/dist/client/acp.d.ts +9 -3
  10. package/dist/client/acp.js +55 -1
  11. package/dist/client/in-process.d.ts +5 -2
  12. package/dist/client/in-process.js +4 -6
  13. package/dist/client/index.d.ts +1 -1
  14. package/dist/client/types.d.ts +6 -5
  15. package/dist/config/agents/direct.yaml +7 -17
  16. package/dist/config/agents/orchestra.yaml +9 -65
  17. package/dist/config/catalogs/embedding-models.yaml +1 -1
  18. package/dist/config/catalogs/stores.yaml +1 -1
  19. package/dist/config/knowledge/knowledge-runtime.yaml +36 -2
  20. package/dist/config/knowledge/procedural-memory-runtime.yaml +78 -0
  21. package/dist/config/{catalogs/models.yaml → models.yaml} +2 -2
  22. package/dist/config/prompts/direct-system.md +16 -0
  23. package/dist/config/prompts/orchestra-system.md +62 -0
  24. package/dist/config/prompts/routing-system.md +14 -0
  25. package/dist/config/runtime/runtime-memory.yaml +39 -5
  26. package/dist/config/runtime/workspace.yaml +7 -16
  27. package/dist/contracts/runtime.d.ts +242 -1
  28. package/dist/contracts/workspace.d.ts +2 -0
  29. package/dist/index.d.ts +5 -3
  30. package/dist/index.js +2 -1
  31. package/dist/init-project.js +178 -33
  32. package/dist/knowledge/contracts.d.ts +5 -0
  33. package/dist/knowledge/module.d.ts +5 -0
  34. package/dist/knowledge/module.js +340 -18
  35. package/dist/package-version.d.ts +1 -1
  36. package/dist/package-version.js +1 -1
  37. package/dist/persistence/file-store.d.ts +5 -1
  38. package/dist/persistence/file-store.js +16 -0
  39. package/dist/persistence/sqlite-store.d.ts +4 -1
  40. package/dist/persistence/sqlite-store.js +88 -14
  41. package/dist/persistence/types.d.ts +4 -1
  42. package/dist/procedural/config.d.ts +63 -0
  43. package/dist/procedural/config.js +125 -0
  44. package/dist/procedural/index.d.ts +2 -0
  45. package/dist/procedural/index.js +1 -0
  46. package/dist/protocol/ag-ui/http.d.ts +3 -0
  47. package/dist/protocol/ag-ui/http.js +10 -0
  48. package/dist/request-events.d.ts +63 -0
  49. package/dist/request-events.js +400 -0
  50. package/dist/resource/isolation.js +11 -0
  51. package/dist/resource/resource-impl.d.ts +1 -0
  52. package/dist/resource/resource-impl.js +103 -12
  53. package/dist/resources/init-templates/agent-context/deep-research.md +5 -0
  54. package/dist/resources/init-templates/prompts/research-analyst-basic.md +1 -0
  55. package/dist/resources/init-templates/prompts/research-analyst-web-search.md +1 -0
  56. package/dist/resources/init-templates/prompts/research-host-deep-research-basic.md +1 -0
  57. package/dist/resources/init-templates/prompts/research-host-deep-research-web-search.md +1 -0
  58. package/dist/resources/init-templates/prompts/research-host-single-agent-basic.md +1 -0
  59. package/dist/resources/init-templates/prompts/research-host-single-agent-web-search.md +1 -0
  60. package/dist/resources/prompts/runtime/browser-capability-disclaimer-recovery.md +1 -0
  61. package/dist/resources/prompts/runtime/default-subagent.md +2 -0
  62. package/dist/resources/prompts/runtime/durable-memory-context.md +7 -0
  63. package/dist/resources/prompts/runtime/execution-with-tool-evidence-retry.md +1 -0
  64. package/dist/resources/prompts/runtime/execution-with-tool-evidence.md +1 -0
  65. package/dist/resources/prompts/runtime/invalid-tool-selection-recovery.md +1 -0
  66. package/dist/resources/prompts/runtime/memory-manager.md +31 -0
  67. package/dist/resources/prompts/runtime/memory-mutation-reconciliation.md +22 -0
  68. package/dist/resources/prompts/runtime/slash-command-skill.md +6 -0
  69. package/dist/resources/prompts/runtime/strict-tool-json.md +1 -0
  70. package/dist/resources/prompts/runtime/workspace-boundary-guidance.md +3 -0
  71. package/dist/resources/prompts/runtime/workspace-relative-path.md +1 -0
  72. package/dist/resources/prompts/runtime/write-todos-descriptive-content.md +1 -0
  73. package/dist/resources/prompts/runtime/write-todos-full-entry.md +1 -0
  74. package/dist/resources/prompts/runtime/write-todos-non-empty-initial-list.md +1 -0
  75. package/dist/resources/tools/_runtime_tool_helpers.mjs +152 -0
  76. package/dist/resources/tools/cancel_request.mjs +21 -0
  77. package/dist/resources/tools/fetch_url.mjs +23 -0
  78. package/dist/resources/tools/http_request.mjs +30 -0
  79. package/dist/resources/tools/inspect_approvals.mjs +27 -0
  80. package/dist/resources/tools/inspect_artifacts.mjs +21 -0
  81. package/dist/resources/tools/inspect_events.mjs +21 -0
  82. package/dist/resources/tools/inspect_requests.mjs +27 -0
  83. package/dist/resources/tools/inspect_sessions.mjs +21 -0
  84. package/dist/resources/tools/list_files.mjs +27 -0
  85. package/dist/resources/tools/read_artifact.mjs +22 -0
  86. package/dist/resources/tools/request_approval.mjs +27 -0
  87. package/dist/resources/tools/run_command.mjs +21 -0
  88. package/dist/resources/tools/schedule_task.mjs +76 -0
  89. package/dist/resources/tools/search_files.mjs +47 -0
  90. package/dist/resources/tools/send_message.mjs +23 -0
  91. package/dist/runtime/adapter/direct-builtin-utility.d.ts +1 -0
  92. package/dist/runtime/adapter/direct-builtin-utility.js +90 -0
  93. package/dist/runtime/adapter/flow/execution-context.d.ts +1 -1
  94. package/dist/runtime/adapter/flow/execution-context.js +1 -1
  95. package/dist/runtime/adapter/flow/invocation-flow.d.ts +1 -0
  96. package/dist/runtime/adapter/flow/invocation-flow.js +9 -1
  97. package/dist/runtime/adapter/flow/invoke-runtime.d.ts +1 -1
  98. package/dist/runtime/adapter/flow/stream-runtime.d.ts +5 -1
  99. package/dist/runtime/adapter/flow/stream-runtime.js +556 -35
  100. package/dist/runtime/adapter/invocation-result.js +3 -2
  101. package/dist/runtime/adapter/local-tool-invocation.d.ts +1 -1
  102. package/dist/runtime/adapter/local-tool-invocation.js +28 -4
  103. package/dist/runtime/adapter/middleware-assembly.js +3 -1
  104. package/dist/runtime/adapter/model/invocation-request.d.ts +4 -1
  105. package/dist/runtime/adapter/model/invocation-request.js +138 -16
  106. package/dist/runtime/adapter/model/message-assembly.js +2 -6
  107. package/dist/runtime/adapter/model/model-providers.js +103 -5
  108. package/dist/runtime/adapter/resilience.js +17 -2
  109. package/dist/runtime/adapter/runtime-adapter-support.d.ts +11 -7
  110. package/dist/runtime/adapter/runtime-adapter-support.js +39 -5
  111. package/dist/runtime/adapter/tool/builtin-middleware-tools.d.ts +63 -1
  112. package/dist/runtime/adapter/tool/builtin-middleware-tools.js +193 -21
  113. package/dist/runtime/adapter/tool/tool-arguments.d.ts +3 -1
  114. package/dist/runtime/adapter/tool/tool-arguments.js +52 -17
  115. package/dist/runtime/adapter/tool-resolution.d.ts +1 -0
  116. package/dist/runtime/adapter/tool-resolution.js +4 -2
  117. package/dist/runtime/agent-runtime-adapter.d.ts +27 -0
  118. package/dist/runtime/agent-runtime-adapter.js +163 -11
  119. package/dist/runtime/harness/events/event-bus.d.ts +1 -0
  120. package/dist/runtime/harness/events/event-bus.js +3 -0
  121. package/dist/runtime/harness/events/event-sink.d.ts +3 -0
  122. package/dist/runtime/harness/events/event-sink.js +16 -7
  123. package/dist/runtime/harness/events/streaming.d.ts +18 -1
  124. package/dist/runtime/harness/events/streaming.js +23 -10
  125. package/dist/runtime/harness/run/inspection.js +26 -5
  126. package/dist/runtime/harness/run/stream-run.d.ts +13 -4
  127. package/dist/runtime/harness/run/stream-run.js +448 -4
  128. package/dist/runtime/harness/run/surface-semantics.js +7 -34
  129. package/dist/runtime/harness/system/runtime-memory-manager.d.ts +3 -0
  130. package/dist/runtime/harness/system/runtime-memory-manager.js +384 -69
  131. package/dist/runtime/harness/system/runtime-memory-policy.d.ts +20 -1
  132. package/dist/runtime/harness/system/runtime-memory-policy.js +65 -17
  133. package/dist/runtime/harness/system/runtime-memory-records.js +100 -0
  134. package/dist/runtime/harness/system/runtime-memory-sync.js +2 -2
  135. package/dist/runtime/harness/system/store.d.ts +4 -0
  136. package/dist/runtime/harness/system/store.js +153 -0
  137. package/dist/runtime/harness.d.ts +9 -1
  138. package/dist/runtime/harness.js +141 -7
  139. package/dist/runtime/maintenance/sqlite-checkpoint-saver.d.ts +8 -3
  140. package/dist/runtime/maintenance/sqlite-checkpoint-saver.js +152 -53
  141. package/dist/runtime/parsing/output-parsing.d.ts +10 -2
  142. package/dist/runtime/parsing/output-parsing.js +223 -16
  143. package/dist/runtime/parsing/stream-event-parsing.d.ts +7 -0
  144. package/dist/runtime/parsing/stream-event-parsing.js +51 -1
  145. package/dist/runtime/scheduling/system-schedule-manager.d.ts +41 -0
  146. package/dist/runtime/scheduling/system-schedule-manager.js +532 -0
  147. package/dist/runtime/support/embedding-models.d.ts +1 -1
  148. package/dist/runtime/support/embedding-models.js +5 -2
  149. package/dist/runtime/support/runtime-factories.js +1 -1
  150. package/dist/runtime/support/runtime-layout.d.ts +3 -0
  151. package/dist/runtime/support/runtime-layout.js +10 -1
  152. package/dist/runtime/support/runtime-prompts.d.ts +30 -0
  153. package/dist/runtime/support/runtime-prompts.js +55 -0
  154. package/dist/runtime/support/vector-stores.d.ts +1 -1
  155. package/dist/runtime/support/vector-stores.js +5 -2
  156. package/dist/upstream-events.js +8 -7
  157. package/dist/utils/bundled-text.d.ts +3 -0
  158. package/dist/utils/bundled-text.js +25 -0
  159. package/dist/utils/id.js +3 -2
  160. package/dist/workspace/agent-binding-compiler.js +53 -13
  161. package/dist/workspace/object-loader.js +64 -2
  162. package/dist/workspace/support/workspace-ref-utils.d.ts +2 -1
  163. package/dist/workspace/support/workspace-ref-utils.js +24 -5
  164. package/dist/workspace/yaml-object-reader.d.ts +1 -0
  165. package/dist/workspace/yaml-object-reader.js +95 -17
  166. package/package.json +11 -5
@@ -1,12 +1,13 @@
1
1
  import path from "node:path";
2
2
  import { MemorySaver } from "@langchain/langgraph";
3
- import { createDeepAgent, FilesystemBackend, } from "deepagents";
4
- import { createAgent } from "langchain";
3
+ import { createDeepAgent, createFilesystemMiddleware, createPatchToolCallsMiddleware, FilesystemBackend, } from "deepagents";
4
+ import { createAgent, todoListMiddleware } from "langchain";
5
5
  import { wrapResolvedModel, } from "./parsing/output-parsing.js";
6
6
  import { UPSTREAM_REQUEST_CONFIG_KEY, UPSTREAM_SESSION_CONFIG_KEY } from "./adapter/upstream-configurable-keys.js";
7
7
  import { resolveDeepAgentSkillSourcePaths, } from "./adapter/compat/deepagent-compat.js";
8
8
  import { buildToolNameMapping, } from "./adapter/tool/tool-name-mapping.js";
9
9
  import { executeRequestInvocation } from "./adapter/flow/invocation-flow.js";
10
+ import { asStructuredExecutableTool } from "./adapter/tool/resolved-tool.js";
10
11
  import { streamRuntimeExecution } from "./adapter/flow/stream-runtime.js";
11
12
  import { applyToolRecoveryInstruction as applyToolRecoveryInstructionHelper, 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";
12
13
  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";
@@ -15,6 +16,7 @@ import { createResolvedModel } from "./adapter/model/model-providers.js";
15
16
  import { compileInterruptOn } from "./adapter/tool/interrupt-policy.js";
16
17
  import { resolveAdapterTools } from "./adapter/tool-resolution.js";
17
18
  import { resolveRuntimeStreamExecutionContext, } from "./adapter/flow/execution-context.js";
19
+ import { isRetryableProviderError } from "./adapter/resilience.js";
18
20
  export { applyDeepAgentDelegationPromptCompatibility, materializeDeepAgentSkillSourcePaths, resolveDeepAgentSkillSourcePaths, relativizeDeepAgentSkillSourcePaths, shouldRelaxDeepAgentDelegationPrompt, } from "./adapter/compat/deepagent-compat.js";
19
21
  export { buildAuthOmittingFetch, normalizeOpenAICompatibleInit } from "./adapter/compat/openai-compatible.js";
20
22
  export { buildToolNameMapping, createModelFacingToolNameCandidates, createModelFacingToolNameLookupCandidates, resolveModelFacingToolName, sanitizeToolNameForModel, } from "./adapter/tool/tool-name-mapping.js";
@@ -42,6 +44,32 @@ const UPSTREAM_BUILTIN_MIDDLEWARE_TOOL_NAMES = Object.freeze([
42
44
  "task",
43
45
  "delegate_task",
44
46
  ]);
47
+ const BUILTIN_MIDDLEWARE_ALIAS_TOOL_NAMES = new Set([
48
+ "list_files",
49
+ "search_files",
50
+ "run_command",
51
+ "delegate_task",
52
+ ]);
53
+ const MODEL_EXPOSED_BUILTIN_MIDDLEWARE_TOOL_NAMES = new Set([
54
+ "fetch_url",
55
+ "http_request",
56
+ "send_message",
57
+ "request_approval",
58
+ "schedule_task",
59
+ ]);
60
+ export function materializeModelExposedBuiltinMiddlewareTools(input) {
61
+ const explicitToolNames = new Set(input.explicitToolNames ?? []);
62
+ const tools = [];
63
+ for (const [toolName, tool] of input.builtinTools.entries()) {
64
+ if (explicitToolNames.has(toolName)
65
+ || BUILTIN_MIDDLEWARE_ALIAS_TOOL_NAMES.has(toolName)
66
+ || !MODEL_EXPOSED_BUILTIN_MIDDLEWARE_TOOL_NAMES.has(toolName)) {
67
+ continue;
68
+ }
69
+ tools.push(asStructuredExecutableTool(tool, toolName, tool.name));
70
+ }
71
+ return tools;
72
+ }
45
73
  export function resolveRunnableCheckpointer(options, binding) {
46
74
  return options.checkpointerResolver ? options.checkpointerResolver(binding) : new MemorySaver();
47
75
  }
@@ -116,6 +144,9 @@ export function resolveLangChainInvocationConfig(binding, options) {
116
144
  if (options.context) {
117
145
  config.context = options.context;
118
146
  }
147
+ if (options.toolRuntimeContext) {
148
+ config.toolRuntimeContext = options.toolRuntimeContext;
149
+ }
119
150
  return config;
120
151
  }
121
152
  export function buildDeepAgentCreateParams(input) {
@@ -152,6 +183,55 @@ export function buildDeepAgentCreateParams(input) {
152
183
  ...(input.resolvedBackend !== undefined ? { backend: input.resolvedBackend } : {}),
153
184
  };
154
185
  }
186
+ export function shouldUseMinimalDeepAgentAssembly(input) {
187
+ const executionKind = getBindingExecutionKind(input.binding);
188
+ if (executionKind !== "deepagent") {
189
+ return false;
190
+ }
191
+ if (input.resolvedBackend === undefined) {
192
+ return false;
193
+ }
194
+ if (input.resolvedSkills.length > 0) {
195
+ return false;
196
+ }
197
+ if (input.resolvedSubagents.length > 0 || getBindingDeepAgentSubagents(input.binding).length > 0) {
198
+ return false;
199
+ }
200
+ if (getBindingMemorySources(input.binding).length > 0) {
201
+ return false;
202
+ }
203
+ if (input.resolvedMiddleware.length > 0 || (getBindingMiddlewareConfigs(input.binding)?.length ?? 0) > 0) {
204
+ return false;
205
+ }
206
+ return input.resolvedInterruptOn === undefined || Object.keys(input.resolvedInterruptOn).length === 0;
207
+ }
208
+ export function buildMinimalDeepAgentCreateParams(input) {
209
+ const executionKind = getBindingExecutionKind(input.binding);
210
+ if (executionKind !== "deepagent" || !getBindingExecutionParams(input.binding)) {
211
+ throw new Error(`Agent ${input.binding.agent.id} has no runnable params`);
212
+ }
213
+ const upstreamParams = buildUpstreamCreateBaseParams(input.binding, [
214
+ "systemPrompt",
215
+ "contextSchema",
216
+ "responseFormat",
217
+ "name",
218
+ "description",
219
+ "includeAgentName",
220
+ "version",
221
+ ]);
222
+ return {
223
+ ...upstreamParams,
224
+ model: input.resolvedModel,
225
+ tools: input.resolvedTools,
226
+ middleware: [
227
+ todoListMiddleware(),
228
+ createFilesystemMiddleware({ backend: input.resolvedBackend }),
229
+ createPatchToolCallsMiddleware(),
230
+ ],
231
+ ...(input.resolvedCheckpointer !== undefined ? { checkpointer: input.resolvedCheckpointer } : {}),
232
+ ...(input.resolvedStore !== undefined ? { store: input.resolvedStore } : {}),
233
+ };
234
+ }
155
235
  function shouldAttachMinimalDeepAgentCheckpointer(binding, resolvedInterruptOn) {
156
236
  if (binding.harnessRuntime.checkpointer !== undefined) {
157
237
  return true;
@@ -289,12 +369,37 @@ export class AgentRuntimeAdapter {
289
369
  return path.isAbsolute(rendered) ? rendered : path.resolve(workspaceRoot, rendered);
290
370
  }
291
371
  resolveBuiltinMiddlewareBackend(binding, options = {}) {
292
- return resolveBuiltinMiddlewareBackendHelper({
372
+ const resolved = resolveBuiltinMiddlewareBackendHelper({
293
373
  binding,
294
374
  runtimeAdapterOptions: this.options,
295
375
  resolveFilesystemBackend: (currentBinding) => this.resolveFilesystemBackend(currentBinding),
296
376
  options,
297
377
  });
378
+ if (!this.options.scheduleManager || typeof resolved !== "object" || !resolved) {
379
+ return resolved;
380
+ }
381
+ const decorated = Object.create(resolved);
382
+ decorated.manageSchedule = (input) => this.options.scheduleManager.manageSchedule(input);
383
+ return decorated;
384
+ }
385
+ buildFunctionToolRuntimeContext(binding, options = {}) {
386
+ if (!this.options.functionToolContextResolver) {
387
+ return undefined;
388
+ }
389
+ const backend = this.resolveBuiltinMiddlewareBackend(binding, options);
390
+ return {
391
+ ...this.options.functionToolContextResolver({
392
+ binding,
393
+ sessionId: options.sessionId,
394
+ requestId: options.requestId,
395
+ }),
396
+ backend,
397
+ invocation: {
398
+ ...(options.context ? { context: options.context } : {}),
399
+ ...(options.sessionId ? { sessionId: options.sessionId } : {}),
400
+ ...(options.requestId ? { requestId: options.requestId } : {}),
401
+ },
402
+ };
298
403
  }
299
404
  createDeclaredMiddlewareResolverOptions(binding, options = {}) {
300
405
  return {
@@ -399,17 +504,21 @@ export class AgentRuntimeAdapter {
399
504
  const interruptOn = resolveRunnableInterruptOn(binding);
400
505
  const resolvedModel = await this.resolveModel(primaryModel);
401
506
  const resolvedTools = this.resolveTools(primaryTools, binding);
507
+ const builtinMiddlewareTools = materializeModelExposedBuiltinMiddlewareTools({
508
+ builtinTools: await this.resolveBuiltinMiddlewareTools(binding, { sessionId: options.sessionId ?? options.legacySessionId }),
509
+ explicitToolNames: primaryTools.map((tool) => tool.name),
510
+ });
402
511
  const resolvedMiddleware = await this.resolveMiddleware(binding, interruptOn, { sessionId: options.sessionId ?? options.legacySessionId });
403
512
  const resolvedCheckpointer = resolveRunnableCheckpointer(this.options, binding);
404
513
  const resolvedStore = this.options.storeResolver?.(binding);
405
514
  const model = resolvedModel;
406
- if (resolvedTools.length > 0 && typeof model.bindTools !== "function") {
407
- throw new Error(`Agent ${binding.agent.id} configures ${resolvedTools.length} tool(s), but resolved model ${primaryModel.id} does not support tool binding.`);
515
+ if (resolvedTools.length + builtinMiddlewareTools.length > 0 && typeof model.bindTools !== "function") {
516
+ throw new Error(`Agent ${binding.agent.id} configures ${resolvedTools.length + builtinMiddlewareTools.length} tool(s), but resolved model ${primaryModel.id} does not support tool binding.`);
408
517
  }
409
518
  return createAgent(buildLangChainCreateParams({
410
519
  binding,
411
520
  resolvedModel: model,
412
- resolvedTools,
521
+ resolvedTools: [...resolvedTools, ...builtinMiddlewareTools],
413
522
  resolvedMiddleware,
414
523
  resolvedCheckpointer,
415
524
  resolvedStore,
@@ -435,6 +544,10 @@ export class AgentRuntimeAdapter {
435
544
  }
436
545
  const resolvedModel = await this.resolveModel(primaryModel);
437
546
  const resolvedTools = this.resolveTools(primaryTools, binding);
547
+ const builtinMiddlewareTools = materializeModelExposedBuiltinMiddlewareTools({
548
+ builtinTools: await this.resolveBuiltinMiddlewareTools(binding),
549
+ explicitToolNames: primaryTools.map((tool) => tool.name),
550
+ });
438
551
  const resolvedMiddleware = await this.resolveMiddleware(binding);
439
552
  const resolvedSubagents = await this.resolveDeepAgentSubagents(getBindingDeepAgentSubagents(binding), binding);
440
553
  const resolvedInterruptOn = resolveRunnableInterruptOn(binding);
@@ -459,7 +572,7 @@ export class AgentRuntimeAdapter {
459
572
  const deepAgentConfig = buildDeepAgentCreateParams({
460
573
  binding,
461
574
  resolvedModel,
462
- resolvedTools,
575
+ resolvedTools: [...resolvedTools, ...builtinMiddlewareTools],
463
576
  resolvedMiddleware,
464
577
  resolvedSubagents,
465
578
  resolvedCheckpointer,
@@ -468,6 +581,24 @@ export class AgentRuntimeAdapter {
468
581
  resolvedInterruptOn,
469
582
  resolvedSkills,
470
583
  });
584
+ if (shouldUseMinimalDeepAgentAssembly({
585
+ binding,
586
+ resolvedMiddleware,
587
+ resolvedSubagents,
588
+ resolvedInterruptOn,
589
+ resolvedSkills,
590
+ resolvedBackend,
591
+ })) {
592
+ const minimalDeepAgentConfig = buildMinimalDeepAgentCreateParams({
593
+ binding,
594
+ resolvedModel,
595
+ resolvedTools: [...resolvedTools, ...builtinMiddlewareTools],
596
+ resolvedCheckpointer,
597
+ resolvedStore,
598
+ resolvedBackend,
599
+ });
600
+ return createAgent(minimalDeepAgentConfig);
601
+ }
471
602
  return createDeepAgent(deepAgentConfig);
472
603
  }
473
604
  buildRunnableCacheKey(binding, sessionId) {
@@ -502,6 +633,11 @@ export class AgentRuntimeAdapter {
502
633
  sessionId,
503
634
  requestId,
504
635
  context: options.context,
636
+ toolRuntimeContext: this.buildFunctionToolRuntimeContext(activeBinding, {
637
+ ...options,
638
+ sessionId,
639
+ requestId,
640
+ }),
505
641
  })), resolveBindingTimeout(activeBinding), "agent invoke", "invoke"));
506
642
  });
507
643
  };
@@ -513,19 +649,27 @@ export class AgentRuntimeAdapter {
513
649
  callRuntime,
514
650
  });
515
651
  };
516
- return executeRequestInvocation({
652
+ const toolRuntimeContext = this.buildFunctionToolRuntimeContext(binding, {
653
+ ...options,
654
+ sessionId,
655
+ requestId,
656
+ });
657
+ return this.invokeWithProviderRetry(binding, async () => executeRequestInvocation({
517
658
  binding,
518
659
  input,
519
660
  sessionId,
520
661
  requestId,
521
662
  resumePayload,
522
663
  history,
523
- invokeOptions: options,
664
+ invokeOptions: {
665
+ ...options,
666
+ ...(toolRuntimeContext ? { toolRuntimeContext } : {}),
667
+ },
524
668
  resolveTools: (tools, currentBinding) => this.resolveTools(tools, currentBinding),
525
669
  getToolNameMapping: (currentBinding) => this.getToolNameMapping(currentBinding),
526
- resolveBuiltinMiddlewareTools: (currentBinding, currentOptions) => this.resolveBuiltinMiddlewareTools(currentBinding, { ...currentOptions, sessionId }),
670
+ resolveBuiltinMiddlewareTools: (currentBinding, currentOptions) => this.resolveBuiltinMiddlewareTools(currentBinding, { ...currentOptions, sessionId, requestId }),
527
671
  callRuntimeWithToolParseRecovery,
528
- });
672
+ }));
529
673
  }
530
674
  async *stream(binding, input, sessionId, history = [], options = {}) {
531
675
  const invokeTimeoutMs = resolveBindingTimeout(binding);
@@ -537,6 +681,11 @@ export class AgentRuntimeAdapter {
537
681
  resolveModel: (model) => this.resolveModel(model),
538
682
  resolveTools: (tools, currentBinding) => this.resolveTools(tools, currentBinding),
539
683
  });
684
+ const streamToolRuntimeContext = this.buildFunctionToolRuntimeContext(binding, {
685
+ ...options,
686
+ sessionId,
687
+ requestId: options.requestId,
688
+ });
540
689
  yield* streamRuntimeExecution({
541
690
  binding,
542
691
  input,
@@ -545,6 +694,8 @@ export class AgentRuntimeAdapter {
545
694
  runtimeOptions: {
546
695
  ...options,
547
696
  requestId: options.requestId,
697
+ profiling: options.profiling,
698
+ ...(streamToolRuntimeContext ? { toolRuntimeContext: streamToolRuntimeContext } : {}),
548
699
  },
549
700
  primaryTools,
550
701
  toolNameMapping,
@@ -559,6 +710,7 @@ export class AgentRuntimeAdapter {
559
710
  streamDeadlineAt,
560
711
  invoke: (activeBinding, activeInput, activeSessionId, activeRequestId, resumePayload, activeHistory, invokeOptions) => this.invoke(activeBinding, activeInput, activeSessionId, activeRequestId, resumePayload, activeHistory, invokeOptions),
561
712
  applyToolRecoveryInstruction: (activeBinding, instruction) => applyToolRecoveryInstructionHelper(activeBinding, instruction),
713
+ isRetryableProviderError: (activeBinding, error) => isRetryableProviderError(activeBinding, error),
562
714
  getSystemPrompt: (activeBinding) => getBindingSystemPrompt(activeBinding),
563
715
  isLangChainBinding,
564
716
  isDeepAgentBinding,
@@ -4,4 +4,5 @@ export declare class EventBus implements RuntimeEventSink {
4
4
  publish(event: HarnessEvent): void;
5
5
  subscribe(listener: HarnessEventListener): () => void;
6
6
  registerProjection(projection: HarnessEventProjection): () => void;
7
+ drain(): Promise<void>;
7
8
  }
@@ -10,4 +10,7 @@ export class EventBus {
10
10
  registerProjection(projection) {
11
11
  return this.sink.registerProjection(projection);
12
12
  }
13
+ async drain() {
14
+ await this.sink.drain();
15
+ }
13
16
  }
@@ -2,8 +2,11 @@ import type { HarnessEvent, HarnessEventListener, HarnessEventProjection, Runtim
2
2
  export declare class RuntimeEventSinkImpl implements RuntimeEventSink {
3
3
  private readonly emitter;
4
4
  private readonly projections;
5
+ private readonly inflightProjectionTasks;
6
+ private trackProjectionTask;
5
7
  publish(event: HarnessEvent): void;
6
8
  subscribe(listener: HarnessEventListener): () => void;
7
9
  registerProjection(projection: HarnessEventProjection): () => void;
10
+ drain(): Promise<void>;
8
11
  }
9
12
  export declare function createRuntimeEventSink(): RuntimeEventSinkImpl;
@@ -3,19 +3,23 @@ import { getEventSubscribers } from "../../../extensions.js";
3
3
  function dispatchListener(listener, event) {
4
4
  void Promise.resolve(listener(event));
5
5
  }
6
- function dispatchProjection(projection, event) {
7
- if (projection.shouldHandle && !projection.shouldHandle(event)) {
8
- return;
9
- }
10
- void Promise.resolve(projection.handleEvent(event));
11
- }
12
6
  export class RuntimeEventSinkImpl {
13
7
  emitter = new EventEmitter();
14
8
  projections = new Set();
9
+ inflightProjectionTasks = new Set();
10
+ trackProjectionTask(task) {
11
+ this.inflightProjectionTasks.add(task);
12
+ void task.finally(() => {
13
+ this.inflightProjectionTasks.delete(task);
14
+ });
15
+ }
15
16
  publish(event) {
16
17
  this.emitter.emit("event", event);
17
18
  for (const projection of this.projections) {
18
- dispatchProjection(projection, event);
19
+ if (projection.shouldHandle && !projection.shouldHandle(event)) {
20
+ continue;
21
+ }
22
+ this.trackProjectionTask(Promise.resolve(projection.handleEvent(event)));
19
23
  }
20
24
  for (const subscriber of getEventSubscribers()) {
21
25
  dispatchListener(subscriber.onEvent, event);
@@ -29,6 +33,11 @@ export class RuntimeEventSinkImpl {
29
33
  this.projections.add(projection);
30
34
  return () => this.projections.delete(projection);
31
35
  }
36
+ async drain() {
37
+ while (this.inflightProjectionTasks.size > 0) {
38
+ await Promise.allSettled(Array.from(this.inflightProjectionTasks));
39
+ }
40
+ }
32
41
  }
33
42
  export function createRuntimeEventSink() {
34
43
  return new RuntimeEventSinkImpl();
@@ -1,5 +1,11 @@
1
- import type { HarnessEvent, HarnessStreamItem, RequestListeners, RequestResult } from "../../../contracts/types.js";
1
+ import type { HarnessEvent, HarnessStreamItem, RequestListeners, RequestPlanState, RequestResult } from "../../../contracts/types.js";
2
2
  export type InternalHarnessStreamItem = HarnessStreamItem | {
3
+ type: "commentary";
4
+ sessionId: string;
5
+ requestId: string;
6
+ agentId: string;
7
+ content: string;
8
+ } | {
3
9
  type: "content";
4
10
  sessionId: string;
5
11
  requestId: string;
@@ -19,6 +25,17 @@ export type InternalHarnessStreamItem = HarnessStreamItem | {
19
25
  toolName: string;
20
26
  output: unknown;
21
27
  isError?: boolean;
28
+ } | {
29
+ type: "plan-state";
30
+ sessionId: string;
31
+ requestId: string;
32
+ agentId: string;
33
+ planState: RequestPlanState;
34
+ } | {
35
+ type: "profile-step";
36
+ sessionId: string;
37
+ requestId: string;
38
+ step: import("../../../contracts/types.js").RequestExecutionStep;
22
39
  };
23
40
  export declare function emitOutputDeltaAndCreateItem(emit: (sessionId: string, requestId: string, sequence: number, eventType: string, payload: Record<string, unknown>) => Promise<HarnessEvent>, sessionId: string, requestId: string, agentId: string, content: string): Promise<InternalHarnessStreamItem>;
24
41
  export declare function createContentBlocksItem(sessionId: string, requestId: string, agentId: string, contentBlocks: unknown[]): InternalHarnessStreamItem;
@@ -1,4 +1,5 @@
1
1
  import { createFallbackRequestResultFromLatestEvent, mergeRequestResultOutput } from "../run/helpers.js";
2
+ import { applyRequestStreamItemToSnapshot, createInitialRequestEventSnapshot, toRequestDataEvent, } from "../../../request-events.js";
2
3
  export async function emitOutputDeltaAndCreateItem(emit, sessionId, requestId, agentId, content) {
3
4
  await emit(sessionId, requestId, 3, "output.delta", {
4
5
  content,
@@ -31,35 +32,47 @@ export function createToolResultKey(toolName, output, isError) {
31
32
  return JSON.stringify([toolName, serializedOutput, isError === true]);
32
33
  }
33
34
  export async function dispatchRequestListeners(stream, listeners, options) {
35
+ const notifyIfPresent = async (listener, value) => {
36
+ if (!listener) {
37
+ return;
38
+ }
39
+ await options.notifyListener(listener, value);
40
+ };
34
41
  let latestEvent;
35
42
  let latestResult;
36
43
  let output = "";
44
+ let snapshot = createInitialRequestEventSnapshot();
37
45
  for await (const item of stream) {
46
+ snapshot = applyRequestStreamItemToSnapshot(snapshot, item);
38
47
  if (item.type === "event") {
39
48
  latestEvent = item.event;
40
- await options.notifyListener(listeners.onEvent, item.event);
41
- continue;
49
+ await notifyIfPresent(listeners.onEvent, item.event);
42
50
  }
43
- if (item.type === "upstream-event") {
44
- await options.notifyListener(listeners.onUpstreamEvent, item.event);
51
+ else if (item.type === "upstream-event") {
52
+ await notifyIfPresent(listeners.onUpstreamEvent, item.event);
45
53
  if (item.surfaceItem) {
46
- await options.notifyListener(listeners.onTraceItem, {
54
+ await notifyIfPresent(listeners.onTraceItem, {
47
55
  sessionId: item.sessionId,
48
56
  requestId: item.requestId,
49
57
  surfaceItem: item.surfaceItem,
50
58
  event: item.event,
51
59
  });
52
60
  }
53
- continue;
54
61
  }
55
- if (item.type === "result") {
62
+ else if (item.type === "result") {
56
63
  latestResult = item.result;
57
- continue;
58
64
  }
59
- if (item.type === "content") {
65
+ else if (item.type === "plan-state") {
66
+ await notifyIfPresent(listeners.onPlanState, item.planState);
67
+ }
68
+ else if (item.type === "content") {
60
69
  output += item.content;
61
- continue;
62
70
  }
71
+ const dataEvent = toRequestDataEvent(item);
72
+ if (dataEvent) {
73
+ await notifyIfPresent(listeners.dataListener, dataEvent);
74
+ }
75
+ await notifyIfPresent(listeners.eventListener, snapshot);
63
76
  }
64
77
  if (!latestEvent) {
65
78
  throw new Error("run did not emit any events");
@@ -1,8 +1,9 @@
1
1
  import { readSkillMetadata } from "../../support/skill-metadata.js";
2
2
  import { createUpstreamTimelineReducer } from "../../../upstream-events.js";
3
3
  import { formatAgentName } from "../../../utils/agent-display.js";
4
- import { getBindingMemorySources, getBindingPrimaryModel, getBindingPrimaryTools, getBindingSkills, getBindingSubagents, } from "../../support/compiled-binding.js";
4
+ import { getBindingMemorySources, getBindingPrimaryModel, getBindingPrimaryTools, getBindingSkills, getBindingSubagents, isDeepAgentBinding, } from "../../support/compiled-binding.js";
5
5
  import { buildRuntimeGovernanceBundles } from "./governance.js";
6
+ import { BUILTIN_MIDDLEWARE_TOOL_DESCRIPTORS } from "../../adapter/tool/builtin-middleware-tools.js";
6
7
  import { buildSurfaceId, resolveSurfaceAction, resolveSurfaceDisplayName, } from "./surface-semantics.js";
7
8
  function asObject(value) {
8
9
  return typeof value === "object" && value !== null ? value : null;
@@ -10,6 +11,14 @@ function asObject(value) {
10
11
  function readStringArray(value) {
11
12
  return Array.isArray(value) ? value.filter((item) => typeof item === "string" && item.trim().length > 0) : [];
12
13
  }
14
+ function getBindingSkillNames(binding) {
15
+ if (!binding) {
16
+ return [];
17
+ }
18
+ return getBindingSkills(binding)
19
+ .map((skillPath) => readSkillMetadata(skillPath).name)
20
+ .filter((name) => typeof name === "string" && name.trim().length > 0);
21
+ }
13
22
  function isTaskDelegationCompletionEvent(event) {
14
23
  const eventName = typeof event.event === "string" ? event.event : "";
15
24
  const name = typeof event.name === "string" ? event.name : "";
@@ -83,6 +92,18 @@ export function buildRequestRuntimeSnapshot(binding, options) {
83
92
  : typeof init.baseURL === "string" && init.baseURL.trim().length > 0
84
93
  ? init.baseURL.trim()
85
94
  : undefined;
95
+ const declaredTools = getBindingPrimaryTools(binding).map((tool) => ({
96
+ name: tool.name,
97
+ description: tool.description,
98
+ }));
99
+ const tools = isDeepAgentBinding(binding)
100
+ ? [
101
+ ...declaredTools,
102
+ ...BUILTIN_MIDDLEWARE_TOOL_DESCRIPTORS
103
+ .filter((descriptor) => !declaredTools.some((tool) => tool.name === descriptor.name))
104
+ .map((descriptor) => ({ ...descriptor })),
105
+ ]
106
+ : declaredTools;
86
107
  return {
87
108
  agentId: binding.agent.id,
88
109
  ...(model ? {
@@ -93,10 +114,7 @@ export function buildRequestRuntimeSnapshot(binding, options) {
93
114
  ...(baseUrl ? { baseUrl } : {}),
94
115
  },
95
116
  } : {}),
96
- tools: getBindingPrimaryTools(binding).map((tool) => ({
97
- name: tool.name,
98
- description: tool.description,
99
- })),
117
+ tools,
100
118
  skills: getBindingSkills(binding).map((skillPath) => {
101
119
  const metadata = readSkillMetadata(skillPath);
102
120
  return {
@@ -339,6 +357,9 @@ export function projectRuntimeSurfaceFromSingleUpstreamEvent(input) {
339
357
  detail: {
340
358
  step: projection.step,
341
359
  category: projection.category,
360
+ ...(kind === "skill" && getBindingSkillNames(input.binding).length > 0
361
+ ? { skillNames: getBindingSkillNames(input.binding) }
362
+ : {}),
342
363
  },
343
364
  });
344
365
  }
@@ -1,12 +1,18 @@
1
- import type { CompiledAgentBinding, HarnessEvent, MessageContent, RequestResult, RuntimeSnapshot, TranscriptMessage } from "../../../contracts/types.js";
1
+ import type { CompiledAgentBinding, HarnessEvent, MemoryRecord, MessageContent, RequestResult, RequestExecutionStep, RuntimeSnapshot, TranscriptMessage } from "../../../contracts/types.js";
2
2
  import { type InternalHarnessStreamItem } from "../events/streaming.js";
3
- type RuntimeStreamChunk = string | {
4
- kind: "content" | "interrupt" | "reasoning" | "step" | "tool-result" | "upstream-event";
3
+ type RuntimeStreamChunk = {
4
+ kind: "commentary";
5
+ content: string;
6
+ } | string | {
7
+ kind: "content" | "interrupt" | "reasoning" | "tool-result" | "upstream-event";
5
8
  content?: string;
6
9
  toolName?: string;
7
10
  output?: unknown;
8
11
  isError?: boolean;
9
12
  event?: unknown;
13
+ } | {
14
+ kind: "profile";
15
+ step: RequestExecutionStep;
10
16
  };
11
17
  type StreamRunOptions = {
12
18
  binding: CompiledAgentBinding;
@@ -16,7 +22,10 @@ type StreamRunOptions = {
16
22
  context?: Record<string, unknown>;
17
23
  state?: Record<string, unknown>;
18
24
  files?: Record<string, unknown>;
19
- memoryContext?: string;
25
+ memoryRecall?: {
26
+ prompt?: string;
27
+ items: MemoryRecord[];
28
+ };
20
29
  };
21
30
  sessionId: string;
22
31
  requestId: string;