mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-29 10:08:13 +00:00
rolling abckt o pydantic v1
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
from pydantic.v1 import BaseModel, Field
|
from pydantic.v1 import BaseModel, Field, root_validator
|
||||||
from pydantic import model_validator
|
|
||||||
|
|
||||||
from langchain.tools import Tool
|
from langchain.tools import Tool
|
||||||
|
|
||||||
@@ -21,7 +20,19 @@ class Task(BaseModel):
|
|||||||
default=[]
|
default=[]
|
||||||
)
|
)
|
||||||
|
|
||||||
@model_validator(mode="after")
|
@root_validator(pre=False)
|
||||||
def _set_tools(self) -> None:
|
def _set_tools(cls, values):
|
||||||
|
if values.get('agent'):
|
||||||
|
values['tools'] = values.get('agent.tools')
|
||||||
|
return values
|
||||||
|
|
||||||
|
def execute(self, context) -> str:
|
||||||
|
"""
|
||||||
|
Execute the task.
|
||||||
|
Returns:
|
||||||
|
output (str): Output of the task.
|
||||||
|
"""
|
||||||
if self.agent:
|
if self.agent:
|
||||||
self.tools = self.agent.tools
|
return self.agent.execute_task(self.description, context)
|
||||||
|
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.")
|
||||||
Reference in New Issue
Block a user