@langgraph-js/sdk
Version:
The UI SDK for LangGraph - seamlessly integrate your AI agents with frontend interfaces
38 lines (37 loc) • 1.08 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 createFETool = (tool) => {
return tool;
};
export const createFeTools = (tools) => {
return tools
.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",
});
};