mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-03 08:12:39 +00:00
WIP. Procedure appears to be working well. Working on mocking properly for tests
This commit is contained in:
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