From 31fbfdc33471e7cbe11cec7a6694f44311a50b80 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 16 Jun 2025 21:17:45 +0000 Subject: [PATCH] Improve type hinting and add logging for None agent handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Change agent parameter type from Any to Optional[Agent] for better type safety - Add TYPE_CHECKING import and Agent type import - Add Logger.log() call alongside Printer.print() for better debugging - Addresses remaining code review suggestions from joaomdmoura Co-Authored-By: João --- src/crewai/utilities/converter.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/crewai/utilities/converter.py b/src/crewai/utilities/converter.py index 71ff4318f..18a608148 100644 --- a/src/crewai/utilities/converter.py +++ b/src/crewai/utilities/converter.py @@ -1,12 +1,16 @@ import json import re -from typing import Any, Optional, Type, Union, get_args, get_origin +from typing import TYPE_CHECKING, Any, Optional, Type, Union, get_args, get_origin from pydantic import BaseModel, ValidationError from crewai.agents.agent_builder.utilities.base_output_converter import OutputConverter from crewai.utilities.printer import Printer from crewai.utilities.pydantic_schema_parser import PydanticSchemaParser +from crewai.utilities.logger import Logger + +if TYPE_CHECKING: + from crewai.agent import Agent class ConverterError(Exception): @@ -187,10 +191,15 @@ def convert_with_instructions( result: str, model: Type[BaseModel], is_json_output: bool, - agent: Any, + agent: Optional["Agent"], converter_cls: Optional[Type[Converter]] = None, ) -> Union[dict, BaseModel, str]: if agent is None: + Logger().log( + level="warning", + message="Attempted conversion with None agent", + color="yellow" + ) Printer().print( content=f"Failed to convert text into a Pydantic model: No agent available for conversion. Using raw output instead. Model: {model.__name__}", color="red",