@langgraph-js/pro
Version:
The Pro SDK for LangGraph - seamlessly integrate your AI agents with frontend interfaces and build complex AI workflows
42 lines (41 loc) • 1.25 kB
JavaScript
import { interrupt } from "@langchain/langgraph";
import { createDefaultAnnotation } from "./createState.js";
import { DynamicStructuredTool } from "@langchain/core/tools";
import { createState } from "./createState.js";
export const FEToolsState = createState().build({
fe_tools: createDefaultAnnotation(() => []),
});
export const createFeTools = (tools,
/** 通过归属的 agent 的名称,来过滤出指定的工具 */
agentName) => {
return tools
.filter((i) => {
if (!i.allowAgent || !agentName)
return true;
return i.allowAgent.includes(agentName);
})
.map((tool) => {
try {
return actionToTool(tool);
}
catch (e) {
console.error(e);
return null;
}
})
.filter((tool) => tool !== null);
};
export const actionToTool = (tool) => {
const callTool = async (args) => {
const data = interrupt(JSON.stringify(args));
return [data, null];
};
const schema = tool.parameters;
return new DynamicStructuredTool({
name: tool.name,
description: tool.description || "",
schema,
func: callTool,
responseFormat: "content_and_artifact",
});
};