Merge branch 'main' into bugfix/fix-backtick-in-agent-response

This commit is contained in:
Brandon Hancock (bhancock_ai)
2025-02-18 15:23:40 -05:00
committed by GitHub

View File

@@ -275,12 +275,26 @@ class Crew(BaseModel):
if self.entity_memory if self.entity_memory
else EntityMemory(crew=self, embedder_config=self.embedder) else EntityMemory(crew=self, embedder_config=self.embedder)
) )
if hasattr(self, "memory_config") and self.memory_config is not None: if (
self._user_memory = ( self.memory_config and "user_memory" in self.memory_config
self.user_memory if self.user_memory else UserMemory(crew=self) ): # Check for user_memory in config
) user_memory_config = self.memory_config["user_memory"]
if isinstance(
user_memory_config, UserMemory
): # Check if it is already an instance
self._user_memory = user_memory_config
elif isinstance(
user_memory_config, dict
): # Check if it's a configuration dict
self._user_memory = UserMemory(
crew=self, **user_memory_config
) # Initialize with config
else:
raise TypeError(
"user_memory must be a UserMemory instance or a configuration dictionary"
)
else: else:
self._user_memory = None self._user_memory = None # No user memory if not in config
return self return self
@model_validator(mode="after") @model_validator(mode="after")
@@ -455,8 +469,6 @@ class Crew(BaseModel):
) )
return self return self
@property @property
def key(self) -> str: def key(self) -> str:
source = [agent.key for agent in self.agents] + [ source = [agent.key for agent in self.agents] + [
@@ -928,13 +940,13 @@ class Crew(BaseModel):
def _create_crew_output(self, task_outputs: List[TaskOutput]) -> CrewOutput: def _create_crew_output(self, task_outputs: List[TaskOutput]) -> CrewOutput:
if not task_outputs: if not task_outputs:
raise ValueError("No task outputs available to create crew output.") raise ValueError("No task outputs available to create crew output.")
# Filter out empty outputs and get the last valid one as the main output # Filter out empty outputs and get the last valid one as the main output
valid_outputs = [t for t in task_outputs if t.raw] valid_outputs = [t for t in task_outputs if t.raw]
if not valid_outputs: if not valid_outputs:
raise ValueError("No valid task outputs available to create crew output.") raise ValueError("No valid task outputs available to create crew output.")
final_task_output = valid_outputs[-1] final_task_output = valid_outputs[-1]
final_string_output = final_task_output.raw final_string_output = final_task_output.raw
self._finish_execution(final_string_output) self._finish_execution(final_string_output)
token_usage = self.calculate_usage_metrics() token_usage = self.calculate_usage_metrics()