fix(workflow): handle missing environment variable defaults

This commit is contained in:
mengyonghao
2026-01-13 15:09:06 +08:00
parent dd7abc0d27
commit 592c2ac217
3 changed files with 19 additions and 7 deletions

View File

@@ -14,6 +14,7 @@ from langgraph.graph.state import CompiledStateGraph
from app.core.workflow.graph_builder import GraphBuilder
from app.core.workflow.nodes import WorkflowState
from app.core.workflow.nodes.base_config import VariableType
from app.core.workflow.nodes.enums import NodeType
# from app.core.tools.registry import ToolRegistry
@@ -78,9 +79,21 @@ class WorkflowExecutor:
var_name = var_def.get("name")
var_default = var_def.get("default")
if var_name:
# TODO: 入参类型校验
conversation_vars[var_name] = var_default
if var_default:
conversation_vars[var_name] = var_default
else:
var_type = var_def.get("type")
match var_type:
case VariableType.STRING:
conversation_vars[var_name] = ""
case VariableType.NUMBER:
conversation_vars[var_name] = 0
case VariableType.OBJECT:
conversation_vars[var_name] = {}
case VariableType.BOOLEAN:
conversation_vars[var_name] = False
case VariableType.ARRAY_NUMBER | VariableType.ARRAY_OBJECT | VariableType.ARRAY_BOOLEAN | VariableType.ARRAY_STRING:
conversation_vars[var_name] = []
input_variables = input_data.get("variables") or {} # Start 节点的自定义变量
# 构建分层的变量结构
@@ -362,7 +375,7 @@ class WorkflowExecutor:
inputv = payload.get("input", {})
variables = inputv.get("variables", {})
variables_sys = variables.get("sys", {})
conversation_id = variables_sys.get("conversation_id")
conversation_id = input_data.get("conversation_id")
execution_id = variables_sys.get("execution_id")
logger.info(f"[DEBUG] Node starts execution: {node_name}")
@@ -381,7 +394,7 @@ class WorkflowExecutor:
inputv = result.get("input", {})
variables = inputv.get("variables", {})
variables_sys = variables.get("sys", {})
conversation_id = variables_sys.get("conversation_id")
conversation_id = input_data.get("conversation_id")
execution_id = variables_sys.get("execution_id")
logger.info(f"[DEBUG] Node execution completed: {node_name}")

View File

@@ -12,7 +12,6 @@ from app.core.workflow.nodes.enums import NodeType
logger = logging.getLogger(__name__)
# TODO: 子图拆解支持
class GraphBuilder:
def __init__(
self,

View File

@@ -45,6 +45,7 @@ class AssignerNode(BaseNode):
# Get the value or expression to assign
value = assignment.value
logger.debug(f"left:{variable_selector}, right: {value}")
pattern = r"\{\{\s*(.*?)\s*\}\}"
if isinstance(value, str):
expression = re.match(pattern, value)
@@ -85,4 +86,3 @@ class AssignerNode(BaseNode):
case _:
raise ValueError(f"Invalid Operator: {assignment.operation}")
logger.info(f"Node {self.node_id}: execution completed")