Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LangGraph Studio (mac) -> AttributeError: module 'mvgbxnshzyfjxntsvqcqbkah' has no attribute 'graph' #2316

Open
5 tasks done
acsankar opened this issue Nov 4, 2024 · 6 comments

Comments

@acsankar
Copy link

acsankar commented Nov 4, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangGraph/LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangGraph/LangChain rather than my code.
  • I am sure this is better as an issue rather than a GitHub discussion, since this is a LangGraph bug and not a design question.

Example Code

def create_workflow() -> StateGraph:
    """Create the workflow graph with conditional routing"""
    
    # Initialize workflow with State type
    workflow = StateGraph(State)
    
    # Define routing function
    def router(state: State) -> str:
        """Route based on state's next value"""
        return state.get('next', 'triage')
    
    # Add nodes
    workflow.add_node("triage", triage_agent)
    workflow.add_node("data_agent", data_agent)
    workflow.add_node("access_agent", access_agent)
    workflow.add_node("human_in_loop", human_in_loop)
    
    # Set entry point
    workflow.set_entry_point("triage")
    
    # Add conditional edges from triage
    workflow.add_conditional_edges(
        "triage",
        router,
        {
            "data_agent": "data_agent",
            "access_agent": "access_agent",
            "human_in_loop": "human_in_loop"
        }
    )
    
    # Add conditional edges from human_in_loop
    workflow.add_conditional_edges(
        "human_in_loop",
        router,
        {
            "data_agent": "data_agent",
            "access_agent": "access_agent",
            "end": END
        }
    )
    
    # Add edges to END from agents
    workflow.add_conditional_edges(
        "data_agent",
        lambda x: "end",
        {"end": END}
    )
    
    workflow.add_conditional_edges(
        "access_agent",
        lambda x: "end",
        {"end": END}
    )
    
    return workflow.compile()

Error Message and Stack Trace (if applicable)

Failed to start project lang4
error | Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 693, in lifespan
    async with self.lifespan_context(app) as maybe_state:
  File "/usr/local/lib/python3.11/contextlib.py", line 210, in __aenter__
    return await anext(self.gen)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/api/langgraph_api/lifespan.py", line 30, in lifespan
  File "/api/langgraph_api/shared/graph.py", line 230, in collect_graphs_from_env
  File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/config.py", line 588, in run_in_executor
    return await asyncio.get_running_loop().run_in_executor(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/config.py", line 579, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/api/langgraph_api/shared/graph.py", line 276, in _graph_from_spec
AttributeError: module 'mvgbxnshzyfjxntsvqcqbkah' has no attribute 'graph'

Description

I am trying to load the folder to Langstudio (mac installation), i am getting the below issue:

File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/config.py", line 579, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/api/langgraph_api/shared/graph.py", line 276, in _graph_from_spec
AttributeError: module 'mvgbxnshzyfjxntsvqcqbkah' has no attribute 'graph'

System Info

]

@vbarda
Copy link
Collaborator

vbarda commented Nov 4, 2024

@acsankar could you share your langgraph.json? it sounds like you don't have a variable called graph with the compiled graph in the .py file you're trying to load the graph from

@acsankar
Copy link
Author

acsankar commented Nov 4, 2024

@acsankar could you share your langgraph.json? it sounds like you don't have a variable called graph with the compiled graph in the .py file you're trying to load the graph from

{
"dockerfile_lines": [],
"graphs": {
"agent": "./main.py:graph"
},
"env": [
"HK"
],
"python_version": "3.11",
"dependencies": [
"."
]
}

@acsankar
Copy link
Author

acsankar commented Nov 4, 2024

below is the structure of the code setup. i am able to make it work in Streamlit but not able to loan in Langgraph studio due to the issue mentioned
image

@vbarda
Copy link
Collaborator

vbarda commented Nov 6, 2024

and just to confirm -- you have a variable like graph = create_workflow() in main.py, right?

@acsankar
Copy link
Author

acsankar commented Nov 7, 2024

Below is the code

def create_workflow() -> Graph:
"""Create the workflow graph"""
workflow = Graph()

# Add nodes
workflow.add_node("triage", triage_agent)
workflow.add_node("data_agent", data_agent)
workflow.add_node("access_agent", access_agent)
workflow.add_node("human_in_loop", human_in_loop)

# Add edges
workflow.set_entry_point("triage")
workflow.add_edge('triage', 'data_agent')
workflow.add_edge('triage', 'access_agent')
workflow.add_edge('triage', 'human_in_loop')
workflow.add_edge('human_in_loop', 'data_agent')
workflow.add_edge('human_in_loop', 'access_agent')

return workflow.compile()

@vbarda
Copy link
Collaborator

vbarda commented Nov 8, 2024

Below is the code

def create_workflow() -> Graph: """Create the workflow graph""" workflow = Graph()

# Add nodes
workflow.add_node("triage", triage_agent)
workflow.add_node("data_agent", data_agent)
workflow.add_node("access_agent", access_agent)
workflow.add_node("human_in_loop", human_in_loop)

# Add edges
workflow.set_entry_point("triage")
workflow.add_edge('triage', 'data_agent')
workflow.add_edge('triage', 'access_agent')
workflow.add_edge('triage', 'human_in_loop')
workflow.add_edge('human_in_loop', 'data_agent')
workflow.add_edge('human_in_loop', 'access_agent')

return workflow.compile()

right, but do you save the output of create_workflow into a variable? if yes, then it should be named graph for your config to work. if no - you can also provide function names instead of variables like this:

"agent": "./main.py:create_workflow"

hope this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants