@librechat/agents 3.0.40 → 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.
- package/dist/cjs/agents/AgentContext.cjs +44 -0
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +22 -15
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +44 -0
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +23 -16
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +16 -0
- package/dist/types/graphs/Graph.d.ts +1 -1
- package/package.json +1 -1
- package/src/agents/AgentContext.ts +53 -0
- package/src/graphs/Graph.ts +33 -17
package/src/graphs/Graph.ts
CHANGED
|
@@ -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'
|
|
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
|
-
|
|
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,16 +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
|
-
let currentModel = this.initializeModel({
|
|
853
|
-
tools: agentContext.tools,
|
|
854
|
-
provider: agentContext.provider,
|
|
855
|
-
clientOptions: agentContext.clientOptions,
|
|
856
|
-
});
|
|
857
|
-
|
|
858
|
-
if (agentContext.systemRunnable) {
|
|
859
|
-
currentModel = agentContext.systemRunnable.pipe(currentModel);
|
|
860
|
-
}
|
|
861
|
-
|
|
862
878
|
const agentNode = `${AGENT}${agentId}` as const;
|
|
863
879
|
const toolNode = `${TOOLS}${agentId}` as const;
|
|
864
880
|
|
|
@@ -878,7 +894,7 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
|
|
|
878
894
|
});
|
|
879
895
|
|
|
880
896
|
const workflow = new StateGraph(StateAnnotation)
|
|
881
|
-
.addNode(agentNode, this.createCallModel(agentId
|
|
897
|
+
.addNode(agentNode, this.createCallModel(agentId))
|
|
882
898
|
.addNode(
|
|
883
899
|
toolNode,
|
|
884
900
|
this.initializeTools({
|