Merge #86 into develop from feature/20251219_myh
fix(workflow): prevent duplicate conditional branches in if-else nodes * feature/20251219_myh: (3 commits squashed) - perf(workflow): adjust default template to be compatible with frontend format - fix: correct function naming for memory retrieval - fix(workflow): prevent duplicate conditional branches in if-else nodes Signed-off-by: Eternity <1533512157@qq.com> Reviewed-by: aliyun6762716068 <accounts_68cb7c6b61f5dcc4200d6251@mail.teambition.com> Merged-by: aliyun6762716068 <accounts_68cb7c6b61f5dcc4200d6251@mail.teambition.com> CR-link: https://codeup.aliyun.com/redbearai/python/redbear-mem-open/change/86
This commit is contained in:
@@ -307,22 +307,30 @@ class WorkflowExecutor:
|
|||||||
|
|
||||||
if condition:
|
if condition:
|
||||||
# 条件边
|
# 条件边
|
||||||
def router(state: WorkflowState, cond=condition, tgt=target):
|
def make_router(cond, tgt):
|
||||||
"""条件路由函数"""
|
"""Dynamically generate a conditional router function to ensure each branch has a unique name."""
|
||||||
if evaluate_condition(
|
|
||||||
cond,
|
|
||||||
state.get("variables", {}),
|
|
||||||
state.get("node_outputs", {}),
|
|
||||||
{
|
|
||||||
"execution_id": state.get("execution_id"),
|
|
||||||
"workspace_id": state.get("workspace_id"),
|
|
||||||
"user_id": state.get("user_id")
|
|
||||||
}
|
|
||||||
):
|
|
||||||
return tgt
|
|
||||||
return END # 条件不满足,结束
|
|
||||||
|
|
||||||
workflow.add_conditional_edges(source, router)
|
|
||||||
|
def router_fn(state: WorkflowState):
|
||||||
|
if evaluate_condition(
|
||||||
|
cond,
|
||||||
|
state.get("variables", {}),
|
||||||
|
state.get("node_outputs", {}),
|
||||||
|
{
|
||||||
|
"execution_id": state.get("execution_id"),
|
||||||
|
"workspace_id": state.get("workspace_id"),
|
||||||
|
"user_id": state.get("user_id")
|
||||||
|
}
|
||||||
|
):
|
||||||
|
return tgt
|
||||||
|
return END
|
||||||
|
|
||||||
|
# 动态修改函数名,避免重复
|
||||||
|
router_fn.__name__ = f"router_{tgt}"
|
||||||
|
return router_fn
|
||||||
|
|
||||||
|
router_fn = make_router(condition, target)
|
||||||
|
workflow.add_conditional_edges(source, router_fn)
|
||||||
logger.debug(f"添加条件边: {source} -> {target} (condition={condition})")
|
logger.debug(f"添加条件边: {source} -> {target} (condition={condition})")
|
||||||
else:
|
else:
|
||||||
# 普通边
|
# 普通边
|
||||||
|
|||||||
Reference in New Issue
Block a user