eaglelandsonce commited on
Commit
81114f1
1 Parent(s): 1f37fbd

Update crewai/task.py

Browse files
Files changed (1) hide show
  1. crewai/task.py +11 -5
crewai/task.py CHANGED
@@ -5,6 +5,7 @@ from pydantic import UUID4, BaseModel, Field, field_validator, model_validator
5
  from pydantic_core import PydanticCustomError
6
 
7
  from crewai.agent import Agent
 
8
 
9
 
10
  class Task(BaseModel):
@@ -19,6 +20,9 @@ class Task(BaseModel):
19
  default_factory=list,
20
  description="Tools the agent are limited to use for this task.",
21
  )
 
 
 
22
  id: UUID4 = Field(
23
  default_factory=uuid.uuid4,
24
  frozen=True,
@@ -45,11 +49,13 @@ class Task(BaseModel):
45
  Returns:
46
  Output of the task.
47
  """
48
- if self.agent:
49
- return self.agent.execute_task(
50
- task=self.description, context=context, tools=self.tools
51
- )
52
- else:
53
  raise Exception(
54
  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."
55
  )
 
 
 
 
 
 
 
5
  from pydantic_core import PydanticCustomError
6
 
7
  from crewai.agent import Agent
8
+ from crewai.tasks.task_output import TaskOutput
9
 
10
 
11
  class Task(BaseModel):
 
20
  default_factory=list,
21
  description="Tools the agent are limited to use for this task.",
22
  )
23
+ output: Optional[TaskOutput] = Field(
24
+ description="Task output, it's final result.", default=None
25
+ )
26
  id: UUID4 = Field(
27
  default_factory=uuid.uuid4,
28
  frozen=True,
 
49
  Returns:
50
  Output of the task.
51
  """
52
+ if not self.agent:
 
 
 
 
53
  raise Exception(
54
  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."
55
  )
56
+ result = self.agent.execute_task(
57
+ task=self.description, context=context, tools=self.tools
58
+ )
59
+
60
+ self.output = TaskOutput(description=self.description, result=result)
61
+ return result