Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/crewai/project/crew_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,10 @@ def _map_task_variables(
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
]

if tools := task_info.get("tools"):
self.tasks_config[task_name]["tools"] = [
Expand Down
5 changes: 5 additions & 0 deletions tests/config_none_context/agents.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test_agent:
role: Test Agent
goal: Test goal
backstory: Test backstory
verbose: true
11 changes: 11 additions & 0 deletions tests/config_none_context/tasks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
task_with_none_context:
description: A test task with None context
expected_output: Some output
agent: test_agent
context: None

task_with_valid_context:
description: A test task with valid context
expected_output: Some output
agent: test_agent
context: [task_with_none_context]
35 changes: 35 additions & 0 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,38 @@ def test_internal_crew_with_mcp():
adapter_mock.assert_called_once_with(
{"host": "localhost", "port": 8000}, connect_timeout=120
)


def test_task_with_none_context_from_yaml():
@CrewBase
class CrewWithNoneContext:
agents_config = "config_none_context/agents.yaml"
tasks_config = "config_none_context/tasks.yaml"

agents: list[BaseAgent]
tasks: list[Task]

@agent
def test_agent(self):
return Agent(config=self.agents_config["test_agent"])

@task
def task_with_none_context(self):
return Task(config=self.tasks_config["task_with_none_context"])

@task
def task_with_valid_context(self):
return Task(config=self.tasks_config["task_with_valid_context"])

@crew
def crew(self):
return Crew(agents=self.agents, tasks=self.tasks, verbose=True)

crew_instance = CrewWithNoneContext()

task_none = crew_instance.task_with_none_context()
assert task_none is not None

task_valid = crew_instance.task_with_valid_context()
assert task_valid.context is not None
assert len(task_valid.context) == 1
Loading