diff --git a/pyproject.toml b/pyproject.toml index 8751bbee0..e67195f23 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "crewai" -version = "0.16.2" +version = "0.16.3" description = "Cutting-edge framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks." authors = ["Joao Moura "] readme = "README.md" diff --git a/src/crewai/agent.py b/src/crewai/agent.py index 82b03cf17..05b5b73fa 100644 --- a/src/crewai/agent.py +++ b/src/crewai/agent.py @@ -256,9 +256,10 @@ class Agent(BaseModel): def interpolate_inputs(self, inputs: Dict[str, Any]) -> None: """Interpolate inputs into the agent description and backstory.""" - self.role = self.role.format(**inputs) - self.goal = self.goal.format(**inputs) - self.backstory = self.backstory.format(**inputs) + if inputs: + self.role = self.role.format(**inputs) + self.goal = self.goal.format(**inputs) + self.backstory = self.backstory.format(**inputs) def increment_formatting_errors(self) -> None: """Count the formatting errors of the agent.""" diff --git a/src/crewai/crew.py b/src/crewai/crew.py index 79a93176a..fc372a48f 100644 --- a/src/crewai/crew.py +++ b/src/crewai/crew.py @@ -70,7 +70,7 @@ class Crew(BaseModel): ) 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={}, + default=None, ) config: Optional[Union[Json, Dict[str, Any]]] = Field(default=None) id: UUID4 = Field(default_factory=uuid.uuid4, frozen=True) diff --git a/src/crewai/task.py b/src/crewai/task.py index bdb552f4d..488e7d1ac 100644 --- a/src/crewai/task.py +++ b/src/crewai/task.py @@ -175,9 +175,10 @@ class Task(BaseModel): def interpolate_inputs(self, inputs: Dict[str, Any]) -> None: """Interpolate inputs into the task description and expected output.""" - self.description = self.description.format(**inputs) - if self.expected_output: - self.expected_output = self.expected_output.format(**inputs) + if inputs: + self.description = self.description.format(**inputs) + if self.expected_output: + self.expected_output = self.expected_output.format(**inputs) def increment_tools_errors(self) -> None: """Increment the tools errors counter.""" diff --git a/tests/crew_test.py b/tests/crew_test.py index c440a43cb..5c5273945 100644 --- a/tests/crew_test.py +++ b/tests/crew_test.py @@ -671,3 +671,26 @@ def test_crew_inputs_interpolate_both_agents_and_tasks(): assert crew.agents[0].role == "AI Researcher" assert crew.agents[0].goal == "Express hot takes on AI." assert crew.agents[0].backstory == "You have a lot of experience with AI." + + +def test_crew_inputs_interpolate_both_agents_and_tasks(): + from unittest.mock import patch + + agent = Agent( + role="{topic} Researcher", + goal="Express hot takes on {topic}.", + backstory="You have a lot of experience with {topic}.", + ) + + task = Task( + description="Give me an analysis around {topic}.", + expected_output="{points} bullet points about {topic}.", + ) + + with patch.object(Agent, "interpolate_inputs") as interpolate_agent_inputs: + with patch.object(Task, "interpolate_inputs") as interpolate_task_inputs: + interpolate_agent_inputs.return_value = None + interpolate_task_inputs.return_value = None + Crew(agents=[agent], tasks=[task], inputs={"topic": "AI", "points": 5}) + interpolate_agent_inputs.assert_called() + interpolate_task_inputs.assert_called()