@librechat/agents 3.0.41 → 3.0.42

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.
@@ -35,6 +35,7 @@ import {
35
35
  GraphEvents,
36
36
  Providers,
37
37
  StepTypes,
38
+ Constants,
38
39
  } from '@/common';
39
40
  import {
40
41
  formatAnthropicArtifactContent,
@@ -608,7 +609,7 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
608
609
  client.abortHandler = undefined;
609
610
  }
610
611
 
611
- createCallModel(agentId = 'default', currentModel?: t.ChatModel) {
612
+ createCallModel(agentId = 'default') {
612
613
  return async (
613
614
  state: t.BaseGraphState,
614
615
  config?: RunnableConfig
@@ -621,15 +622,23 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
621
622
  throw new Error(`Agent context not found for agentId: ${agentId}`);
622
623
  }
623
624
 
624
- const model = this.overrideModel ?? currentModel;
625
- if (!model) {
626
- throw new Error('No Graph model found');
627
- }
628
625
  if (!config) {
629
626
  throw new Error('No config provided');
630
627
  }
631
628
 
632
- // Ensure token calculations are complete before proceeding
629
+ const toolsForBinding = agentContext.getToolsForBinding();
630
+ let model =
631
+ this.overrideModel ??
632
+ this.initializeModel({
633
+ tools: toolsForBinding,
634
+ provider: agentContext.provider,
635
+ clientOptions: agentContext.clientOptions,
636
+ });
637
+
638
+ if (agentContext.systemRunnable) {
639
+ model = agentContext.systemRunnable.pipe(model as Runnable);
640
+ }
641
+
633
642
  if (agentContext.tokenCalculationPromise) {
634
643
  await agentContext.tokenCalculationPromise;
635
644
  }
@@ -703,6 +712,23 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
703
712
 
704
713
  const isLatestToolMessage = lastMessageY instanceof ToolMessage;
705
714
 
715
+ if (
716
+ isLatestToolMessage &&
717
+ lastMessageY.name === Constants.TOOL_SEARCH_REGEX &&
718
+ typeof lastMessageY.artifact === 'object' &&
719
+ lastMessageY.artifact != null
720
+ ) {
721
+ const artifact = lastMessageY.artifact as {
722
+ tool_references?: Array<{ tool_name: string }>;
723
+ };
724
+ if (artifact.tool_references && artifact.tool_references.length > 0) {
725
+ const discoveredNames = artifact.tool_references.map(
726
+ (ref) => ref.tool_name
727
+ );
728
+ agentContext.markToolsAsDiscovered(discoveredNames);
729
+ }
730
+ }
731
+
706
732
  if (
707
733
  isLatestToolMessage &&
708
734
  agentContext.provider === Providers.ANTHROPIC
@@ -849,36 +875,6 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
849
875
  throw new Error(`Agent context not found for agentId: ${agentId}`);
850
876
  }
851
877
 
852
- // Filter tools for LLM binding: only tools with allowed_callers including 'direct'
853
- // Default: if allowed_callers is not specified, tool is bound to LLM (direct)
854
- let toolsForLLM = agentContext.tools;
855
- if (agentContext.toolRegistry != null && agentContext.tools != null) {
856
- toolsForLLM = agentContext.tools.filter((tool) => {
857
- const toolDef =
858
- 'name' in tool
859
- ? agentContext.toolRegistry?.get(tool.name)
860
- : undefined;
861
- if (!toolDef) {
862
- // Tool not in registry - bind to LLM by default
863
- return true;
864
- }
865
- if (!toolDef.allowed_callers) {
866
- return true;
867
- }
868
- return toolDef.allowed_callers.includes('direct');
869
- });
870
- }
871
-
872
- let currentModel = this.initializeModel({
873
- tools: toolsForLLM,
874
- provider: agentContext.provider,
875
- clientOptions: agentContext.clientOptions,
876
- });
877
-
878
- if (agentContext.systemRunnable) {
879
- currentModel = agentContext.systemRunnable.pipe(currentModel);
880
- }
881
-
882
878
  const agentNode = `${AGENT}${agentId}` as const;
883
879
  const toolNode = `${TOOLS}${agentId}` as const;
884
880
 
@@ -898,7 +894,7 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
898
894
  });
899
895
 
900
896
  const workflow = new StateGraph(StateAnnotation)
901
- .addNode(agentNode, this.createCallModel(agentId, currentModel))
897
+ .addNode(agentNode, this.createCallModel(agentId))
902
898
  .addNode(
903
899
  toolNode,
904
900
  this.initializeTools({