@@ -35,10 +35,27 @@ def __init__(self, tasks: Dict[str, Task], agents: List[Agent], manager_llm: Opt
3535
3636 def _build_task_context (self , current_task : Task ) -> str :
3737 """Build context for a task based on its retain_full_context setting"""
38- if not (current_task .previous_tasks or current_task .context ):
39- return ""
38+ # Check if we have validation feedback to include
39+ if current_task .validation_feedback :
40+ feedback = current_task .validation_feedback
41+ context = f"\n Previous attempt failed validation with reason: { feedback ['validation_response' ]} "
42+ if feedback .get ('validation_details' ):
43+ context += f"\n Validation feedback: { feedback ['validation_details' ]} "
44+ if feedback .get ('rejected_output' ):
45+ context += f"\n Rejected output: { feedback ['rejected_output' ]} "
46+ context += "\n Please try again with a different approach based on this feedback.\n "
47+ # Clear the feedback after including it to prevent it from persisting
48+ current_task .validation_feedback = None
4049
41- context = "\n Input data from previous tasks:"
50+ # If we have validation feedback but no previous tasks context, return just the feedback
51+ if not (current_task .previous_tasks or current_task .context ):
52+ return context
53+ # Otherwise, append the regular context
54+ context += "\n Input data from previous tasks:"
55+ elif not (current_task .previous_tasks or current_task .context ):
56+ return ""
57+ else :
58+ context = "\n Input data from previous tasks:"
4259
4360 if current_task .retain_full_context :
4461 # Original behavior: include all previous tasks
@@ -496,6 +513,26 @@ async def aworkflow(self) -> AsyncGenerator[str, None]:
496513 next_task = next ((t for t in self .tasks .values () if t .name == task_value ), None )
497514 if next_task :
498515 next_task .status = "not started" # Reset status to allow execution
516+
517+ # Capture validation feedback for retry scenarios
518+ if decision_str in ["invalid" , "retry" , "failed" , "error" , "unsuccessful" ]:
519+ if current_task and current_task .result :
520+ # Get the rejected output from the task that was validated
521+ validated_task = None
522+ # Find the task that produced the output being validated
523+ if current_task .previous_tasks :
524+ prev_task_name = current_task .previous_tasks [- 1 ]
525+ validated_task = next ((t for t in self .tasks .values () if t .name == prev_task_name ), None )
526+
527+ feedback = {
528+ 'validation_response' : decision_str ,
529+ 'validation_details' : current_task .result .raw ,
530+ 'rejected_output' : validated_task .result .raw if validated_task and validated_task .result else None ,
531+ 'validator_task' : current_task .name
532+ }
533+ next_task .validation_feedback = feedback
534+ logging .debug (f"Added validation feedback to { next_task .name } : { feedback ['validation_response' ]} " )
535+
499536 logging .debug (f"Routing to { next_task .name } based on decision: { decision_str } " )
500537 # Don't mark workflow as finished when following condition path
501538 self .workflow_finished = False
@@ -1098,6 +1135,26 @@ def workflow(self):
10981135 next_task = next ((t for t in self .tasks .values () if t .name == task_value ), None )
10991136 if next_task :
11001137 next_task .status = "not started" # Reset status to allow execution
1138+
1139+ # Capture validation feedback for retry scenarios
1140+ if decision_str in ["invalid" , "retry" , "failed" , "error" , "unsuccessful" ]:
1141+ if current_task and current_task .result :
1142+ # Get the rejected output from the task that was validated
1143+ validated_task = None
1144+ # Find the task that produced the output being validated
1145+ if current_task .previous_tasks :
1146+ prev_task_name = current_task .previous_tasks [- 1 ]
1147+ validated_task = next ((t for t in self .tasks .values () if t .name == prev_task_name ), None )
1148+
1149+ feedback = {
1150+ 'validation_response' : decision_str ,
1151+ 'validation_details' : current_task .result .raw ,
1152+ 'rejected_output' : validated_task .result .raw if validated_task and validated_task .result else None ,
1153+ 'validator_task' : current_task .name
1154+ }
1155+ next_task .validation_feedback = feedback
1156+ logging .debug (f"Added validation feedback to { next_task .name } : { feedback ['validation_response' ]} " )
1157+
11011158 logging .debug (f"Routing to { next_task .name } based on decision: { decision_str } " )
11021159 # Don't mark workflow as finished when following condition path
11031160 self .workflow_finished = False
0 commit comments