[Python] Langgraph: Getting ValueError: Found edge ending at unknown node `<function chatbot...

Discussão em 'Python' iniciado por Stack, Abril 23, 2025.

  1. Stack

    Stack Membro Participativo

    As part of experimenting Langgraph, i created below flow

    def chatbot(state:State):
    return {"messages":llm.invoke(state['messages'])}

    def chat_history(state:State):
    global chat_history
    chat_history.append(state["messages"])
    return state

    def product_rec_prompt(state: State):
    prompt_template = ChatPromptTemplate.from_messages(["prompt to get recommended product
    from user query"])
    formated_prompt = prompt_template.format_messages(topic=str(user_input))
    response = llm.invoke(prompt_template.invoke(formated_prompt))
    print(response)
    return state


    i added below flow and edge case

    graph_builder.add_node("chatbot", chatbot)
    graph_builder.add_edge(START, chatbot)
    graph_builder.set_entry_point("chatbot")

    graph_builder.add_node("chat_history",chat_history)

    graph_builder.add_node("product_rec_prompt", product_rec_prompt)

    # Define edge case to use chat history and recoomndation
    graph_builder.add_edge("chat_history", "product_rec_prompt")
    graph_builder.add_edge("product_rec_prompt", "chatbot")
    graph_builder.add_edge("chatbot", END)
    graph = graph_builder.compile()


    but i am getting below error

    raise ValueError(f"Found edge ending at unknown node `{target}`")
    ValueError: Found edge ending at unknown node `<function chatbot at 0x0000029C45B4FF40>`


    i hope the flow work as it is

    Chatbot -> Start -> call chat_history -> call product_rec_prompt -> END


    can you help with solution and right approach if applicable?

    Continue reading...

Compartilhe esta Página