From 2ec68501aefb77d331a1eda1e70bca0749cdf74f Mon Sep 17 00:00:00 2001 From: Eduardo Chiarotti Date: Fri, 11 Oct 2024 19:35:35 -0300 Subject: [PATCH 1/3] fix: training issue --- src/crewai/agents/crew_agent_executor.py | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/crewai/agents/crew_agent_executor.py b/src/crewai/agents/crew_agent_executor.py index 3cb195206f..d15c80732e 100644 --- a/src/crewai/agents/crew_agent_executor.py +++ b/src/crewai/agents/crew_agent_executor.py @@ -334,6 +334,32 @@ def _handle_crew_training_output( color="red", ) + if self.ask_for_human_input and human_feedback is not None: + training_data = { + "initial_output": result.output, + "human_feedback": human_feedback, + "agent": agent_id, + "agent_role": self.agent.role, + } + if self.crew is not None and hasattr(self.crew, "_train_iteration"): + train_iteration = self.crew._train_iteration + if isinstance(train_iteration, int): + CrewTrainingHandler(TRAINING_DATA_FILE).append( + train_iteration, agent_id, training_data + ) + else: + self._logger.log( + "error", + "Invalid train iteration type. Expected int.", + color="red", + ) + else: + self._logger.log( + "error", + "Crew is None or does not have _train_iteration attribute.", + color="red", + ) + def _format_prompt(self, prompt: str, inputs: Dict[str, str]) -> str: prompt = prompt.replace("{input}", inputs["input"]) prompt = prompt.replace("{tool_names}", inputs["tool_names"]) From 6187e458fe95c483b5ed6a621ddb7a33f7adecb5 Mon Sep 17 00:00:00 2001 From: Eduardo Chiarotti Date: Fri, 11 Oct 2024 21:33:07 -0300 Subject: [PATCH 2/3] fix: output from crew --- src/crewai/cli/run_crew.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/crewai/cli/run_crew.py b/src/crewai/cli/run_crew.py index e4e3e1b2f9..7cf8fccf7e 100644 --- a/src/crewai/cli/run_crew.py +++ b/src/crewai/cli/run_crew.py @@ -9,7 +9,9 @@ def run_crew() -> None: """ command = ["uv", "run", "run_crew"] try: - subprocess.run(command, capture_output=True, text=True, check=True) + subprocess.run( + command, capture_output=False, text=True, check=True, stderr=subprocess.PIPE + ) except subprocess.CalledProcessError as e: click.echo(f"An error occurred while running the crew: {e}", err=True) From d84766c356842221efbd6b3dc78267f88e6ba97a Mon Sep 17 00:00:00 2001 From: Eduardo Chiarotti Date: Fri, 11 Oct 2024 22:02:17 -0300 Subject: [PATCH 3/3] fix: message --- src/crewai/cli/run_crew.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/crewai/cli/run_crew.py b/src/crewai/cli/run_crew.py index 7cf8fccf7e..0b1ac29bc9 100644 --- a/src/crewai/cli/run_crew.py +++ b/src/crewai/cli/run_crew.py @@ -1,6 +1,7 @@ import subprocess import click +import tomllib def run_crew() -> None: @@ -9,15 +10,16 @@ def run_crew() -> None: """ command = ["uv", "run", "run_crew"] try: - subprocess.run( - command, capture_output=False, text=True, check=True, stderr=subprocess.PIPE - ) + subprocess.run(command, capture_output=False, text=True, check=True) except subprocess.CalledProcessError as e: click.echo(f"An error occurred while running the crew: {e}", err=True) click.echo(e.output, err=True, nl=True) - click.echo(e.stderr, err=True, nl=True) - if "table found" in e.stderr: + + with open("pyproject.toml", "rb") as f: + data = tomllib.load(f) + + if data.get("tool", {}).get("poetry"): click.secho( "It's possible that you are using an old version of crewAI that uses poetry, please run `crewai update` to update your pyproject.toml to use uv.", fg="yellow",