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

The node is followed by one conditional_edges, and the state update is returned at the node. As a result, conditional_edges are updated twice after the return #2550

Open
5 tasks done
Panda-eat-meat opened this issue Nov 27, 2024 · 0 comments

Comments

@Panda-eat-meat
Copy link

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

# code likes like this

def add_message(left_message, right_message):
    print("add_message: ", left_message, right_message)
    if isinstance(left_message, list) and isinstance(right_message, list):
        left_message.extend(right_message)
    elif isinstance(left_message, list):
        left_message.append(right_message)
    else:
        left_message = right_message
    print("add_message end: ", left_message)
    return left_message



class MainState(TypedDict):
    history_diag: Annotated[List[Union[UserMessage, SystemMessage, str, int]], add_message]



async def build_graph(self):
    ********some node************

    self.workflow.add_node("node 1", self.node_1)
    self.workflow.add_node("daozhen_node_get_next_question_wrap", self.node_get_next_question_wrap)
    self.workflow.add_edge("daozhen_node_get_next_question", "daozhen_node_get_next_question_wrap")

    self.workflow.add_conditional_edges("daozhen_node_get_next_question_wrap", self.edge_conditional_res_route, ["node 1","node 2"])
    return self



async def edge_conditional_res_route(self, state: MainState):
    if is_end or jump_out:
        return "node 1"
    else:
        return "node 2"



async def node_get_next_question_wrap(self, state: MainState):
    append_message = [1, 2]
    return {"history_diag": append_message}



async def node_1(self, state: MainState):
    print(state["history_diag"])
    # get [1, 2, 1, 2], bug just update once

Error Message and Stack Trace (if applicable)

No response

Description

One node is called node1. Following the node, conditional_edges returns to update one field of the state. As a result, conditional_edges returns are updated twice. But if I insert a node between node1 and conditional_edges that doesn't return anything, it won't repeat

System Info

macbook m3

lang version:
langchain 0.3.7
langchain-anthropic 0.2.3
langchain-core 0.3.15
langchain-text-splitters 0.3.2
langgraph 0.2.53
langgraph-checkpoint 2.0.6
langgraph-checkpoint-postgres 2.0.2
langgraph-sdk 0.1.35
langsmith 0.1.137

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

1 participant