@@ -665,16 +665,22 @@ async def aexecute_task(self, task_id):
665665 if executor_agent and executor_agent .tools :
666666 tools .extend (executor_agent .tools )
667667
668- task_prompt = f"""
669- You need to do the following task: { task .description } .
670- Expected Output: { task .expected_output } .
671- """
668+ # Substitute variables in task description if provided
669+ task_description = task .description
670+ if getattr (task , 'variables' , None ):
671+ for key , value in task .variables .items ():
672+ task_description = task_description .replace (f"{{{{{ key } }}}}" , str (value ))
673+
674+ # Build context first to include in task prompt
675+ context_text = ""
672676 if task .context :
673677 context_results = [] # Use list to avoid duplicates
674678 for context_item in task .context :
675679 # Use the centralized helper function
676680 context_str = process_task_context (context_item , self .verbose , self .user_id )
677- context_results .append (context_str )
681+ # Only add non-empty context strings
682+ if context_str and context_str .strip ():
683+ context_results .append (context_str )
678684
679685 # Join unique context results with proper formatting
680686 unique_contexts = list (dict .fromkeys (context_results )) # Remove duplicates
@@ -683,15 +689,26 @@ async def aexecute_task(self, task_id):
683689 for i , ctx in enumerate (unique_contexts ):
684690 logger .debug (f"Context { i + 1 } : { ctx [:100 ]} ..." )
685691 context_separator = '\n \n '
686- task_prompt += f"""
687- Context:
692+ context_text = context_separator .join (unique_contexts )
693+
694+ # Build task prompt - only use "User Input/Topic" format if there's actual content
695+ if context_text and context_text .strip ():
696+ task_prompt = f"""
697+ User Input/Topic: { context_text }
688698
689- { context_separator .join (unique_contexts )}
690- """
691- task_prompt += "Please provide only the final result of your work. Do not add any conversation or extra explanation."
699+ Task: { task_description }
700+ Expected Output: { task .expected_output }
701+
702+ IMPORTANT: Your response must be about the user's input/topic above. Incorporate it into your task.
703+ Please provide only the final result of your work. Do not add any conversation or extra explanation."""
704+ else :
705+ task_prompt = f"""
706+ You need to do the following task: { task_description } .
707+ Expected Output: { task .expected_output } .
708+ Please provide only the final result of your work. Do not add any conversation or extra explanation."""
692709
693710 if self .verbose >= 2 :
694- logger .info (f"Executing task { task_id } : { task . description } using { executor_agent .display_name } " )
711+ logger .info (f"Executing task { task_id } : { task_description } using { executor_agent .display_name } " )
695712 logger .debug (f"Starting execution of task { task_id } with prompt:\n { task_prompt } " )
696713
697714 if task .images :
@@ -989,16 +1006,16 @@ def execute_task(self, task_id):
9891006 for key , value in task .variables .items ():
9901007 task_description = task_description .replace (f"{{{{{ key } }}}}" , str (value ))
9911008
992- task_prompt = f"""
993- You need to do the following task: { task_description } .
994- Expected Output: { task .expected_output } .
995- """
1009+ # Build context first to include in task prompt
1010+ context_text = ""
9961011 if task .context :
9971012 context_results = [] # Use list to avoid duplicates
9981013 for context_item in task .context :
9991014 # Use the centralized helper function
10001015 context_str = process_task_context (context_item , self .verbose , self .user_id )
1001- context_results .append (context_str )
1016+ # Only add non-empty context strings
1017+ if context_str and context_str .strip ():
1018+ context_results .append (context_str )
10021019
10031020 # Join unique context results with proper formatting
10041021 unique_contexts = list (dict .fromkeys (context_results )) # Remove duplicates
@@ -1007,11 +1024,21 @@ def execute_task(self, task_id):
10071024 for i , ctx in enumerate (unique_contexts ):
10081025 logger .debug (f"Context { i + 1 } : { ctx [:100 ]} ..." )
10091026 context_separator = '\n \n '
1010- task_prompt += f"""
1011- Context:
1027+ context_text = context_separator .join (unique_contexts )
1028+
1029+ # Build task prompt - only use "User Input/Topic" format if there's actual content
1030+ if context_text and context_text .strip ():
1031+ task_prompt = f"""
1032+ User Input/Topic: { context_text }
1033+
1034+ Task: { task_description }
1035+ Expected Output: { task .expected_output }
10121036
1013- { context_separator .join (unique_contexts )}
1014- """
1037+ IMPORTANT: Your response must be about the user's input/topic above. Incorporate it into your task."""
1038+ else :
1039+ task_prompt = f"""
1040+ You need to do the following task: { task_description } .
1041+ Expected Output: { task .expected_output } ."""
10151042
10161043 # Add memory context if available
10171044 if task .memory :
@@ -1025,7 +1052,7 @@ def execute_task(self, task_id):
10251052 except Exception as e :
10261053 logger .error (f"Error getting memory context: { e } " )
10271054
1028- task_prompt += "Please provide only the final result of your work. Do not add any conversation or extra explanation."
1055+ task_prompt += "\n Please provide only the final result of your work. Do not add any conversation or extra explanation."
10291056
10301057 if self .verbose >= 2 :
10311058 logger .info (f"Executing task { task_id } : { task .description } using { executor_agent .display_name } " )
0 commit comments