Update config typecheck to accept agents

This commit is contained in:
Brandon Hancock
2024-09-05 14:39:30 -04:00
parent c7e8d55926
commit 66c0d67e2f
3 changed files with 14 additions and 7 deletions

View File

@@ -103,7 +103,8 @@ def crew(func):
for task_name in sorted_task_names:
task_instance = tasks[task_name]()
instantiated_tasks.append(task_instance)
if hasattr(task_instance, "agent"):
agent_instance = getattr(task_instance, "agent", None)
if agent_instance is not None:
agent_instance = task_instance.agent
if agent_instance.role not in agent_roles:
instantiated_agents.append(agent_instance)

View File

@@ -27,7 +27,9 @@ def CrewBase(cls):
tasks_config_path = self.base_directory / self.original_tasks_config_path
self.agents_config = self.load_yaml(agents_config_path)
print("agent_config", self.agents_config)
self.tasks_config = self.load_yaml(tasks_config_path)
print("task_config", self.tasks_config)
self.map_all_agent_variables()
self.map_all_task_variables()
@@ -136,6 +138,8 @@ def CrewBase(cls):
output_pydantic_functions,
)
print(f"config for task {task_name}:", self.tasks_config[task_name])
def _map_task_variables(
self,
task_name: str,
@@ -147,6 +151,7 @@ def CrewBase(cls):
callback_functions: Dict[str, Callable],
output_pydantic_functions: Dict[str, Callable],
) -> None:
# print("TASK INFO", task_info)
if context_list := task_info.get("context"):
self.tasks_config[task_name]["context"] = [
tasks[context_task_name]() for context_task_name in context_list
@@ -175,4 +180,6 @@ def CrewBase(cls):
callback_functions[callback]() for callback in callbacks
]
# print("FINAL TASK CONFIG", self.tasks_config)
return WrappedClass

View File

@@ -23,17 +23,16 @@ def process_config(
# Copy values from config (originally from YAML) to the model's attributes.
# Only copy if the attribute isn't already set, preserving any explicitly defined values.
for key, value in config.items():
if key not in model_class.model_fields:
if key not in model_class.model_fields or values.get(key) is not None:
continue
if values.get(key) is not None:
continue
if isinstance(value, (str, int, float, bool, list)):
values[key] = value
elif isinstance(value, dict):
if isinstance(value, dict):
if isinstance(values.get(key), dict):
values[key].update(value)
else:
values[key] = value
else:
values[key] = value
# Remove the config from values to avoid duplicate processing
values.pop("config", None)