CrewAIInteroperability - AG2
CrewAIInteroperability
autogen.interop.CrewAIInteroperability
A class implementing the Interoperable protocol for converting CrewAI tools to a general Tool format.
This class takes a CrewAITool and converts it into a standard Tool object.
convert_toolclassmethod
convert_tool(tool, **kwargs)
Converts a given CrewAI tool into a general Tool format.
This method ensures that the provided tool is a valid CrewAITool, sanitizes the tool's name, processes its description, and prepares a function to interact with the tool's arguments. It then returns a standardized Tool object.
| PARAMETER | DESCRIPTION |
|---|---|
tool |
The tool to convert, expected to be an instance of CrewAITool.TYPE: Any |
**kwargs |
Additional arguments, which are not supported by this method. TYPE: AnyDEFAULT:{} |
| RETURNS | DESCRIPTION |
|---|---|
Tool |
A standardized Tool object converted from the CrewAI tool.TYPE: Tool |
| RAISES | DESCRIPTION |
|---|---|
ValueError |
If the provided tool is not an instance of CrewAITool, or if any additional arguments are passed. |
Source code in autogen/interop/crewai/crewai.py
<br>34<br>35<br>36<br>37<br>38<br>39<br>40<br>41<br>42<br>43<br>44<br>45<br>46<br>47<br>48<br>49<br>50<br>51<br>52<br>53<br>54<br>55<br>56<br>57<br>58<br>59<br>60<br>61<br>62<br>63<br>64<br>65<br>66<br>67<br>68<br>69<br>70<br>71<br>72<br>73<br>74<br>75<br> |
<br>@classmethod<br>@require_optional_import("crewai", "interop-crewai")<br>def convert_tool(cls, tool: Any, **kwargs: Any) -> Tool:<br> """Converts a given CrewAI tool into a general `Tool` format.<br> This method ensures that the provided tool is a valid `CrewAITool`, sanitizes<br> the tool's name, processes its description, and prepares a function to interact<br> with the tool's arguments. It then returns a standardized `Tool` object.<br> Args:<br> tool (Any): The tool to convert, expected to be an instance of `CrewAITool`.<br> **kwargs (Any): Additional arguments, which are not supported by this method.<br> Returns:<br> Tool: A standardized `Tool` object converted from the CrewAI tool.<br> Raises:<br> ValueError: If the provided tool is not an instance of `CrewAITool`, or if<br> any additional arguments are passed.<br> """<br> if not isinstance(tool, CrewAITool):<br> raise ValueError(f"Expected an instance of `crewai.tools.BaseTool`, got {type(tool)}")<br> if kwargs:<br> raise ValueError(f"The CrewAIInteroperability does not support any additional arguments, got {kwargs}")<br> # needed for type checking<br> crewai_tool: CrewAITool = tool # type: ignore[no-any-unimported]<br> name = _sanitize_name(crewai_tool.name)<br> description = (<br> crewai_tool.description.split("Tool Description: ")[-1]<br> + " (IMPORTANT: When using arguments, put them all in an `args` dictionary)"<br> )<br> def func(args: crewai_tool.args_schema) -> Any: # type: ignore[no-any-unimported]<br> return crewai_tool.run(**args.model_dump())<br> return Tool(<br> name=name,<br> description=description,<br> func_or_tool=func,<br> )<br> |
get_unsupported_reasonclassmethod
get_unsupported_reason()
Source code in autogen/interop/crewai/crewai.py
<br>77<br>78<br>79<br>80<br>81<br>82<br>83<br>84<br>85<br>86<br>87<br>88<br> |
<br>@classmethod<br>def get_unsupported_reason(cls) -> Optional[str]:<br> if sys.version_info < (3, 10) or sys.version_info >= (3, 13):<br> return "This submodule is only supported for Python versions 3.10, 3.11, and 3.12"<br> with optional_import_block() as result:<br> import crewai.tools # noqa: F401<br> if not result.is_successful:<br> return "Please install `interop-crewai` extra to use this module:\n\n\tpip install ag2[interop-crewai]"<br> return None<br> |