diff --git a/crewai/crew.py b/crewai/crew.py index daa992455..72f78fcf2 100644 --- a/crewai/crew.py +++ b/crewai/crew.py @@ -32,7 +32,7 @@ class Crew(BaseModel): if values.get('config'): config = json.loads(values.get('config')) - if not config['agents'] or not config['tasks']: + if not config.get('agents') or not config.get('tasks'): raise ValueError('Config should have agents and tasks.') values['agents'] = [Agent(**agent) for agent in config['agents']] diff --git a/tests/crew_test.py b/tests/crew_test.py index c0ff8c9ea..a4072c067 100644 --- a/tests/crew_test.py +++ b/tests/crew_test.py @@ -63,6 +63,32 @@ def test_crew_config_conditional_requirement(): assert [agent.role for agent in crew.agents] == [agent['role'] for agent in parsed_config['agents']] assert [task.description for task in crew.tasks] == [task['description'] for task in parsed_config['tasks']] +def test_crew_config_with_wrong_keys(): + no_tasks_config = json.dumps({ + "agents": [ + { + "role": "Senior Researcher", + "goal": "Make the best research and analysis on content about AI and AI agents", + "backstory": "You're an expert researcher, specialized in technology, software engineering, AI and startups. You work as a freelancer and is now working on doing research and analysis for a new customer." + } + ] + }) + + no_agents_config = json.dumps({ + "tasks": [ + { + "description": "Give me a list of 5 interesting ideas to explore for na article, what makes them unique and interesting.", + "agent": "Senior Researcher" + } + ] + }) + with pytest.raises(ValueError): + Crew(process=Process.sequential, config='{"wrong_key": "wrong_value"}') + with pytest.raises(ValueError): + Crew(process=Process.sequential, config=no_tasks_config) + with pytest.raises(ValueError): + Crew(process=Process.sequential, config=no_agents_config) + @pytest.mark.vcr() def test_crew_creation(): tasks = [