@lleverage-ai/agent-sdk 0.0.6 → 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 +56 -95
  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,CAytFxD"}
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
792
- 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
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
798
751
  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
@@ -2526,17 +2498,6 @@ export function createAgent(options) {
2526
2498
  delete runtimeTools[name];
2527
2499
  }
2528
2500
  },
2529
- loadTools(toolNames) {
2530
- if (!toolRegistry) {
2531
- // No registry in eager mode - all tools already loaded
2532
- return { loaded: [], notFound: toolNames };
2533
- }
2534
- const result = toolRegistry.load(toolNames);
2535
- return {
2536
- loaded: result.loaded,
2537
- notFound: result.notFound,
2538
- };
2539
- },
2540
2501
  setPermissionMode(mode) {
2541
2502
  permissionMode = mode;
2542
2503
  },