Skip to content

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.

fix(rag): preserve github loader source attribution (#7983)

エイカクce149db3115b
diff --git a/lib/crewai-tools/src/crewai_tools/rag/loaders/github_loader.py b/lib/crewai-tools/src/crewai_tools/rag/loaders/github_loader.py
index 0df68010f..4a431bbe6 100644
--- a/lib/crewai-tools/src/crewai_tools/rag/loaders/github_loader.py
+++ b/lib/crewai-tools/src/crewai_tools/rag/loaders/github_loader.py
@@ -103,6 +103,7 @@ class GithubLoader(BaseLoader):
content = "\n".join(all_content)
return LoaderResult(
content=content,
+ source=repo_url,
metadata={
"source": repo_url,
"repo": repo_name,
diff --git a/lib/crewai-tools/tests/rag/test_github_loader.py b/lib/crewai-tools/tests/rag/test_github_loader.py
new file mode 100644
index 000000000..b18327c61
--- /dev/null
+++ b/lib/crewai-tools/tests/rag/test_github_loader.py
@@ -0,0 +1,31 @@
+from types import SimpleNamespace
+from unittest.mock import patch
+
+from crewai_tools.rag.loaders.github_loader import GithubLoader
+from crewai_tools.rag.source_content import SourceContent
+import pytest
+
+
[email protected]("content_types", [["repo"], ["code"], ["repo", "code"]])
+def test_github_loader_preserves_repository_source(content_types: list[str]) -> None:
+ url = "https://github.com/example/project"
+ repository = SimpleNamespace(
+ full_name="example/project",
+ description="An offline repository",
+ language="Python",
+ stargazers_count=1,
+ forks_count=0,
+ get_readme=lambda: SimpleNamespace(decoded_content=b"Repository README"),
+ get_contents=lambda path: [],
+ )
+ with patch("crewai_tools.rag.loaders.github_loader.Github") as github:
+ github.return_value.get_repo.return_value = repository
+ result = GithubLoader().load(
+ SourceContent(url), metadata={"content_types": content_types}
+ )
+
+ assert result.content
+ assert result.source == url
+ assert result.source == result.metadata["source"]
+ assert result.metadata["repo"] == "example/project"
+ assert result.doc_id == GithubLoader.generate_doc_id(url, result.content)