Introduce structure keys (#902)

* Introduce structure keys

* Add agent key to tasks

* Rebasing is hard

* Rename task output telemetry

* Feedback
This commit is contained in:
Gui Vieira
2024-07-15 19:37:07 -03:00
committed by GitHub
parent 18fe9fc921
commit 02f6da700a
7 changed files with 133 additions and 14 deletions

View File

@@ -5,8 +5,10 @@ import threading
import uuid
from concurrent.futures import Future
from copy import copy
from hashlib import md5
from typing import Any, Dict, List, Optional, Tuple, Type, Union
from langchain_openai import ChatOpenAI
from opentelemetry.trace import Span
from pydantic import UUID4, BaseModel, Field, field_validator, model_validator
@@ -173,6 +175,14 @@ class Task(BaseModel):
"""Execute the task synchronously."""
return self._execute_core(agent, context, tools)
@property
def key(self) -> str:
description = self._original_description or self.description
expected_output = self._original_expected_output or self.expected_output
source = [description, expected_output]
return md5("|".join(source).encode()).hexdigest()
def execute_async(
self,
agent: BaseAgent | None = None,
@@ -238,7 +248,7 @@ class Task(BaseModel):
self.callback(self.output)
if self._execution_span:
self._telemetry.task_ended(self._execution_span, self)
self._telemetry.task_ended(self._execution_span, self, agent.crew)
self._execution_span = None
if self.output_file: