Add support to delegate work

This commit is contained in:
Joao Moura
2023-11-10 18:15:45 -03:00
parent d6989b7959
commit 6ff18128a7
15 changed files with 1786 additions and 1636 deletions

View File

@@ -22,17 +22,21 @@ class Task(BaseModel):
@root_validator(pre=False)
def _set_tools(cls, values):
if values.get('agent'):
values['tools'] = values.get('agent.tools')
if (values.get('agent')) and not (values.get('tools')):
values['tools'] = values.get('agent').tools
return values
def execute(self, context) -> str:
def execute(self, context: str = None) -> str:
"""
Execute the task.
Returns:
output (str): Output of the task.
"""
if self.agent:
return self.agent.execute_task(self.description, context)
return self.agent.execute_task(
task = self.description,
context = context,
tools = self.tools
)
else:
raise Exception(f"The task '{self.description}' has no agent assigned, therefore it can't be executed directly and should be executed in a Crew using a specific process that support that, either consensual or hierarchical.")