Compiled app.getGraph() throws an exception
Checked other resources
- [X] I added a very descriptive title to this issue.
- [X] I searched the LangChain documentation with the integrated search.
- [X] I used the GitHub search to find a similar question and didn't find it.
- [X] I am sure that this is a bug in LangChain rather than my code.
Example Code
The graph was initialized as the following:
graph = StateGraph(GraphState)
from IPython.display import display, HTML
import base64
def display_image(image_bytes: bytes, width=300):
decoded_img_bytes = base64.b64encode(image_bytes).decode('utf-8')
html = f'<img src="data:image/png;base64,{decoded_img_bytes}" style="width: {width}px;" />'
display(HTML(html))
import nest_asyncio
from langchain_core.runnables.graph import CurveStyle, NodeColors, MermaidDrawMethod
nest_asyncio.apply() # Required for Jupyter Notebook to run async functions
display_image(app.get_graph().draw_mermaid_png(
curve_style=CurveStyle.LINEAR,
node_colors=NodeColors(start="#ffdfba", end="#baffc9", other="#fad7de"),
wrap_label_n_words=9,
output_file_path=None,
draw_method=MermaidDrawMethod.PYPPETEER,
background_color="white",
padding=10
))
Error Message and Stack Trace (if applicable)
RuntimeError Traceback (most recent call last) Cell In[84], line 6 2 from langchain_core.runnables.graph import CurveStyle, NodeColors, MermaidDrawMethod 4 nest_asyncio.apply() # Required for Jupyter Notebook to run async functions ----> 6 display_image(app.get_graph().draw_mermaid_png( 7 curve_style=CurveStyle.LINEAR, 8 node_colors=NodeColors(start="#ffdfba", end="#baffc9", other="#fad7de"), 9 wrap_label_n_words=9, 10 output_file_path=None, 11 draw_method=MermaidDrawMethod.PYPPETEER, 12 background_color="white", 13 padding=10 14 )) ... --> 760 raise RuntimeError(f'error checking inheritance of {type_!r} (type: {display_as_type(type_)})') 762 if config.arbitrary_types_allowed: 763 yield make_arbitrary_type_validator(type_) RuntimeError: error checking inheritance of <built-in function any> (type: builtin_function_or_method)
Description
No exception, graph drawn and visialized within the Jupyter notebook
System Info
System Information
OS: Linux OS Version: #111-Ubuntu SMP Tue Mar 5 20:16:58 UTC 2024 Python Version: 3.10.13 (main, Sep 11 2023, 13:44:35) [GCC 11.2.0]
Package Information
langchain_core: 0.1.45 langchain: 0.1.16 langchain_community: 0.0.34 langsmith: 0.1.45 langchain_chroma: 0.1.0 langchain_experimental: 0.0.55 langchain_openai: 0.1.1 langchain_text_splitters: 0.0.1 langchainhub: 0.1.15 langgraph: 0.0.38
Packages not installed (Not Necessarily a Problem)
The following packages were not found:
langserve
Issue is coming from the definition of GraphState that's passed to langgraph.graph.StateGraph.
If all any is updated to typing.Any in the GraphState definition, the get_graph method can run with no issues.
from typing import Dict, Optional, TypedDict, Any
class GraphState(TypedDict):
"""
Represents the state of our graph.
Attributes:
keys: A dictionary of keys.
tools: A dictionary of tools.
"""
keys: Dict[str, Any]
tools: Dict[str, Any]
hi @kenichinakanishi thanks for looking into this, given this arises from user error, any is a builtin function to work with iterables, not a typing annotation, I don't really want to add code to the library to handle this?
Thanks @nfcampos! You're right.
I've had a search, and none of the examples in the repo have an incorrect use of any in any TypedDict state definition, so I've closed the PR - no fixes needed.