@lleverage-ai/agent-sdk 0.0.5 → 0.0.7

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 (51) hide show
  1. package/dist/agent.d.ts.map +1 -1
  2. package/dist/agent.js +93 -117
  3. package/dist/agent.js.map +1 -1
  4. package/dist/index.d.ts +4 -3
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +5 -4
  7. package/dist/index.js.map +1 -1
  8. package/dist/mcp/manager.d.ts +14 -0
  9. package/dist/mcp/manager.d.ts.map +1 -1
  10. package/dist/mcp/manager.js +19 -0
  11. package/dist/mcp/manager.js.map +1 -1
  12. package/dist/plugins.d.ts.map +1 -1
  13. package/dist/plugins.js +2 -0
  14. package/dist/plugins.js.map +1 -1
  15. package/dist/prompt-builder/components.d.ts.map +1 -1
  16. package/dist/prompt-builder/components.js +2 -0
  17. package/dist/prompt-builder/components.js.map +1 -1
  18. package/dist/prompt-builder/delegation-component.d.ts +27 -0
  19. package/dist/prompt-builder/delegation-component.d.ts.map +1 -0
  20. package/dist/prompt-builder/delegation-component.js +53 -0
  21. package/dist/prompt-builder/delegation-component.js.map +1 -0
  22. package/dist/testing/mock-agent.d.ts.map +1 -1
  23. package/dist/testing/mock-agent.js +0 -4
  24. package/dist/testing/mock-agent.js.map +1 -1
  25. package/dist/testing/recorder.d.ts.map +1 -1
  26. package/dist/testing/recorder.js +0 -3
  27. package/dist/testing/recorder.js.map +1 -1
  28. package/dist/tools/call-tool.d.ts +59 -0
  29. package/dist/tools/call-tool.d.ts.map +1 -0
  30. package/dist/tools/call-tool.js +93 -0
  31. package/dist/tools/call-tool.js.map +1 -0
  32. package/dist/tools/factory.d.ts +10 -2
  33. package/dist/tools/factory.d.ts.map +1 -1
  34. package/dist/tools/factory.js +10 -1
  35. package/dist/tools/factory.js.map +1 -1
  36. package/dist/tools/index.d.ts +2 -2
  37. package/dist/tools/index.d.ts.map +1 -1
  38. package/dist/tools/index.js +2 -2
  39. package/dist/tools/index.js.map +1 -1
  40. package/dist/tools/search.d.ts +8 -0
  41. package/dist/tools/search.d.ts.map +1 -1
  42. package/dist/tools/search.js +41 -2
  43. package/dist/tools/search.js.map +1 -1
  44. package/dist/types.d.ts +99 -44
  45. package/dist/types.d.ts.map +1 -1
  46. package/dist/types.js.map +1 -1
  47. package/package.json +5 -3
  48. package/dist/tools/tool-registry.d.ts +0 -424
  49. package/dist/tools/tool-registry.d.ts.map +0 -1
  50. package/dist/tools/tool-registry.js +0 -607
  51. package/dist/tools/tool-registry.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA2DH,OAAO,KAAK,EACV,KAAK,EACL,YAAY,EAyBb,MAAM,YAAY,CAAC;AA6pBpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,KAAK,CA0sFxD"}
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA4DH,OAAO,KAAK,EACV,KAAK,EACL,YAAY,EAwBb,MAAM,YAAY,CAAC;AA6pBpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,KAAK,CAmrFxD"}
package/dist/agent.js CHANGED
@@ -15,9 +15,10 @@ import { MCPManager } from "./mcp/manager.js";
15
15
  import { applyMiddleware, mergeHooks, setupMiddleware } from "./middleware/index.js";
16
16
  import { createDefaultPromptBuilder } from "./prompt-builder/components.js";
17
17
  import { ACCEPT_EDITS_BLOCKED_PATTERNS } from "./security/index.js";
18
+ import { createSubagent } from "./subagents.js";
18
19
  import { TaskManager } from "./task-manager.js";
20
+ import { createCallToolTool } from "./tools/call-tool.js";
19
21
  import { coreToolsToToolSet, createCoreTools, createSearchToolsTool, createTaskOutputTool, createTaskTool, } from "./tools/factory.js";
20
- import { createUseToolsTool, ToolRegistry } from "./tools/tool-registry.js";
21
22
  let agentIdCounter = 0;
22
23
  /**
23
24
  * Internal signal for interrupt flow control.
@@ -630,43 +631,7 @@ export function createAgent(options) {
630
631
  return `[Background task failed: ${task.id}]\nCommand: ${command}\nError: ${task.error ?? "Unknown error"}`;
631
632
  });
632
633
  // Determine plugin loading mode
633
- // Track whether it was explicitly set to distinguish from default
634
- const explicitPluginLoading = options.pluginLoading !== undefined;
635
634
  const pluginLoadingMode = options.pluginLoading ?? "eager";
636
- const preloadPlugins = new Set(options.preloadPlugins ?? []);
637
- // Initialize tool registry for lazy/explicit loading modes
638
- const toolRegistry = pluginLoadingMode !== "eager"
639
- ? new ToolRegistry({
640
- onToolRegistered: async (input) => {
641
- const hooks = effectiveHooks?.ToolRegistered ?? [];
642
- if (hooks.length === 0)
643
- return;
644
- const hookInput = {
645
- hook_event_name: "ToolRegistered",
646
- session_id: "default",
647
- cwd: process.cwd(),
648
- tool_name: input.tool_name,
649
- description: input.description,
650
- source: input.source,
651
- };
652
- await invokeHooksWithTimeout(hooks, hookInput, null, agent);
653
- },
654
- onToolLoadError: async (input) => {
655
- const hooks = effectiveHooks?.ToolLoadError ?? [];
656
- if (hooks.length === 0)
657
- return;
658
- const hookInput = {
659
- hook_event_name: "ToolLoadError",
660
- session_id: "default",
661
- cwd: process.cwd(),
662
- tool_name: input.tool_name,
663
- error: input.error,
664
- source: input.source,
665
- };
666
- await invokeHooksWithTimeout(hooks, hookInput, null, agent);
667
- },
668
- })
669
- : undefined;
670
635
  // Collect skills from options and plugins
671
636
  const skills = [...(options.skills ?? [])];
672
637
  // Initialize MCP manager for unified plugin tool handling
@@ -728,6 +693,10 @@ export function createAgent(options) {
728
693
  const toolSearchMaxResults = toolSearchConfig.maxResults ?? 10;
729
694
  // Track whether deferred loading is active
730
695
  let deferredLoadingActive = false;
696
+ // Track whether any deferred or proxy plugins exist (for call_tool creation)
697
+ let hasProxiedTools = false;
698
+ // Auto-created subagent definitions from delegated plugins
699
+ const autoSubagents = [];
731
700
  // Count total plugin tools for threshold calculation and collect plugin skills.
732
701
  // Note: Function-based (streaming) tools are not counted since we don't know
733
702
  // their count until they're invoked with a streaming context.
@@ -746,7 +715,7 @@ export function createAgent(options) {
746
715
  // Determine if we should use deferred loading based on tool search settings
747
716
  // Note: Only activate deferred loading if explicitly requested, not based on auto threshold
748
717
  // The auto threshold should only affect whether search_tools is created, not loading behavior
749
- if (toolSearchEnabled === "always") {
718
+ if (toolSearchEnabled === "always" || pluginLoadingMode === "proxy") {
750
719
  deferredLoadingActive = true;
751
720
  }
752
721
  // Removed: auto threshold no longer forces deferred loading
@@ -767,7 +736,7 @@ export function createAgent(options) {
767
736
  ...coreToolsToToolSet(autoCreatedCoreTools),
768
737
  ...(options.tools ?? {}),
769
738
  };
770
- // Process plugins based on loading mode and deferred loading
739
+ // Process plugins based on loading mode, deferred, and delegation settings
771
740
  // Note: Plugin skills are collected earlier (before createCoreTools) so
772
741
  // the skill tool can include them in progressive disclosure.
773
742
  for (const plugin of options.plugins ?? []) {
@@ -775,36 +744,18 @@ export function createAgent(options) {
775
744
  // Note: Function-based (streaming) tools are handled separately in
776
745
  // getActiveToolSetWithStreaming() and are not registered here
777
746
  if (plugin.tools && typeof plugin.tools !== "function") {
778
- const shouldPreload = preloadPlugins.has(plugin.name);
779
- // Priority order:
780
- // 1. Explicit mode - don't register
781
- // 2. Preload - always load immediately
782
- // 3. Explicit eager - always load immediately
783
- // 4. Lazy mode - register with tool registry
784
- // 5. Deferred loading - register but don't load
785
- // 6. Default eager - load immediately
786
- if (pluginLoadingMode === "explicit") {
787
- // Explicit mode: don't auto-register, user must do it manually
788
- // Skip registration entirely
789
- }
790
- else if (shouldPreload) {
791
- // Preloaded plugins: always load immediately, regardless of other settings
747
+ // Check if this plugin is deferred (proxy mode or per-plugin opt-in)
748
+ const isDeferred = plugin.deferred === true || (pluginLoadingMode === "proxy" && plugin.deferred !== false);
749
+ if (isDeferred) {
750
+ // Deferred plugin: register in MCP for discovery via search_tools + call_tool
792
751
  mcpManager.registerPluginTools(plugin.name, plugin.tools, {
793
- autoLoad: true,
794
- });
795
- }
796
- else if (explicitPluginLoading && pluginLoadingMode === "eager") {
797
- // Explicit eager mode: always load immediately, regardless of toolSearch settings
798
- mcpManager.registerPluginTools(plugin.name, plugin.tools, {
799
- autoLoad: true,
752
+ autoLoad: false,
800
753
  });
754
+ hasProxiedTools = true;
801
755
  }
802
- else if (pluginLoadingMode === "lazy" && toolRegistry) {
803
- // Lazy mode: register with registry for on-demand loading
804
- toolRegistry.registerPlugin(plugin.name, plugin.tools);
805
- }
806
- else if (deferredLoadingActive) {
756
+ else if (deferredLoadingActive && plugin.deferred !== false) {
807
757
  // Deferred loading (auto threshold or always enabled): register tools but don't load them initially
758
+ // Respect explicit deferred: false opt-out
808
759
  mcpManager.registerPluginTools(plugin.name, plugin.tools, {
809
760
  autoLoad: false,
810
761
  });
@@ -817,33 +768,61 @@ export function createAgent(options) {
817
768
  }
818
769
  }
819
770
  }
771
+ // Create subagent definitions from plugins with subagent config
772
+ for (const plugin of options.plugins ?? []) {
773
+ if (plugin.subagent) {
774
+ autoSubagents.push({
775
+ type: `plugin-${plugin.name}`,
776
+ description: plugin.subagent.description,
777
+ model: plugin.subagent.model ?? "inherit",
778
+ create: (_ctx) => createSubagent(agent, {
779
+ name: `plugin-${plugin.name}`,
780
+ description: plugin.subagent.description,
781
+ model: _ctx.model,
782
+ tools: plugin.subagent.tools,
783
+ systemPrompt: plugin.subagent.prompt ??
784
+ `You are a ${plugin.name} specialist. Complete the requested task using available tools and return a clear summary.`,
785
+ }),
786
+ });
787
+ }
788
+ }
789
+ // Merge auto-created subagents with user-provided ones
790
+ const allSubagents = [...(options.subagents ?? []), ...autoSubagents];
791
+ const hasSubagents = allSubagents.length > 0;
792
+ // In proxy mode, create call_tool and configure search_tools with schema disclosure
793
+ const isProxyMode = pluginLoadingMode === "proxy" || hasProxiedTools;
794
+ if (isProxyMode && !options.disabledCoreTools?.includes("call_tool")) {
795
+ coreTools.call_tool = createCallToolTool({
796
+ mcpManager,
797
+ });
798
+ }
820
799
  // Create search_tools for MCP tool discovery and/or plugin loading
821
800
  // New behavior:
822
801
  // - Create when auto threshold is exceeded (for lazy discovery)
823
802
  // - Create when deferred loading is active (explicitly requested)
803
+ // - Create when proxy mode is active (for call_tool discovery)
824
804
  // - Create when external MCP servers exist (for MCP tool search)
825
- // - Always auto-load tools when found (no manual load step)
805
+ // - Always auto-load tools when found (no manual load step) — unless proxy mode
826
806
  const shouldCreateSearchToolsForAutoThreshold = toolSearchEnabled === "auto" && totalPluginToolCount > toolSearchThreshold;
827
807
  const shouldCreateSearchTools = !options.disabledCoreTools?.includes("search_tools") &&
828
808
  (deferredLoadingActive ||
809
+ isProxyMode ||
829
810
  shouldCreateSearchToolsForAutoThreshold ||
830
811
  (mcpManager.hasExternalServers() && toolSearchEnabled !== "never"));
831
812
  if (shouldCreateSearchTools) {
832
813
  coreTools.search_tools = createSearchToolsTool({
833
814
  manager: mcpManager,
834
815
  maxResults: toolSearchMaxResults,
835
- enableLoad: true, // Always enable auto-loading
836
- autoLoad: true, // NEW: Auto-load tools after searching
816
+ // In proxy mode: don't auto-load, include schema for call_tool usage
817
+ enableLoad: !isProxyMode,
818
+ autoLoad: !isProxyMode,
819
+ includeSchema: isProxyMode,
837
820
  onToolsLoaded: (toolNames) => {
838
821
  // Tools are now loaded in MCPManager and will be included in getActiveToolSet()
839
822
  // This callback can be used for logging/notifications
840
823
  },
841
824
  });
842
825
  }
843
- // Add use_tools meta-tool in lazy mode
844
- if (pluginLoadingMode === "lazy" && toolRegistry) {
845
- coreTools.use_tools = createUseToolsTool({ registry: toolRegistry });
846
- }
847
826
  /**
848
827
  * Filter a tool set by the allowedTools and disallowedTools restrictions.
849
828
  * If neither is set, returns all tools.
@@ -887,9 +866,6 @@ export function createAgent(options) {
887
866
  const allTools = { ...coreTools };
888
867
  Object.assign(allTools, runtimeTools);
889
868
  Object.assign(allTools, mcpManager.getToolSet());
890
- if (toolRegistry) {
891
- Object.assign(allTools, toolRegistry.getLoadedTools());
892
- }
893
869
  return allTools;
894
870
  })());
895
871
  // Extract tool metadata for context
@@ -926,6 +902,10 @@ export function createAgent(options) {
926
902
  permissionMode,
927
903
  currentMessages: messages,
928
904
  threadId,
905
+ custom: {
906
+ hasSubagents,
907
+ delegationInstructions: options.delegationInstructions,
908
+ },
929
909
  };
930
910
  };
931
911
  // Helper to get system prompt (either static or built from context)
@@ -947,10 +927,6 @@ export function createAgent(options) {
947
927
  // Add MCP tools from plugin registrations
948
928
  const mcpTools = mcpManager.getToolSet();
949
929
  Object.assign(allTools, mcpTools);
950
- // Add dynamically loaded tools from registry (lazy mode)
951
- if (toolRegistry) {
952
- Object.assign(allTools, toolRegistry.getLoadedTools());
953
- }
954
930
  // Apply allowedTools filtering
955
931
  const filtered = filterToolsByAllowed(allTools);
956
932
  // Apply permission mode wrapping with canUseTool callback and approval state
@@ -991,10 +967,6 @@ export function createAgent(options) {
991
967
  // Add MCP tools from plugin registrations
992
968
  const mcpTools = mcpManager.getToolSet();
993
969
  Object.assign(allTools, mcpTools);
994
- // Add dynamically loaded tools from registry (lazy mode)
995
- if (toolRegistry) {
996
- Object.assign(allTools, toolRegistry.getLoadedTools());
997
- }
998
970
  // Apply allowedTools filtering
999
971
  const filtered = filterToolsByAllowed(allTools);
1000
972
  // Apply permission mode wrapping with canUseTool callback and approval state
@@ -1047,7 +1019,7 @@ export function createAgent(options) {
1047
1019
  const result = {
1048
1020
  ...tools,
1049
1021
  task: createTaskTool({
1050
- subagents: options.subagents ?? [],
1022
+ subagents: allSubagents,
1051
1023
  defaultModel: options.model,
1052
1024
  parentAgent: agent,
1053
1025
  // Always include general-purpose subagent so agents can delegate tasks
@@ -1399,7 +1371,7 @@ export function createAgent(options) {
1399
1371
  const checkpointThreadId = forkedSessionId ?? effectiveGenOptions.threadId;
1400
1372
  const finalMessages = [
1401
1373
  ...messages,
1402
- { role: "assistant", content: response.text },
1374
+ ...(response.text ? [{ role: "assistant", content: response.text }] : []),
1403
1375
  ];
1404
1376
  const savedCheckpoint = await saveCheckpoint(checkpointThreadId, finalMessages, startStep + response.steps.length);
1405
1377
  if (savedCheckpoint) {
@@ -1468,10 +1440,12 @@ export function createAgent(options) {
1468
1440
  // Save checkpoint - use forked session ID if forking, otherwise use original threadId
1469
1441
  const checkpointThreadId = forkedSessionId ?? effectiveGenOptions.threadId;
1470
1442
  if (checkpointThreadId && options.checkpointer) {
1471
- // Build final messages including the assistant response
1443
+ // Build final messages including the assistant response.
1444
+ // Skip empty text to avoid invalid content blocks (e.g. when
1445
+ // the model finishes with only tool calls).
1472
1446
  const finalMessages = [
1473
1447
  ...messages,
1474
- { role: "assistant", content: response.text },
1448
+ ...(response.text ? [{ role: "assistant", content: response.text }] : []),
1475
1449
  ];
1476
1450
  await saveCheckpoint(checkpointThreadId, finalMessages, startStep + response.steps.length);
1477
1451
  }
@@ -1506,7 +1480,12 @@ export function createAgent(options) {
1506
1480
  let lastResult = finalResult;
1507
1481
  let runningMessages = hasCheckpointing
1508
1482
  ? []
1509
- : [...messages, { role: "assistant", content: finalResult.text }];
1483
+ : [
1484
+ ...messages,
1485
+ ...(finalResult.text
1486
+ ? [{ role: "assistant", content: finalResult.text }]
1487
+ : []),
1488
+ ];
1510
1489
  let followUpPrompt = await getNextTaskPrompt();
1511
1490
  while (followUpPrompt !== null) {
1512
1491
  lastResult = await agent.generate({
@@ -1521,7 +1500,9 @@ export function createAgent(options) {
1521
1500
  runningMessages = [
1522
1501
  ...runningMessages,
1523
1502
  { role: "user", content: followUpPrompt },
1524
- { role: "assistant", content: lastResult.text },
1503
+ ...(lastResult.text
1504
+ ? [{ role: "assistant", content: lastResult.text }]
1505
+ : []),
1525
1506
  ];
1526
1507
  }
1527
1508
  followUpPrompt = await getNextTaskPrompt();
@@ -1808,7 +1789,7 @@ export function createAgent(options) {
1808
1789
  if (effectiveGenOptions.threadId && options.checkpointer) {
1809
1790
  const finalMessages = [
1810
1791
  ...messages,
1811
- { role: "assistant", content: text },
1792
+ ...(text ? [{ role: "assistant", content: text }] : []),
1812
1793
  ];
1813
1794
  await saveCheckpoint(effectiveGenOptions.threadId, finalMessages, startStep + steps.length);
1814
1795
  }
@@ -1832,7 +1813,7 @@ export function createAgent(options) {
1832
1813
  const hasCheckpointing = !!(effectiveGenOptions.threadId && options.checkpointer);
1833
1814
  let currentMessages = hasCheckpointing
1834
1815
  ? []
1835
- : [...messages, { role: "assistant", content: text }];
1816
+ : [...messages, ...(text ? [{ role: "assistant", content: text }] : [])];
1836
1817
  let followUpPrompt = await getNextTaskPrompt();
1837
1818
  while (followUpPrompt !== null) {
1838
1819
  const followUpGen = agent.stream({
@@ -1850,7 +1831,7 @@ export function createAgent(options) {
1850
1831
  currentMessages = [
1851
1832
  ...currentMessages,
1852
1833
  { role: "user", content: followUpPrompt },
1853
- { role: "assistant", content: followUpText },
1834
+ ...(followUpText ? [{ role: "assistant", content: followUpText }] : []),
1854
1835
  ];
1855
1836
  }
1856
1837
  followUpPrompt = await getNextTaskPrompt();
@@ -1958,10 +1939,9 @@ export function createAgent(options) {
1958
1939
  // Build messages including this step's results
1959
1940
  const stepMessages = [
1960
1941
  ...initialParams.messages,
1961
- {
1962
- role: "assistant",
1963
- content: stepResult.text,
1964
- },
1942
+ ...(stepResult.text
1943
+ ? [{ role: "assistant", content: stepResult.text }]
1944
+ : []),
1965
1945
  ];
1966
1946
  await saveCheckpoint(effectiveGenOptions.threadId, stepMessages, startStep + currentStepCount);
1967
1947
  }
@@ -1980,7 +1960,9 @@ export function createAgent(options) {
1980
1960
  if (effectiveGenOptions.threadId && options.checkpointer) {
1981
1961
  const finalMessages = [
1982
1962
  ...initialParams.messages,
1983
- { role: "assistant", content: finishResult.text },
1963
+ ...(finishResult.text
1964
+ ? [{ role: "assistant", content: finishResult.text }]
1965
+ : []),
1984
1966
  ];
1985
1967
  await saveCheckpoint(effectiveGenOptions.threadId, finalMessages, startStep + finishResult.steps.length);
1986
1968
  }
@@ -2021,7 +2003,7 @@ export function createAgent(options) {
2021
2003
  let accumulatedStepCount = initialSteps.length;
2022
2004
  let currentMessages = [
2023
2005
  ...messages,
2024
- { role: "assistant", content: text },
2006
+ ...(text ? [{ role: "assistant", content: text }] : []),
2025
2007
  ];
2026
2008
  let followUpPrompt = await getNextTaskPrompt();
2027
2009
  while (followUpPrompt !== null) {
@@ -2048,7 +2030,9 @@ export function createAgent(options) {
2048
2030
  currentMessages = [
2049
2031
  ...currentMessages,
2050
2032
  { role: "user", content: followUpPrompt },
2051
- { role: "assistant", content: followUpText },
2033
+ ...(followUpText
2034
+ ? [{ role: "assistant", content: followUpText }]
2035
+ : []),
2052
2036
  ];
2053
2037
  // --- Post-completion bookkeeping for follow-ups ---
2054
2038
  const followUpSteps = await followUpResult.steps;
@@ -2182,10 +2166,9 @@ export function createAgent(options) {
2182
2166
  // Build messages including this step's results
2183
2167
  const stepMessages = [
2184
2168
  ...initialParams.messages,
2185
- {
2186
- role: "assistant",
2187
- content: stepResult.text,
2188
- },
2169
+ ...(stepResult.text
2170
+ ? [{ role: "assistant", content: stepResult.text }]
2171
+ : []),
2189
2172
  ];
2190
2173
  await saveCheckpoint(effectiveGenOptions.threadId, stepMessages, startStep + currentStepCount);
2191
2174
  }
@@ -2204,7 +2187,9 @@ export function createAgent(options) {
2204
2187
  if (effectiveGenOptions.threadId && options.checkpointer) {
2205
2188
  const finalMessages = [
2206
2189
  ...initialParams.messages,
2207
- { role: "assistant", content: finishResult.text },
2190
+ ...(finishResult.text
2191
+ ? [{ role: "assistant", content: finishResult.text }]
2192
+ : []),
2208
2193
  ];
2209
2194
  await saveCheckpoint(effectiveGenOptions.threadId, finalMessages, startStep + finishResult.steps.length);
2210
2195
  }
@@ -2405,7 +2390,7 @@ export function createAgent(options) {
2405
2390
  let accumulatedStepCount = initialSteps.length;
2406
2391
  let currentMessages = [
2407
2392
  ...messages,
2408
- { role: "assistant", content: text },
2393
+ ...(text ? [{ role: "assistant", content: text }] : []),
2409
2394
  ];
2410
2395
  let followUpPrompt = await getNextTaskPrompt();
2411
2396
  while (followUpPrompt !== null) {
@@ -2432,7 +2417,9 @@ export function createAgent(options) {
2432
2417
  currentMessages = [
2433
2418
  ...currentMessages,
2434
2419
  { role: "user", content: followUpPrompt },
2435
- { role: "assistant", content: followUpText },
2420
+ ...(followUpText
2421
+ ? [{ role: "assistant", content: followUpText }]
2422
+ : []),
2436
2423
  ];
2437
2424
  // --- Post-completion bookkeeping for follow-ups ---
2438
2425
  const followUpSteps = await followUpResult.steps;
@@ -2511,17 +2498,6 @@ export function createAgent(options) {
2511
2498
  delete runtimeTools[name];
2512
2499
  }
2513
2500
  },
2514
- loadTools(toolNames) {
2515
- if (!toolRegistry) {
2516
- // No registry in eager mode - all tools already loaded
2517
- return { loaded: [], notFound: toolNames };
2518
- }
2519
- const result = toolRegistry.load(toolNames);
2520
- return {
2521
- loaded: result.loaded,
2522
- notFound: result.notFound,
2523
- };
2524
- },
2525
2501
  setPermissionMode(mode) {
2526
2502
  permissionMode = mode;
2527
2503
  },