mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-20 13:28:13 +00:00
WIP. Procedure appears to be working well. Working on mocking properly for tests
This commit is contained in:
@@ -6,15 +6,15 @@ from typing import Any, Dict, List, Optional, Tuple, Union
|
||||
|
||||
from langchain_core.callbacks import BaseCallbackHandler
|
||||
from pydantic import (
|
||||
UUID4,
|
||||
BaseModel,
|
||||
ConfigDict,
|
||||
Field,
|
||||
InstanceOf,
|
||||
Json,
|
||||
PrivateAttr,
|
||||
field_validator,
|
||||
model_validator,
|
||||
UUID4,
|
||||
BaseModel,
|
||||
ConfigDict,
|
||||
Field,
|
||||
InstanceOf,
|
||||
Json,
|
||||
PrivateAttr,
|
||||
field_validator,
|
||||
model_validator,
|
||||
)
|
||||
from pydantic_core import PydanticCustomError
|
||||
|
||||
@@ -34,8 +34,8 @@ from crewai.utilities import I18N, FileHandler, Logger, RPMController
|
||||
from crewai.utilities.constants import TRAINED_AGENTS_DATA_FILE, TRAINING_DATA_FILE
|
||||
from crewai.utilities.evaluators.task_evaluator import TaskEvaluator
|
||||
from crewai.utilities.formatter import (
|
||||
aggregate_raw_outputs_from_task_outputs,
|
||||
aggregate_raw_outputs_from_tasks,
|
||||
aggregate_raw_outputs_from_task_outputs,
|
||||
aggregate_raw_outputs_from_tasks,
|
||||
)
|
||||
from crewai.utilities.training_handler import CrewTrainingHandler
|
||||
|
||||
@@ -86,7 +86,7 @@ class Crew(BaseModel):
|
||||
tasks: List[Task] = Field(default_factory=list)
|
||||
agents: List[BaseAgent] = Field(default_factory=list)
|
||||
process: Process = Field(default=Process.sequential)
|
||||
verbose: Union[int, bool] = Field(default=0)
|
||||
verbose: int = Field(default=0)
|
||||
memory: bool = Field(
|
||||
default=False,
|
||||
description="Whether the crew should use memory to store memories of it's execution",
|
||||
@@ -131,8 +131,8 @@ class Crew(BaseModel):
|
||||
default=None,
|
||||
description="Path to the prompt json file to be used for the crew.",
|
||||
)
|
||||
output_log_file: Optional[Union[bool, str]] = Field(
|
||||
default=False,
|
||||
output_log_file: Optional[str] = Field(
|
||||
default="",
|
||||
description="output_log_file",
|
||||
)
|
||||
|
||||
|
||||
3
src/crewai/procedure/__init__.py
Normal file
3
src/crewai/procedure/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from crewai.procedure.procedure import Procedure
|
||||
|
||||
__all__ = ["Procedure"]
|
||||
38
src/crewai/procedure/procedure.py
Normal file
38
src/crewai/procedure/procedure.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import asyncio
|
||||
from typing import Any, Dict, List
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from crewai.crew import Crew
|
||||
from crewai.crews.crew_output import CrewOutput
|
||||
|
||||
|
||||
class Procedure(BaseModel):
|
||||
crews: List[Crew] = Field(
|
||||
..., description="List of crews to be executed in sequence"
|
||||
)
|
||||
|
||||
async def kickoff(self, inputs: List[Dict[str, Any]]) -> List[CrewOutput]:
|
||||
current_inputs = inputs
|
||||
|
||||
for crew in self.crews:
|
||||
# Process all inputs for the current crew
|
||||
crew_outputs = await self._process_crew(crew, current_inputs)
|
||||
print("Crew Outputs", crew_outputs)
|
||||
|
||||
# Prepare inputs for the next crew
|
||||
current_inputs = [output.to_dict() for output in crew_outputs]
|
||||
|
||||
# Return the final outputs
|
||||
return crew_outputs
|
||||
|
||||
async def _process_crew(
|
||||
self, crew: Crew, inputs: List[Dict[str, Any]]
|
||||
) -> List[CrewOutput]:
|
||||
# Kickoff crew asynchronously for each input
|
||||
crew_kickoffs = [crew.kickoff_async(inputs=input_data) for input_data in inputs]
|
||||
|
||||
# Wait for all kickoffs to complete
|
||||
outputs = await asyncio.gather(*crew_kickoffs)
|
||||
|
||||
return outputs
|
||||
Reference in New Issue
Block a user