feat: Phase 4 - Join Nodes and Path Consolidation
Backend Implementation (v0.9m, workflow 0.5.0): - join_evaluator.py (394 lines): Join-Strategie-Evaluator - evaluate_join_node(): Hauptlogik für Join-Node Execution - Join-Strategien: wait_all, wait_any, best_effort - Skip-Handling: ignore_skipped, use_placeholder, require_minimum - Result Consolidation: merge analysis_cores, combine signals - Partial Execution: korrekte Behandlung von SKIPPED/FAILED Pfaden - workflow_executor.py: execute_join_node() Integration - BFS-Traversierung erweitert für Join-Nodes - NodeExecutionState List → Dict Konvertierung für Signale - Signal-Name-Kollisionen via node_id Präfix gelöst Testing (49 Tests passing): - test_phase4_join_nodes.py: 18 neue Unit Tests - Join-Strategien (wait_all, wait_any, best_effort) - Skip-Handling (ignore, placeholder) - Result Consolidation (merge, combine) - Partial Execution (mixed status paths) - Helper Functions (collect, check, merge, combine) - Backward Compatibility: 31 Phase 2/3 Tests (alle passing) - test_phase2_workflow_executor.py: 1 Test aktualisiert - test_phase3_logic_evaluator.py: 20 Tests unverändert Konzept: konzept_workflow_engine_konsolidated.md (Sektion 8.8) Anforderungsanalyse: phase4_anforderungsanalyse.md Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
2ce0874dcb
commit
e2a132353d
5 files changed
+1039
-17
No files matched your search
@@ -1,13 +1,14 @@
|
||||
"""
|
||||
Workflow Executor (Phase 3)
|
||||
Workflow Executor (Phase 4)
|
||||
|
||||
Führt Workflows mit conditional branching aus (Logic Nodes).
|
||||
Führt Workflows mit conditional branching und path consolidation aus.
|
||||
|
||||
Phase 2: Sequential execution
|
||||
Phase 3: Conditional branching, Logic Nodes, Fallback strategies
|
||||
Phase 4: Join Nodes, Path consolidation
|
||||
|
||||
Konzept-Basis: konzept_workflow_engine_konsolidated.md
|
||||
Anforderungsanalyse: anforderungsanalyse_umsetzungsplan.md (Phase 2-3)
|
||||
Anforderungsanalyse: anforderungsanalyse_umsetzungsplan.md (Phase 2-4)
|
||||
"""
|
||||
from typing import Dict, Any, List, Optional, Set
|
||||
from datetime import datetime
|
||||
@@ -27,6 +28,7 @@ from question_augmenter import (
|
||||
from result_container_parser import parse_result_container
|
||||
from normalization_engine import normalize_all_signals, load_question_catalog
|
||||
from logic_evaluator import evaluate_logic_expression, resolve_signal_reference
|
||||
from join_evaluator import evaluate_join_node as evaluate_join_node_core
|
||||
from db import get_db, get_cursor
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -40,10 +42,11 @@ async def execute_workflow(
|
||||
enable_debug: bool = False
|
||||
) -> ExecutionResult:
|
||||
"""
|
||||
Führt einen Workflow aus (mit conditional branching).
|
||||
Führt einen Workflow aus (mit conditional branching und path consolidation).
|
||||
|
||||
Phase 2: Linear execution in topological order.
|
||||
Phase 3: Conditional branching basierend auf logic nodes.
|
||||
Phase 4: Join nodes und path consolidation.
|
||||
|
||||
Args:
|
||||
workflow_id: UUID des Workflows
|
||||
@@ -235,7 +238,7 @@ async def execute_node(
|
||||
- start/end: No-op
|
||||
- analysis: Load prompt → augment → LLM → parse → normalize
|
||||
- logic: Evaluate condition → activate/deactivate edges (Phase 3)
|
||||
- join: Not implemented (Phase 4)
|
||||
- join: Consolidate paths → merge results (Phase 4)
|
||||
"""
|
||||
started_at = datetime.utcnow().isoformat()
|
||||
|
||||
@@ -254,6 +257,10 @@ async def execute_node(
|
||||
if node.type == "logic":
|
||||
return execute_logic_node(node, context, graph)
|
||||
|
||||
# Join Nodes (Phase 4)
|
||||
if node.type == "join":
|
||||
return execute_join_node(node, context, graph)
|
||||
|
||||
# Analysis Nodes
|
||||
if node.type == "analysis":
|
||||
# 1. Lade Prompt
|
||||
@@ -411,6 +418,91 @@ def execute_logic_node(
|
||||
)
|
||||
|
||||
|
||||
def execute_join_node(
|
||||
node,
|
||||
context: Dict[str, Any],
|
||||
graph: WorkflowGraph
|
||||
) -> NodeExecutionState:
|
||||
"""
|
||||
Führt Join Node aus (Phase 4).
|
||||
|
||||
Args:
|
||||
node: WorkflowNode vom Typ "join"
|
||||
context: Execution context mit node_results
|
||||
graph: WorkflowGraph
|
||||
|
||||
Returns:
|
||||
NodeExecutionState mit konsolidierten Daten
|
||||
|
||||
Logic:
|
||||
1. Evaluiere Join-Strategie (via join_evaluator)
|
||||
2. Prüfe ob ready (alle erforderlichen Pfade verfügbar?)
|
||||
3. Konsolidiere Ergebnisse (merge analysis_core, combine signals)
|
||||
4. Return NodeExecutionState mit konsolidierten Daten
|
||||
|
||||
Error Handling:
|
||||
- wait_all + fehlende Pfade → FAILED
|
||||
- wait_any + keine Pfade → FAILED
|
||||
- best_effort + keine Pfade → EXECUTED (mit metadata)
|
||||
"""
|
||||
started_at = datetime.utcnow().isoformat()
|
||||
|
||||
try:
|
||||
logger.info(f"Executing join node: {node.id}")
|
||||
|
||||
# 1. Evaluiere Join-Node
|
||||
join_result = evaluate_join_node_core(node, graph, context)
|
||||
|
||||
# 2. Prüfe ob ready
|
||||
if not join_result.ready:
|
||||
# Strategie nicht erfüllt → FAILED
|
||||
logger.warning(f"Join node {node.id}: Not ready - {join_result.error}")
|
||||
return NodeExecutionState(
|
||||
node_id=node.id,
|
||||
status=NodeStatus.FAILED,
|
||||
error=join_result.error,
|
||||
started_at=started_at,
|
||||
completed_at=datetime.utcnow().isoformat(),
|
||||
metadata=join_result.metadata
|
||||
)
|
||||
|
||||
# 3. Baue konsolidierten analysis_core
|
||||
# Format: JSON mit node_id → analysis_core mapping
|
||||
consolidated_core_json = json.dumps(
|
||||
join_result.consolidated_analysis_core,
|
||||
ensure_ascii=False,
|
||||
indent=2
|
||||
)
|
||||
|
||||
# 4. Log Konsolidierung
|
||||
executed_count = join_result.metadata.get("executed_paths", 0)
|
||||
total_count = join_result.metadata.get("total_paths", 0)
|
||||
logger.info(
|
||||
f"Join node {node.id}: Consolidated {executed_count}/{total_count} paths"
|
||||
)
|
||||
|
||||
# 5. Return NodeExecutionState
|
||||
return NodeExecutionState(
|
||||
node_id=node.id,
|
||||
status=NodeStatus.EXECUTED,
|
||||
analysis_core=consolidated_core_json,
|
||||
normalized_signals=join_result.consolidated_signals,
|
||||
metadata=join_result.metadata,
|
||||
started_at=started_at,
|
||||
completed_at=datetime.utcnow().isoformat()
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Join node execution failed ({node.id}): {e}", exc_info=True)
|
||||
return NodeExecutionState(
|
||||
node_id=node.id,
|
||||
status=NodeStatus.FAILED,
|
||||
error=str(e),
|
||||
started_at=started_at,
|
||||
completed_at=datetime.utcnow().isoformat()
|
||||
)
|
||||
|
||||
|
||||
def _apply_fallback(
|
||||
node,
|
||||
graph: WorkflowGraph,
|
||||
|
||||
Reference in new issue
Block a user