From 33b9cd35e9486b49e2b16e3498b58da3ba563d07 Mon Sep 17 00:00:00 2001 From: Brandon Hancock Date: Wed, 19 Feb 2025 13:00:51 -0500 Subject: [PATCH] imporve HITL --- .../base_agent_executor_mixin.py | 11 +++++--- src/crewai/agents/crew_agent_executor.py | 26 ++----------------- src/crewai/translations/en.json | 1 - 3 files changed, 10 insertions(+), 28 deletions(-) diff --git a/src/crewai/agents/agent_builder/base_agent_executor_mixin.py b/src/crewai/agents/agent_builder/base_agent_executor_mixin.py index 924cef71c..e7917f2bd 100644 --- a/src/crewai/agents/agent_builder/base_agent_executor_mixin.py +++ b/src/crewai/agents/agent_builder/base_agent_executor_mixin.py @@ -114,10 +114,15 @@ class CrewAgentExecutorMixin: prompt = ( "\n\n=====\n" "## HUMAN FEEDBACK: Provide feedback on the Final Result and Agent's actions.\n" - "Respond with 'looks good' to accept or provide specific improvement requests.\n" - "You can provide multiple rounds of feedback until satisfied.\n" + "Please follow these guidelines:\n" + " - If you are happy with the result, simply hit Enter without typing anything.\n" + " - Otherwise, provide specific improvement requests.\n" + " - You can provide multiple rounds of feedback until satisfied.\n" "=====\n" ) self._printer.print(content=prompt, color="bold_yellow") - return input() + response = input() + if response.strip() != "": + self._printer.print(content="\nProcessing your feedback...", color="cyan") + return response diff --git a/src/crewai/agents/crew_agent_executor.py b/src/crewai/agents/crew_agent_executor.py index ed89008fd..fca214422 100644 --- a/src/crewai/agents/crew_agent_executor.py +++ b/src/crewai/agents/crew_agent_executor.py @@ -537,9 +537,8 @@ class CrewAgentExecutor(CrewAgentExecutorMixin): answer = current_answer while self.ask_for_human_input: - response = self._get_llm_feedback_response(feedback) - - if not self._feedback_requires_changes(response): + # If the user provides a blank response, assume they are happy with the result + if feedback.strip() == "": self.ask_for_human_input = False else: answer = self._process_feedback_iteration(feedback) @@ -547,27 +546,6 @@ class CrewAgentExecutor(CrewAgentExecutorMixin): return answer - def _get_llm_feedback_response(self, feedback: str) -> Optional[str]: - """Get LLM classification of whether feedback requires changes.""" - prompt = self._i18n.slice("human_feedback_classification").format( - feedback=feedback - ) - message = self._format_msg(prompt, role="system") - - for retry in range(MAX_LLM_RETRY): - try: - response = self.llm.call([message], callbacks=self.callbacks) - return response.strip().lower() if response else None - except Exception as error: - self._log_feedback_error(retry, error) - - self._log_max_retries_exceeded() - return None - - def _feedback_requires_changes(self, response: Optional[str]) -> bool: - """Determine if feedback response indicates need for changes.""" - return response == "true" if response else False - def _process_feedback_iteration(self, feedback: str) -> AgentFinish: """Process a single feedback iteration.""" self.messages.append( diff --git a/src/crewai/translations/en.json b/src/crewai/translations/en.json index f09f1dba0..4c28fc5d5 100644 --- a/src/crewai/translations/en.json +++ b/src/crewai/translations/en.json @@ -23,7 +23,6 @@ "summary": "This is a summary of our conversation so far:\n{merged_summary}", "manager_request": "Your best answer to your coworker asking you this, accounting for the context shared.", "formatted_task_instructions": "Ensure your final answer contains only the content in the following format: {output_format}\n\nEnsure the final output does not include any code block markers like ```json or ```python.", - "human_feedback_classification": "Determine if the following feedback indicates that the user is satisfied or if further changes are needed. Respond with 'True' if further changes are needed, or 'False' if the user is satisfied. **Important** Do not include any additional commentary outside of your 'True' or 'False' response.\n\nFeedback: \"{feedback}\"", "conversation_history_instruction": "You are a member of a crew collaborating to achieve a common goal. Your task is a specific action that contributes to this larger objective. For additional context, please review the conversation history between you and the user that led to the initiation of this crew. Use any relevant information or feedback from the conversation to inform your task execution and ensure your response aligns with both the immediate task and the crew's overall goals.", "feedback_instructions": "User feedback: {feedback}\nInstructions: Use this feedback to enhance the next output iteration.\nNote: Do not respond or add commentary." },