-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(langgraph): Adds error page for unreachable nodes (#741)
- Loading branch information
1 parent
3ef8ace
commit 403cd51
Showing
8 changed files
with
185 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# UNREACHABLE_NODE\n", | ||
"\n", | ||
"LangGraph cannot identify an incoming edge to one of your nodes. Check to ensure you have added sufficient edges when constructing your graph.\n", | ||
"\n", | ||
"Alternatively, if you are returning [`Command`](/langgraphjs/how-tos/command/) instances from your nodes to make your graphs edgeless, you will need to add an additional `ends` parameter when calling `addNode` to help LangGraph determine the destinations for your node.\n", | ||
"\n", | ||
"Here's an example:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import { Annotation, Command } from \"@langchain/langgraph\";\n", | ||
"\n", | ||
"const StateAnnotation = Annotation.Root({\n", | ||
" foo: Annotation<string>,\n", | ||
"});\n", | ||
"\n", | ||
"const nodeA = async (_state: typeof StateAnnotation.State) => {\n", | ||
" const goto = Math.random() > .5 ? \"nodeB\" : \"nodeC\";\n", | ||
" return new Command({\n", | ||
" update: { foo: \"a\" },\n", | ||
" goto,\n", | ||
" });\n", | ||
"};\n", | ||
"\n", | ||
"const nodeB = async (state: typeof StateAnnotation.State) => {\n", | ||
" return {\n", | ||
" foo: state.foo + \"|b\",\n", | ||
" };\n", | ||
"}\n", | ||
"\n", | ||
"const nodeC = async (state: typeof StateAnnotation.State) => {\n", | ||
" return {\n", | ||
" foo: state.foo + \"|c\",\n", | ||
" };\n", | ||
"}\n", | ||
"\n", | ||
"import { StateGraph } from \"@langchain/langgraph\";\n", | ||
"\n", | ||
"// NOTE: there are no edges between nodes A, B and C!\n", | ||
"const graph = new StateGraph(StateAnnotation)\n", | ||
" .addNode(\"nodeA\", nodeA, {\n", | ||
" // Explicitly specify \"nodeB\" and \"nodeC\" as potential destinations for nodeA\n", | ||
" ends: [\"nodeB\", \"nodeC\"],\n", | ||
" })\n", | ||
" .addNode(\"nodeB\", nodeB)\n", | ||
" .addNode(\"nodeC\", nodeC)\n", | ||
" .addEdge(\"__start__\", \"nodeA\")\n", | ||
" .compile();" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Troubleshooting\n", | ||
"\n", | ||
"The following may help resolve this error:\n", | ||
"\n", | ||
"- Make sure that you have not forgotten to add edges between some of your nodes.\n", | ||
"- If you are returning `Commands` from your nodes, make sure that you're passing an `ends` array with the names of potential destination nodes as shown above." | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "TypeScript", | ||
"language": "typescript", | ||
"name": "tslab" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"mode": "typescript", | ||
"name": "javascript", | ||
"typescript": true | ||
}, | ||
"file_extension": ".ts", | ||
"mimetype": "text/typescript", | ||
"name": "typescript", | ||
"version": "3.7.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters