diff --git a/src/crewai/project/crew_base.py b/src/crewai/project/crew_base.py index 0b43882f2..afd6b72f4 100644 --- a/src/crewai/project/crew_base.py +++ b/src/crewai/project/crew_base.py @@ -123,6 +123,10 @@ def CrewBase(cls: T) -> T: cache_handler_functions: Dict[str, Callable], callbacks: Dict[str, Callable], ) -> None: + # If agent_info is a list, use the first item as the configuration + if isinstance(agent_info, list) and len(agent_info) > 0: + agent_info = agent_info[0] + if llm := agent_info.get("llm"): try: self.agents_config[agent_name]["llm"] = llms[llm]() diff --git a/tests/project/test_yaml_config.py b/tests/project/test_yaml_config.py new file mode 100644 index 000000000..b8cb1ff93 --- /dev/null +++ b/tests/project/test_yaml_config.py @@ -0,0 +1,45 @@ +import pytest +import yaml +import tempfile +from pathlib import Path +import sys +import os + +# Add a simple test to verify the fix works +def test_list_format_in_yaml(): + """Test that list format in YAML is handled correctly.""" + # Create a test YAML content with list format + yaml_content = """ + test_agent: + - name: test_agent + role: Test Agent + goal: Test Goal + """ + + # Parse the YAML content + data = yaml.safe_load(yaml_content) + + # Get the agent_info which should be a list + agent_name = "test_agent" + agent_info = data[agent_name] + + # Verify it's a list + assert isinstance(agent_info, list) + + # Create a function that simulates the behavior of _map_agent_variables + # with our fix applied + def map_agent_variables(agent_name, agent_info): + # This is the fix we implemented + if isinstance(agent_info, list) and len(agent_info) > 0: + agent_info = agent_info[0] + + # Try to access a dictionary method on agent_info + # This would fail with AttributeError if agent_info is still a list + value = agent_info.get("name") + return value + + # Call the function - this would raise AttributeError before the fix + result = map_agent_variables(agent_name, agent_info) + + # Verify the result + assert result == "test_agent"