adding support for input interpolation for tasks and agents

This commit is contained in:
João Moura
2024-02-28 02:59:58 -03:00
parent 2530196cf8
commit 997c906b5f
4 changed files with 49 additions and 2 deletions

View File

@@ -41,6 +41,7 @@ class Crew(BaseModel):
full_output: Whether the crew should return the full output with all tasks outputs or just the final output.
step_callback: Callback to be executed after each step for every agents execution.
share_crew: Whether you want to share the complete crew infromation and execution with crewAI to make the library better, and allow us to train models.
inputs: Any inputs that the crew will use in tasks or agents, it will be interpolated in promtps.
"""
__hash__ = object.__hash__ # type: ignore
@@ -67,6 +68,10 @@ class Crew(BaseModel):
function_calling_llm: Optional[Any] = Field(
description="Language model that will run the agent.", default=None
)
inputs: Optional[Dict[str, Any]] = Field(
description="Any inputs that the crew will use in tasks or agents, it will be interpolated in promtps.",
default={},
)
config: Optional[Union[Json, Dict[str, Any]]] = Field(default=None)
id: UUID4 = Field(default_factory=uuid.uuid4, frozen=True)
share_crew: Optional[bool] = Field(default=False)
@@ -129,6 +134,15 @@ class Crew(BaseModel):
)
return self
@model_validator(mode="after")
def interpolate_inputs(self):
"""Interpolates the inputs in the tasks and agents."""
for task in self.tasks:
task.interpolate_inputs(self.inputs)
for agent in self.agents:
agent.interpolate_inputs(self.inputs)
return self
@model_validator(mode="after")
def check_config(self):
"""Validates that the crew is properly configured with agents and tasks."""