-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
feature:Dynamic Workflow Mode Implementation for Conditional Edges #3345
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Skipped Deployment
|
2a4acb6
to
7a9bbe9
Compare
7a9bbe9
to
98bd643
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, this would change langgraph to be a library for DAGs, which is very much the opposite of what we want, as we started langgraph with the explicit goal of supporting graphs with cycles
@nfcampos My goal is to provide clients with low-code workflow configuration capabilities, offering functional nodes that users can freely arrange and combine as needed, without requiring programmers to manually write specific processes. In my practical tests, I found that only condition_edges had discrepancies with the actual execution results. To address this, I temporarily fixed the issue using a monkey patch. However, I recognize that this is not a long-term solution, which is why I submitted this PR to provide a more robust fix. For example, as shown in my previous example, I simply added a D node after the B node. This does not change the overall execution logic of the workflow, yet it results in completely different execution outcomes. Specifically, whether the E node executes once or twice depends not on the actual execution logic but on whether the number of nodes following the B and C nodes is consistent. I believe this execution behavior is not rigorous. These changes aim to provide a clearer and more reliable execution path for workflows. In fact,in my usage scenario, both langgraph with workflow_mode and langgraph without workflow_mode coexist simultaneously. The workflow is inherently a tool for user-defined processes, functioning similarly to other tools by providing output based on given input data. The PR I submitted is solely intended to fix issues in the original langgraph during workflow execution. Ultimately, the tools are invoked within agents, where the timing and repetition of calls are managed by the agent's langgraph (langgraph without workflow_mode). These two versions of langgraph can exist concurrently and operate completely independently without interfering with each other. |
d37f07d
to
7b725f8
Compare
7b725f8
to
263bbd9
Compare
Overview
Building upon the existing LangGraph framework, I developed and implemented a complete workflow in my project. I discovered that using
add_conditional_edges
in the workflow had certain flaws in executing subsequent nodes. By applying monkey patch, I temporarily fixed the issues related to conditional node execution within the workflow and designed an Analyzer to maintain the directed graph of execution paths. This improvement allows users to enable the new execution mode by settingworkflow_mode=True
during compilation. If not set or set toFalse
, the original execution mode is used by default. I hope this approach can be adopted.Problem Description
Prerequisite: In the workflow, each node should execute only once unless special handling logic is set.
When handling conditional branches with LangGraph, the following execution issues were discovered:
Set up a selector node (A) with two executable branches, Type 1 and Type 2:
When the results of both types point to Node E, LangGraph's parallel processing mechanism causes Node E to execute only once.
Attempts in Existing LangGraph:
Since each node is dynamically generated, specific branch paths cannot be determined before workflow execution. Therefore, it is necessary to dynamically choose the appropriate path during execution.
Solution
Added an Analyzer to LangGraph's source code to achieve the aforementioned requirements. Its main functionalities include:
Execution in this Case:
Through these improvements, each node executes only once within the workflow. The trigger conditions for subsequent nodes are dynamically adjusted based on the actual execution paths, catering to different types of text processing requirements.
Usage
To use the improved execution mode in LangGraph, set
workflow_mode=True
incompile
. The specific steps are as follows:Set the Option:
Add
workflow_mode=True
in the compilation configuration to enable the dynamic workflow mode.Note: When
workflow_mode=True
, either thepath_map
parameter or aLiteral
return is required. Only one of them is needed. Thepath_map
orLiteral
must cover all possible execution paths.Default Behavior:
If not set or if
workflow_mode
is set toFalse
, the original execution mode of LangGraph is used, maintaining backward compatibility.