mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 08:08:32 +00:00
Fix AttributeError when agent_info is a list in YAML configuration
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -123,6 +123,10 @@ def CrewBase(cls: T) -> T:
|
|||||||
cache_handler_functions: Dict[str, Callable],
|
cache_handler_functions: Dict[str, Callable],
|
||||||
callbacks: Dict[str, Callable],
|
callbacks: Dict[str, Callable],
|
||||||
) -> None:
|
) -> 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"):
|
if llm := agent_info.get("llm"):
|
||||||
try:
|
try:
|
||||||
self.agents_config[agent_name]["llm"] = llms[llm]()
|
self.agents_config[agent_name]["llm"] = llms[llm]()
|
||||||
|
|||||||
45
tests/project/test_yaml_config.py
Normal file
45
tests/project/test_yaml_config.py
Normal file
@@ -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"
|
||||||
Reference in New Issue
Block a user