pleasing the types gods

This commit is contained in:
João Moura
2024-09-13 09:09:31 -03:00
parent bd0e840486
commit f6e3eb3e7c
2 changed files with 28 additions and 11 deletions

View File

@@ -102,6 +102,10 @@ class Agent(BaseAgent):
default=True,
description="Keep messages under the context window size by summarizing content.",
)
max_iter: int = Field(
default=15,
description="Maximum number of iterations for an agent to execute a task before giving it's best answer",
)
max_retry_limit: int = Field(
default=2,
description="Maximum number of retries for an agent to execute a task when an error occurs.",

View File

@@ -226,11 +226,17 @@ class CrewAgentExecutor(CrewAgentExecutorMixin):
):
training_data = CrewTrainingHandler(TRAINING_DATA_FILE).load()
if training_data.get(agent_id):
# type: ignore[union-attr]
if self.crew is not None and hasattr(self.crew, "_train_iteration"):
training_data[agent_id][self.crew._train_iteration][
"improved_output"
] = result.output
CrewTrainingHandler(TRAINING_DATA_FILE).save(training_data)
else:
self._logger.log(
"error",
"Invalid crew or missing _train_iteration attribute.",
color="red",
)
if self.ask_for_human_input and human_feedback is not None:
training_data = {
@@ -239,10 +245,11 @@ class CrewAgentExecutor(CrewAgentExecutorMixin):
"agent": agent_id,
"agent_role": self.agent.role,
}
# type: ignore[union-attr]
if isinstance(self.crew._train_iteration, int):
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(
self.crew._train_iteration, agent_id, training_data
train_iteration, agent_id, training_data
)
else:
self._logger.log(
@@ -250,6 +257,12 @@ class CrewAgentExecutor(CrewAgentExecutorMixin):
"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"])