mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 16:48:30 +00:00
Fix logging
This commit is contained in:
@@ -37,12 +37,11 @@ from crewai.utilities.constants import (
|
|||||||
TRAINING_DATA_FILE,
|
TRAINING_DATA_FILE,
|
||||||
)
|
)
|
||||||
from crewai.utilities.evaluators.task_evaluator import TaskEvaluator
|
from crewai.utilities.evaluators.task_evaluator import TaskEvaluator
|
||||||
from crewai.utilities.task_output_storage_handler import TaskOutputStorageHandler
|
|
||||||
|
|
||||||
from crewai.utilities.formatter import (
|
from crewai.utilities.formatter import (
|
||||||
aggregate_raw_outputs_from_task_outputs,
|
aggregate_raw_outputs_from_task_outputs,
|
||||||
aggregate_raw_outputs_from_tasks,
|
aggregate_raw_outputs_from_tasks,
|
||||||
)
|
)
|
||||||
|
from crewai.utilities.task_output_storage_handler import TaskOutputStorageHandler
|
||||||
from crewai.utilities.training_handler import CrewTrainingHandler
|
from crewai.utilities.training_handler import CrewTrainingHandler
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -621,12 +620,12 @@ class Crew(BaseModel):
|
|||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"No agent available for task: {task.description}. Ensure that either the task has an assigned agent or a manager agent is provided."
|
f"No agent available for task: {task.description}. Ensure that either the task has an assigned agent or a manager agent is provided."
|
||||||
)
|
)
|
||||||
self._log_task_start(task, agent_to_use)
|
|
||||||
|
|
||||||
if task.async_execution:
|
if task.async_execution:
|
||||||
context = self._get_context(
|
context = self._get_context(
|
||||||
task, [last_sync_output] if last_sync_output else []
|
task, [last_sync_output] if last_sync_output else []
|
||||||
)
|
)
|
||||||
|
self._log_task_start(task, agent_to_use.role)
|
||||||
future = task.execute_async(
|
future = task.execute_async(
|
||||||
agent=agent_to_use,
|
agent=agent_to_use,
|
||||||
context=context,
|
context=context,
|
||||||
@@ -635,12 +634,14 @@ class Crew(BaseModel):
|
|||||||
futures.append((task, future, task_index))
|
futures.append((task, future, task_index))
|
||||||
else:
|
else:
|
||||||
if futures:
|
if futures:
|
||||||
|
task_outputs = []
|
||||||
task_outputs.extend(
|
task_outputs.extend(
|
||||||
self._process_async_tasks(futures, was_replayed)
|
self._process_async_tasks(futures, was_replayed)
|
||||||
)
|
)
|
||||||
futures.clear()
|
futures.clear()
|
||||||
|
|
||||||
context = self._get_context(task, task_outputs)
|
context = self._get_context(task, task_outputs)
|
||||||
|
self._log_task_start(task, agent_to_use.role)
|
||||||
task_output = task.execute_sync(
|
task_output = task.execute_sync(
|
||||||
agent=agent_to_use,
|
agent=agent_to_use,
|
||||||
context=context,
|
context=context,
|
||||||
@@ -687,9 +688,8 @@ class Crew(BaseModel):
|
|||||||
# Add the new tool
|
# Add the new tool
|
||||||
task.tools.append(new_tool)
|
task.tools.append(new_tool)
|
||||||
|
|
||||||
def _log_task_start(self, task: Task, agent: Optional[BaseAgent]):
|
def _log_task_start(self, task: Task, role: str = "None"):
|
||||||
color = self._logging_color
|
color = self._logging_color
|
||||||
role = agent.role if agent else "None"
|
|
||||||
self._logger.log("debug", f"== Working Agent: {role}", color=color)
|
self._logger.log("debug", f"== Working Agent: {role}", color=color)
|
||||||
self._logger.log("info", f"== Starting Task: {task.description}", color=color)
|
self._logger.log("info", f"== Starting Task: {task.description}", color=color)
|
||||||
if self.output_log_file:
|
if self.output_log_file:
|
||||||
@@ -738,7 +738,7 @@ class Crew(BaseModel):
|
|||||||
futures: List[Tuple[Task, Future[TaskOutput], int]],
|
futures: List[Tuple[Task, Future[TaskOutput], int]],
|
||||||
was_replayed: bool = False,
|
was_replayed: bool = False,
|
||||||
) -> List[TaskOutput]:
|
) -> List[TaskOutput]:
|
||||||
task_outputs = []
|
task_outputs: List[TaskOutput] = []
|
||||||
for future_task, future, task_index in futures:
|
for future_task, future, task_index in futures:
|
||||||
task_output = future.result()
|
task_output = future.result()
|
||||||
task_outputs.append(task_output)
|
task_outputs.append(task_output)
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ from copy import copy
|
|||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
from typing import Any, Dict, List, Optional, Tuple, Type, Union
|
from typing import Any, Dict, List, Optional, Tuple, Type, Union
|
||||||
|
|
||||||
|
|
||||||
from langchain_openai import ChatOpenAI
|
from langchain_openai import ChatOpenAI
|
||||||
from opentelemetry.trace import Span
|
from opentelemetry.trace import Span
|
||||||
from pydantic import UUID4, BaseModel, Field, field_validator, model_validator
|
from pydantic import UUID4, BaseModel, Field, field_validator, model_validator
|
||||||
@@ -255,9 +254,7 @@ class Task(BaseModel):
|
|||||||
content = (
|
content = (
|
||||||
json_output
|
json_output
|
||||||
if json_output
|
if json_output
|
||||||
else pydantic_output.model_dump_json()
|
else pydantic_output.model_dump_json() if pydantic_output else result
|
||||||
if pydantic_output
|
|
||||||
else result
|
|
||||||
)
|
)
|
||||||
self._save_file(content)
|
self._save_file(content)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user