From 7c29545afb14e77eaf17aa1b419ab0afcb2f89e1 Mon Sep 17 00:00:00 2001 From: Thiago Moretto Date: Wed, 28 Jan 2026 21:31:41 -0300 Subject: [PATCH] Extract module name --- lib/crewai/src/crewai/cli/plus_api.py | 2 +- lib/crewai/src/crewai/cli/tools/main.py | 2 ++ lib/crewai/src/crewai/cli/utils.py | 11 +++++++++++ lib/crewai/tests/cli/test_plus_api.py | 2 +- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/crewai/src/crewai/cli/plus_api.py b/lib/crewai/src/crewai/cli/plus_api.py index 456f8ed2b..3f9a1468d 100644 --- a/lib/crewai/src/crewai/cli/plus_api.py +++ b/lib/crewai/src/crewai/cli/plus_api.py @@ -69,7 +69,7 @@ class PlusAPI: "file": encoded_file, "description": description, "available_exports": available_exports, - "tools_metadata": {"tools": tools_metadata} if tools_metadata else None, + "tools_metadata": {"package": handle, "tools": tools_metadata} if tools_metadata else None, } return self._make_request("POST", f"{self.TOOLS_RESOURCE}", json=params) diff --git a/lib/crewai/src/crewai/cli/tools/main.py b/lib/crewai/src/crewai/cli/tools/main.py index 4b2991244..81599d01c 100644 --- a/lib/crewai/src/crewai/cli/tools/main.py +++ b/lib/crewai/src/crewai/cli/tools/main.py @@ -260,6 +260,8 @@ class ToolCommand(BaseCommand, PlusAPIMixin): for tool in tools_metadata: console.print(f" [bold cyan]{tool.get('name', 'Unknown')}[/bold cyan]") + if tool.get("module"): + console.print(f" Module: {tool.get('module')}") console.print(f" Name: {tool.get('humanized_name', 'N/A')}") console.print(f" Description: {tool.get('description', 'N/A')[:80]}{'...' if len(tool.get('description', '')) > 80 else ''}") diff --git a/lib/crewai/src/crewai/cli/utils.py b/lib/crewai/src/crewai/cli/utils.py index 602269b57..dcbf6e750 100644 --- a/lib/crewai/src/crewai/cli/utils.py +++ b/lib/crewai/src/crewai/cli/utils.py @@ -591,8 +591,19 @@ def _extract_single_tool_metadata(tool_class: type) -> dict[str, Any] | None: schema = _unwrap_schema(core_schema) fields = schema.get("schema", {}).get("fields", {}) + try: + file_path = inspect.getfile(tool_class) + relative_path = Path(file_path).relative_to(Path.cwd()) + module_path = relative_path.with_suffix("") + if module_path.parts[0] == "src": + module_path = Path(*module_path.parts[1:]) + module = ".".join(module_path.parts) + except (TypeError, ValueError): + module = tool_class.__module__ + return { "name": tool_class.__name__, + "module": module, "humanized_name": _extract_field_default( fields.get("name"), fallback=tool_class.__name__ ), diff --git a/lib/crewai/tests/cli/test_plus_api.py b/lib/crewai/tests/cli/test_plus_api.py index bb97c18fc..17d5275c9 100644 --- a/lib/crewai/tests/cli/test_plus_api.py +++ b/lib/crewai/tests/cli/test_plus_api.py @@ -261,7 +261,7 @@ class TestPlusAPI(unittest.TestCase): "file": encoded_file, "description": description, "available_exports": available_exports, - "tools_metadata": {"tools": tools_metadata}, + "tools_metadata": {"package": handle, "tools": tools_metadata}, } mock_make_request.assert_called_once_with( "POST", "/crewai_plus/api/v1/tools", json=params