This commit is contained in:
lda
2026-04-27 18:57:43 +07:00 Verified
parent 8a7fdb3297
commit 89d23a0ca0
2 changed files with 22 additions and 9 deletions
+6 -1
View File
@@ -10,7 +10,12 @@ from .model import (
StateSchema, StateSchema,
Workflow, Workflow,
) )
from .runtime import RuntimeContext, TraceEntry, WorkflowExecutionError, execute_workflow from .runtime import (
RuntimeContext,
TraceEntry,
WorkflowExecutionError,
execute_workflow,
)
from .validate import ValidationIssue, ValidationReport, validate_workflow from .validate import ValidationIssue, ValidationReport, validate_workflow
__all__ = [ __all__ = [
+16 -8
View File
@@ -56,7 +56,9 @@ def execute_workflow(
report = workflow.validate_structure() report = workflow.validate_structure()
report.raise_for_errors() report.raise_for_errors()
_validate_payload_against_schema(workflow.input_schema, workflow_input, "workflow input") _validate_payload_against_schema(
workflow.input_schema, workflow_input, "workflow input"
)
node_defs = {node_def.name: node_def for node_def in workflow.node_defs} node_defs = {node_def.name: node_def for node_def in workflow.node_defs}
nodes_by_id = {node.id: node for node in workflow.nodes} nodes_by_id = {node.id: node for node in workflow.nodes}
@@ -85,7 +87,9 @@ def execute_workflow(
) )
outcome = node_result["outcome"] outcome = node_result["outcome"]
elif isinstance(step, ConditionNode): elif isinstance(step, ConditionNode):
predicate = _eval_condition(step.check, state, workflow_input, prior_outcome) predicate = _eval_condition(
step.check, state, workflow_input, prior_outcome
)
outcome = "true" if predicate else "false" outcome = "true" if predicate else "false"
node_result = { node_result = {
"resolved_input": {}, "resolved_input": {},
@@ -127,7 +131,9 @@ def execute_workflow(
current_node_id = next_node_id current_node_id = next_node_id
final_output = _project_output(workflow, state) final_output = _project_output(workflow, state)
_validate_payload_against_schema(workflow.output_schema, final_output, "workflow output") _validate_payload_against_schema(
workflow.output_schema, final_output, "workflow output"
)
return { return {
"state": state, "state": state,
"output": final_output, "output": final_output,
@@ -147,7 +153,9 @@ def _execute_node_use(
) -> dict[str, Any]: ) -> dict[str, Any]:
handler = registry.get(node.node) handler = registry.get(node.node)
if handler is None: if handler is None:
raise WorkflowExecutionError(f"no handler registered for node def {node.node!r}") raise WorkflowExecutionError(
f"no handler registered for node def {node.node!r}"
)
resolved_input = { resolved_input = {
destination_field: _resolve_path(source_path, state, workflow_input, {}) destination_field: _resolve_path(source_path, state, workflow_input, {})
@@ -227,7 +235,9 @@ def _write_state_value(
current_value = _get_nested_value(state, key_path) current_value = _get_nested_value(state, key_path)
if merge_strategy == "append": if merge_strategy == "append":
if current_value is None: if current_value is None:
_set_nested_value(state, key_path, [value] if not isinstance(value, list) else value) _set_nested_value(
state, key_path, [value] if not isinstance(value, list) else value
)
return return
if not isinstance(current_value, list): if not isinstance(current_value, list):
raise WorkflowExecutionError( raise WorkflowExecutionError(
@@ -259,9 +269,7 @@ def _write_state_value(
def _project_output(workflow: Workflow, state: dict[str, Any]) -> dict[str, Any]: def _project_output(workflow: Workflow, state: dict[str, Any]) -> dict[str, Any]:
return { return {
key: state[key] key: state[key] for key in workflow.output_schema.properties if key in state
for key in workflow.output_schema.properties
if key in state
} }