From 8e0b0f5f5144e9f0402e934fd1c8f3e0376fcbab Mon Sep 17 00:00:00 2001 From: Vidit-Ostwal Date: Sat, 11 Oct 2025 11:48:56 +0530 Subject: [PATCH 1/3] Fixed task configuration with None as context parameter --- src/crewai/project/crew_base.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/crewai/project/crew_base.py b/src/crewai/project/crew_base.py index 44871f6a09..82937025e1 100644 --- a/src/crewai/project/crew_base.py +++ b/src/crewai/project/crew_base.py @@ -259,10 +259,14 @@ def _map_task_variables( callback_functions: dict[str, Callable], output_pydantic_functions: dict[str, Callable], ) -> None: + if context_list := task_info.get("context"): - self.tasks_config[task_name]["context"] = [ - tasks[context_task_name]() for context_task_name in context_list - ] + if isinstance(context_list, list): + self.tasks_config[task_name]["context"] = [ + tasks[context_task_name]() for context_task_name in context_list + ] + elif isinstance(context_list,str) and context_list == 'None': + self.tasks_config[task_name]["context"] = None if tools := task_info.get("tools"): self.tasks_config[task_name]["tools"] = [ From 05d37572aecfd7ec5bd69c890b4ed936418c7852 Mon Sep 17 00:00:00 2001 From: Vidit-Ostwal Date: Sat, 11 Oct 2025 12:35:22 +0530 Subject: [PATCH 2/3] Added test cases --- tests/config/tasks_with_none_context.yaml | 19 ++++++++ tests/test_project.py | 56 +++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 tests/config/tasks_with_none_context.yaml diff --git a/tests/config/tasks_with_none_context.yaml b/tests/config/tasks_with_none_context.yaml new file mode 100644 index 0000000000..a59b1d77c4 --- /dev/null +++ b/tests/config/tasks_with_none_context.yaml @@ -0,0 +1,19 @@ +research_task: + description: > + Conduct a thorough research about {topic} + Make sure you find any interesting and relevant information given + the current year is 2025. + expected_output: > + A list with 10 bullet points of the most relevant information about {topic} + agent: researcher + guardrail: ensure each bullet contains its source + +reporting_task: + description: > + Review the context you got and expand each topic into a full section for a report. + Make sure the report is detailed and contains any and all relevant information. + expected_output: > + A fully fledge reports with the mains topics, each with a full section of information. + Formatted as markdown without '```' + agent: reporting_analyst + context: None diff --git a/tests/test_project.py b/tests/test_project.py index c6708d92ff..7ba749fde0 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -107,6 +107,54 @@ def researcher(self): ) # type: ignore[index] +@CrewBase +class Crew_With_Task_Context_None: + agents_config = "config/agents.yaml" + tasks_config = "config/tasks_with_none_context.yaml" + + agents: list[BaseAgent] + tasks: list[Task] + + @llm + def local_llm(self): + return LLM( + model="openai/model_name", + api_key="None", + base_url="http://xxx.xxx.xxx.xxx:8000/v1", + ) + + @agent + def researcher(self): + return Agent(config=self.agents_config["researcher"]) # type: ignore[index] + + @agent + def reporting_analyst(self): + return Agent(config=self.agents_config["reporting_analyst"]) # type: ignore[index] + + @task + def research_task(self): + return Task(config=self.tasks_config["research_task"]) # type: ignore[index] + + @task + def reporting_task(self): + return Task(config=self.tasks_config["reporting_task"]) # type: ignore[index] + + @before_kickoff + def modify_inputs(self, inputs): + if inputs: + inputs["topic"] = "Bicycles" + return inputs + + @after_kickoff + def modify_outputs(self, outputs): + outputs.raw = outputs.raw + " post processed" + return outputs + + @crew + def crew(self): + return Crew(agents=self.agents, tasks=self.tasks, verbose=True) + + def test_agent_memoization(): crew = SimpleCrew() first_call_result = crew.simple_agent() @@ -287,3 +335,11 @@ def test_internal_crew_with_mcp(): adapter_mock.assert_called_once_with( {"host": "localhost", "port": 8000}, connect_timeout=120 ) + + +def test_crew_with_task_context_none(): + crew = Crew_With_Task_Context_None() + task_with_context_none = crew.reporting_task() + + assert task_with_context_none.context is None + assert task_with_context_none.context != 'None' \ No newline at end of file From a351ec2a5269e0cbe2f194b483bf13236af991a2 Mon Sep 17 00:00:00 2001 From: Vidit-Ostwal Date: Sat, 11 Oct 2025 12:58:53 +0530 Subject: [PATCH 3/3] fixed linting issues --- tests/test_project.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_project.py b/tests/test_project.py index 7ba749fde0..d32b7bfff5 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -108,7 +108,7 @@ def researcher(self): @CrewBase -class Crew_With_Task_Context_None: +class CrewWithTaskContextNone: agents_config = "config/agents.yaml" tasks_config = "config/tasks_with_none_context.yaml" @@ -153,7 +153,7 @@ def modify_outputs(self, outputs): @crew def crew(self): return Crew(agents=self.agents, tasks=self.tasks, verbose=True) - + def test_agent_memoization(): crew = SimpleCrew() @@ -338,8 +338,8 @@ def test_internal_crew_with_mcp(): def test_crew_with_task_context_none(): - crew = Crew_With_Task_Context_None() + crew = CrewWithTaskContextNone() task_with_context_none = crew.reporting_task() assert task_with_context_none.context is None - assert task_with_context_none.context != 'None' \ No newline at end of file + assert task_with_context_none.context != 'None'