mirror of
https://github.com/langchain-ai/langgraphjs.git
synced 2026-07-22 17:15:25 -04:00
fix(api): access graph to obtain the actual graph when using createAgent (#1751)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@langchain/langgraph-api": patch
|
||||
---
|
||||
|
||||
Hotfix graph resolution for createAgent
|
||||
@@ -55,6 +55,17 @@ export async function resolveGraph(
|
||||
return "compile" in graph && typeof graph.compile === "function";
|
||||
};
|
||||
|
||||
const isCompiledGraph = (
|
||||
graph: GraphLike
|
||||
): graph is CompiledGraph<string> => {
|
||||
if (typeof graph !== "object" || graph == null) return false;
|
||||
return (
|
||||
"builder" in graph &&
|
||||
typeof graph.builder === "object" &&
|
||||
graph.builder != null
|
||||
);
|
||||
};
|
||||
|
||||
const graph: GraphUnknown = await import(
|
||||
pathToFileURL(sourceFile).toString()
|
||||
).then((module) => module[exportSymbol || "default"]);
|
||||
@@ -66,6 +77,11 @@ export async function resolveGraph(
|
||||
|
||||
const afterResolve = (graphLike: GraphLike): CompiledGraph<string> => {
|
||||
const graph = isGraph(graphLike) ? graphLike.compile() : graphLike;
|
||||
|
||||
// TODO: hack, remove once LangChain 1.x createAgent is fixed
|
||||
if (!isCompiledGraph(graph) && "graph" in graph) {
|
||||
return (graph as { graph: CompiledGraph<string> }).graph;
|
||||
}
|
||||
return graph;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user