@@ -16,6 +16,7 @@ class LoopItems(BaseModel):
1616
1717class Process :
1818 DEFAULT_RETRY_LIMIT = 3 # Predefined retry limit in a common place
19+ VALIDATION_FAILURE_DECISIONS = ["invalid" , "retry" , "failed" , "error" , "unsuccessful" , "fail" , "errors" , "reject" , "rejected" , "incomplete" ] # Decision strings that trigger validation feedback
1920
2021 def __init__ (self , tasks : Dict [str , Task ], agents : List [Agent ], manager_llm : Optional [str ] = None , verbose : bool = False , max_iter : int = 10 ):
2122 logging .debug (f"=== Initializing Process ===" )
@@ -33,12 +34,21 @@ def __init__(self, tasks: Dict[str, Task], agents: List[Agent], manager_llm: Opt
3334 self .task_retry_counter : Dict [str , int ] = {} # Initialize retry counter
3435 self .workflow_finished = False # ADDED: Workflow finished flag
3536
37+ def _create_loop_subtasks (self , loop_task : Task ):
38+ """Create subtasks for a loop task from input file."""
39+ logging .warning (f"_create_loop_subtasks called for { loop_task .name } but method not fully implemented" )
40+ # TODO: Implement loop subtask creation from input file
41+ # This should read loop_task.input_file and create subtasks
42+ pass
43+
3644 def _build_task_context (self , current_task : Task ) -> str :
3745 """Build context for a task based on its retain_full_context setting"""
3846 # Check if we have validation feedback to include
3947 if current_task .validation_feedback :
4048 feedback = current_task .validation_feedback
4149 context = f"\n Previous attempt failed validation with reason: { feedback ['validation_response' ]} "
50+ if feedback .get ('validated_task' ):
51+ context += f"\n Validated task: { feedback ['validated_task' ]} "
4252 if feedback .get ('validation_details' ):
4353 context += f"\n Validation feedback: { feedback ['validation_details' ]} "
4454 if feedback .get ('rejected_output' ):
@@ -515,23 +525,32 @@ async def aworkflow(self) -> AsyncGenerator[str, None]:
515525 next_task .status = "not started" # Reset status to allow execution
516526
517527 # Capture validation feedback for retry scenarios
518- if decision_str in [ "invalid" , "retry" , "failed" , "error" , "unsuccessful" ] :
528+ if decision_str in Process . VALIDATION_FAILURE_DECISIONS :
519529 if current_task and current_task .result :
520530 # Get the rejected output from the task that was validated
521531 validated_task = None
522532 # Find the task that produced the output being validated
523533 if current_task .previous_tasks :
534+ # For validation tasks, typically validate the most recent previous task
524535 prev_task_name = current_task .previous_tasks [- 1 ]
525536 validated_task = next ((t for t in self .tasks .values () if t .name == prev_task_name ), None )
537+ elif current_task .context :
538+ # If no previous_tasks, check context for the validated task
539+ # Use the most recent task with a result from context
540+ for ctx_task in reversed (current_task .context ):
541+ if ctx_task .result and ctx_task .name != current_task .name :
542+ validated_task = ctx_task
543+ break
526544
527545 feedback = {
528546 'validation_response' : decision_str ,
529547 'validation_details' : current_task .result .raw ,
530548 'rejected_output' : validated_task .result .raw if validated_task and validated_task .result else None ,
531- 'validator_task' : current_task .name
549+ 'validator_task' : current_task .name ,
550+ 'validated_task' : validated_task .name if validated_task else None
532551 }
533552 next_task .validation_feedback = feedback
534- logging .debug (f"Added validation feedback to { next_task .name } : { feedback ['validation_response' ]} " )
553+ logging .debug (f"Added validation feedback to { next_task .name } : { feedback ['validation_response' ]} (validated task: { feedback . get ( 'validated_task' , 'None' ) } ) " )
535554
536555 logging .debug (f"Routing to { next_task .name } based on decision: { decision_str } " )
537556 # Don't mark workflow as finished when following condition path
@@ -1137,23 +1156,32 @@ def workflow(self):
11371156 next_task .status = "not started" # Reset status to allow execution
11381157
11391158 # Capture validation feedback for retry scenarios
1140- if decision_str in [ "invalid" , "retry" , "failed" , "error" , "unsuccessful" ] :
1159+ if decision_str in Process . VALIDATION_FAILURE_DECISIONS :
11411160 if current_task and current_task .result :
11421161 # Get the rejected output from the task that was validated
11431162 validated_task = None
11441163 # Find the task that produced the output being validated
11451164 if current_task .previous_tasks :
1165+ # For validation tasks, typically validate the most recent previous task
11461166 prev_task_name = current_task .previous_tasks [- 1 ]
11471167 validated_task = next ((t for t in self .tasks .values () if t .name == prev_task_name ), None )
1168+ elif current_task .context :
1169+ # If no previous_tasks, check context for the validated task
1170+ # Use the most recent task with a result from context
1171+ for ctx_task in reversed (current_task .context ):
1172+ if ctx_task .result and ctx_task .name != current_task .name :
1173+ validated_task = ctx_task
1174+ break
11481175
11491176 feedback = {
11501177 'validation_response' : decision_str ,
11511178 'validation_details' : current_task .result .raw ,
11521179 'rejected_output' : validated_task .result .raw if validated_task and validated_task .result else None ,
1153- 'validator_task' : current_task .name
1180+ 'validator_task' : current_task .name ,
1181+ 'validated_task' : validated_task .name if validated_task else None
11541182 }
11551183 next_task .validation_feedback = feedback
1156- logging .debug (f"Added validation feedback to { next_task .name } : { feedback ['validation_response' ]} " )
1184+ logging .debug (f"Added validation feedback to { next_task .name } : { feedback ['validation_response' ]} (validated task: { feedback . get ( 'validated_task' , 'None' ) } ) " )
11571185
11581186 logging .debug (f"Routing to { next_task .name } based on decision: { decision_str } " )
11591187 # Don't mark workflow as finished when following condition path
0 commit comments