fix(workflow): handle missing environment variable defaults
This commit is contained in:
@@ -14,6 +14,7 @@ from langgraph.graph.state import CompiledStateGraph
|
|||||||
|
|
||||||
from app.core.workflow.graph_builder import GraphBuilder
|
from app.core.workflow.graph_builder import GraphBuilder
|
||||||
from app.core.workflow.nodes import WorkflowState
|
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.workflow.nodes.enums import NodeType
|
||||||
|
|
||||||
# from app.core.tools.registry import ToolRegistry
|
# from app.core.tools.registry import ToolRegistry
|
||||||
@@ -78,9 +79,21 @@ class WorkflowExecutor:
|
|||||||
var_name = var_def.get("name")
|
var_name = var_def.get("name")
|
||||||
var_default = var_def.get("default")
|
var_default = var_def.get("default")
|
||||||
if var_name:
|
if var_name:
|
||||||
# TODO: 入参类型校验
|
if var_default:
|
||||||
conversation_vars[var_name] = 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 节点的自定义变量
|
input_variables = input_data.get("variables") or {} # Start 节点的自定义变量
|
||||||
|
|
||||||
# 构建分层的变量结构
|
# 构建分层的变量结构
|
||||||
@@ -362,7 +375,7 @@ class WorkflowExecutor:
|
|||||||
inputv = payload.get("input", {})
|
inputv = payload.get("input", {})
|
||||||
variables = inputv.get("variables", {})
|
variables = inputv.get("variables", {})
|
||||||
variables_sys = variables.get("sys", {})
|
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")
|
execution_id = variables_sys.get("execution_id")
|
||||||
logger.info(f"[DEBUG] Node starts execution: {node_name}")
|
logger.info(f"[DEBUG] Node starts execution: {node_name}")
|
||||||
|
|
||||||
@@ -381,7 +394,7 @@ class WorkflowExecutor:
|
|||||||
inputv = result.get("input", {})
|
inputv = result.get("input", {})
|
||||||
variables = inputv.get("variables", {})
|
variables = inputv.get("variables", {})
|
||||||
variables_sys = variables.get("sys", {})
|
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")
|
execution_id = variables_sys.get("execution_id")
|
||||||
logger.info(f"[DEBUG] Node execution completed: {node_name}")
|
logger.info(f"[DEBUG] Node execution completed: {node_name}")
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ from app.core.workflow.nodes.enums import NodeType
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
# TODO: 子图拆解支持
|
|
||||||
class GraphBuilder:
|
class GraphBuilder:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ class AssignerNode(BaseNode):
|
|||||||
|
|
||||||
# Get the value or expression to assign
|
# Get the value or expression to assign
|
||||||
value = assignment.value
|
value = assignment.value
|
||||||
|
logger.debug(f"left:{variable_selector}, right: {value}")
|
||||||
pattern = r"\{\{\s*(.*?)\s*\}\}"
|
pattern = r"\{\{\s*(.*?)\s*\}\}"
|
||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
expression = re.match(pattern, value)
|
expression = re.match(pattern, value)
|
||||||
@@ -85,4 +86,3 @@ class AssignerNode(BaseNode):
|
|||||||
case _:
|
case _:
|
||||||
raise ValueError(f"Invalid Operator: {assignment.operation}")
|
raise ValueError(f"Invalid Operator: {assignment.operation}")
|
||||||
logger.info(f"Node {self.node_id}: execution completed")
|
logger.info(f"Node {self.node_id}: execution completed")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user