From c5e037b92c11a1f3d68c1b5159675cc43f3fc0a3 Mon Sep 17 00:00:00 2001 From: Aakash Tembhare Date: Sun, 1 Nov 2026 16:06:20 +0530 Subject: [PATCH] fix(tools): preserve configured content_types in GithubSearchTool --- .../github_search_tool/github_search_tool.py | 6 ++++-- .../tests/tools/test_search_tools.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/crewai-tools/src/crewai_tools/tools/github_search_tool/github_search_tool.py b/lib/crewai-tools/src/crewai_tools/tools/github_search_tool/github_search_tool.py index 724c38edb0..deb6dbf75d 100644 --- a/lib/crewai-tools/src/crewai_tools/tools/github_search_tool/github_search_tool.py +++ b/lib/crewai-tools/src/crewai_tools/tools/github_search_tool/github_search_tool.py @@ -42,10 +42,12 @@ def __init__( content_types: list[str] | None = None, **kwargs: Any, ) -> None: + if content_types is not None: + kwargs["content_types"] = content_types super().__init__(**kwargs) - if github_repo and content_types: - self.add(repo=github_repo, content_types=content_types) + if github_repo: + self.add(repo=github_repo, content_types=self.content_types) self.description = f"A tool that can be used to semantic search a query the {github_repo} github repo's content. This is not the GitHub API, but instead a tool that can provide semantic search capabilities." self.args_schema = FixedGithubSearchToolSchema self._generate_description() diff --git a/lib/crewai-tools/tests/tools/test_search_tools.py b/lib/crewai-tools/tests/tools/test_search_tools.py index 533be1ea24..83d2fe4b6c 100644 --- a/lib/crewai-tools/tests/tools/test_search_tools.py +++ b/lib/crewai-tools/tests/tools/test_search_tools.py @@ -361,3 +361,20 @@ def test_github_search_tool(mock_adapter): mock_adapter.query.assert_called_once_with( "tell me about crewai repo", similarity_threshold=0.6, limit=5 ) + + # ensure content_types configured at construction is retained on dynamic tool + mock_adapter.query.reset_mock() + mock_adapter.add.reset_mock() + + tool = GithubSearchTool( + gh_token="test_token", + content_types=["repo"], + adapter=mock_adapter, + ) + assert tool.content_types == ["repo"] + tool.add(repo="crewai/crewai") + mock_adapter.add.assert_called_once_with( + "https://github.com/crewai/crewai", + data_type=DataType.GITHUB, + metadata={"content_types": ["repo"], "gh_token": "test_token"}, + )