Skip to content

feat(tools): add WikipediaSearchTool to crewai-tools - #6848

Open
Toprak1yu wants to merge 9 commits into
crewAIInc:mainfrom
Toprak1yu:feat/add-wikipedia-search-tool
Open

feat(tools): add WikipediaSearchTool to crewai-tools#6848
Toprak1yu wants to merge 9 commits into
crewAIInc:mainfrom
Toprak1yu:feat/add-wikipedia-search-tool

Conversation

@Toprak1yu

@Toprak1yu Toprak1yu commented Aug 6, 2026

Copy link
Copy Markdown
## Description

Adds `WikipediaSearchTool` to `crewai-tools`, allowing agents to search Wikipedia and retrieve article summaries
or full content.

## Features

- **Search & Summarize**: Retrieves titles, URLs, and summaries for matching Wikipedia articles.
- **Language & Limits**: Supports language selection (e.g., `'en'`, `'tr'`) and result limits (`limit=3`).
- **Full Content Option**: Includes `load_full_content=True` flag to fetch complete article text when needed.
- **Safe Handling**: Gracefully handles disambiguation pages and missing articles.

## Verification

- Added unit tests covering all features (`7 passed`).
- Passed `ruff check`, `ruff format`, and `mypy` checks.

## Labels

- `llm-generated`

Copilot AI lite review requested due to automatic review settings August 6, 2026 20:14
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds WikipediaSearchTool with optional dependency installation, package exports, configurable search and content retrieval, error handling, tests, and usage documentation.

Changes

Wikipedia search tool

Layer / File(s) Summary
Tool contract and package wiring
lib/crewai-tools/pyproject.toml, lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py, lib/crewai-tools/src/crewai_tools/__init__.py, lib/crewai-tools/src/crewai_tools/tools/__init__.py
Adds the optional wikipedia dependency, defines the tool schema and configuration, guards model rebuilding, and exports WikipediaSearchTool.
Search and result handling
lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py
Uses Wikipedia REST endpoints for searches, summaries, and full content. Applies language, result-limit, and User-Agent settings. Handles missing dependencies, empty results, redirects, disambiguation, missing pages, and API errors.
Validation and usage documentation
lib/crewai-tools/tests/tools/test_wikipedia_search_tool.py, lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/README.md
Tests search results, HTTP requests, content modes, errors, client isolation, limit handling, schema validation, redirects, logging, dependency handling, and result formatting. Documents installation, arguments, examples, CrewAI integration, and error behavior.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant WikipediaSearchTool
  participant WikipediaClient
  participant WikipediaAPI as Wikipedia REST API
  Caller->>WikipediaSearchTool: submit search query and options
  WikipediaSearchTool->>WikipediaClient: search with language, limit, and User-Agent
  WikipediaClient->>WikipediaAPI: request search results
  WikipediaAPI-->>WikipediaClient: return article titles
  WikipediaSearchTool->>WikipediaClient: retrieve summaries or full content
  WikipediaClient->>WikipediaAPI: request page data
  WikipediaAPI-->>WikipediaClient: return article data or errors
  WikipediaSearchTool-->>Caller: return formatted results
Loading

Suggested reviewers: lorenzejay

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the addition of WikipediaSearchTool to crewai-tools.
Description check ✅ Passed The description directly explains the new WikipediaSearchTool, its features, and verification results.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/crewai-tools/pyproject.toml`:
- Around line 155-157: Replace the global wikipedia dependency in
lib/crewai-tools/pyproject.toml (lines 155-157) with an instance-configurable
Wikipedia client, then update the configuration logic in
WikipediaSearchTool._run
(lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py,
lines 90-94) to create and use a client instance whose language and User-Agent
are scoped per call instead of mutating global package state.

In
`@lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py`:
- Around line 52-54: Constrain the WikipediaSearchTool limit field to the valid
1–10 range and add equivalent validation at the start of _run() so direct calls
cannot bypass WikipediaSearchToolSchema. Reject invalid configured or runtime
limits before invoking wikipedia.search, while preserving the existing
valid-result behavior.
- Line 134: Update the result formatting return in the Wikipedia search tool to
create one separator containing the divider and surrounding blank lines, then
join formatted_results with that separator so no divider precedes the first
result. Add a test covering at least two search results and verifying the
separator appears only between them.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3d59f6a0-50a6-454f-b417-1bd9ad442d00

📥 Commits

Reviewing files that changed from the base of the PR and between 18c52c4 and f210916.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • lib/crewai-tools/pyproject.toml
  • lib/crewai-tools/src/crewai_tools/__init__.py
  • lib/crewai-tools/src/crewai_tools/tools/__init__.py
  • lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/README.md
  • lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/__init__.py
  • lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py
  • lib/crewai-tools/tests/tools/test_wikipedia_search_tool.py

Comment thread lib/crewai-tools/pyproject.toml Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a new WikipediaSearchTool to crewai_tools, including documentation and pytest coverage, and exposes it via package exports.

Changes:

  • Introduces WikipediaSearchTool with language/limit configuration, summary vs full content retrieval, and error handling.
  • Adds a README documenting installation, arguments, and usage examples.
  • Adds pytest unit tests and exports the tool from crewai_tools and crewai_tools.tools.

Reviewed changes

Copilot reviewed 6 out of 8 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py Implements the Wikipedia search tool and its schema.
lib/crewai-tools/tests/tools/test_wikipedia_search_tool.py Adds unit tests for main success/error paths.
lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/README.md Documents tool installation, arguments, and examples.
lib/crewai-tools/src/crewai_tools/tools/init.py Exports WikipediaSearchTool from the tools package.
lib/crewai-tools/src/crewai_tools/init.py Exports WikipediaSearchTool from the top-level package.
lib/crewai-tools/pyproject.toml Adds an optional dependency group for wikipedia.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

f"Title: {title}\nNote: Error retrieving details: {e!s}"
)

return "\n\n" + "-" * 80 + "\n\n".join(formatted_results)
Comment on lines +59 to +68
def __init__(self, **kwargs: Any) -> None:
super().__init__(**kwargs)
self._initialize_wikipedia()

def _initialize_wikipedia(self) -> None:
if not WIKIPEDIA_AVAILABLE:
raise ImportError(
"The 'wikipedia' package is required to use the WikipediaSearchTool. "
"Please install it using your package manager (e.g., `pip install wikipedia` or `uv add wikipedia`)."
)
Comment on lines +78 to +82
if not WIKIPEDIA_AVAILABLE:
return (
"Error: The 'wikipedia' package is required to use WikipediaSearchTool. "
"Please install it using your package manager (e.g., `pip install wikipedia` or `uv add wikipedia`)."
)
Comment on lines +90 to +91
wikipedia.set_user_agent(self.user_agent)
wikipedia.set_lang(target_lang)
Comment on lines +84 to +85
target_lang = lang or self.lang
target_limit = limit or self.limit
Comment on lines +1 to +9
from unittest.mock import MagicMock, patch

from crewai_tools import WikipediaSearchTool
import pytest


@pytest.fixture
def tool():
return WikipediaSearchTool()
f"Title: {title}\nNote: Error retrieving details: {e!s}"
)

return "\n\n" + "-" * 80 + "\n\n".join(formatted_results)
Copilot AI review requested due to automatic review settings August 6, 2026 20:44

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py`:
- Around line 38-58: Add concise docstrings to the public properties content and
summary on WikipediaPage and the methods search, page, summary, and get_content
on WikipediaClient. Document each input and return value, and explicitly
describe PageError or DisambiguationError behavior for methods that can raise
them, without changing runtime behavior.
- Around line 64-71: Validate and normalize the lang argument in
WikipediaSearchTool.__init__ before constructing api_url: lowercase it, accept
only a valid Wikipedia language-subdomain format, and reject URL delimiters or
other invalid characters. Raise an appropriate validation error for invalid
values, and add a regression test confirming values such as
“en@attacker.example#” are rejected before any request is created.
- Around line 290-297: Update the summary branch in the search-result loop to
call client.summary with the resolved page.title returned by client.page, while
preserving auto_suggest=False. Keep the full-content branch and existing body
formatting unchanged.

In `@lib/crewai-tools/tests/tools/test_wikipedia_search_tool.py`:
- Around line 143-153: Expand test_wikipedia_client_instance_isolation coverage
with mocked requests.get behavior tests for WikipediaClient.search, page,
summary, and get_content. Assert request outcomes for successful responses, API
error conversion, redirects, missing pages, and disambiguation parsing,
including a redirected title case; focus assertions on public behavior rather
than request-construction internals.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3ec9a4e3-8ac3-44e0-b1af-616647363d3b

📥 Commits

Reviewing files that changed from the base of the PR and between f210916 and acae717.

📒 Files selected for processing (2)
  • lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py
  • lib/crewai-tools/tests/tools/test_wikipedia_search_tool.py

Comment thread lib/crewai-tools/tests/tools/test_wikipedia_search_tool.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py (1)

359-363: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Do not log the raw search query.

search_query is user-controlled and can contain sensitive data. The error log can retain it when the request fails. Log the exception type or a request identifier instead.

Proposed fix
-            logger.error(f"Wikipedia search failed for query '{search_query}': {e}")
+            logger.error("Wikipedia search failed: %s", type(e).__name__)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py`
around lines 359 - 363, Update the exception handler around client.search in
WikipediaSearchTool to remove the raw user-controlled search_query from
logger.error. Log the exception type or an appropriate request identifier while
preserving the existing error return behavior and exception details returned to
the caller.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/crewai-tools/tests/tools/test_wikipedia_search_tool.py`:
- Around line 358-360: Strengthen the assertions in the Wikipedia search test
around tool._run by verifying the mocked client.summary call receives the
resolved title "Python (programming language)", rather than only checking the
returned text. Keep the existing result assertions and ensure the request-title
assertion distinguishes page.title from the original search query.

---

Outside diff comments:
In
`@lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py`:
- Around line 359-363: Update the exception handler around client.search in
WikipediaSearchTool to remove the raw user-controlled search_query from
logger.error. Log the exception type or an appropriate request identifier while
preserving the existing error return behavior and exception details returned to
the caller.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c255fbbb-2a56-4ed4-8c53-c7a080c46e17

📥 Commits

Reviewing files that changed from the base of the PR and between acae717 and b7dc1c6.

📒 Files selected for processing (2)
  • lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py
  • lib/crewai-tools/tests/tools/test_wikipedia_search_tool.py

Comment thread lib/crewai-tools/tests/tools/test_wikipedia_search_tool.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 8 changed files in this pull request and generated 5 comments.

Suppressed comments (4)

lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py:154

  • auto_suggest is part of the public method signatures but isn’t used in either page() or summary(). This can confuse callers into thinking the behavior is supported. Consider (mandatory) either implementing the parameter’s behavior or removing it from the signature (if it’s kept only for compatibility, document explicitly that it’s unused/ignored).
    def page(self, title: str, auto_suggest: bool = False) -> WikipediaPage:

lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py:227

  • auto_suggest is part of the public method signatures but isn’t used in either page() or summary(). This can confuse callers into thinking the behavior is supported. Consider (mandatory) either implementing the parameter’s behavior or removing it from the signature (if it’s kept only for compatibility, document explicitly that it’s unused/ignored).
    def summary(self, title: str, auto_suggest: bool = False) -> str:

lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py:363

  • Logging exceptions with formatted strings drops traceback context, which makes production debugging harder. Consider (optional) using logger.exception(...) in the except blocks (or passing exc_info=True) so stack traces are retained; you can still keep the user-facing returned error strings as-is.
        try:
            search_results = client.search(search_query, results=target_limit)
        except Exception as e:
            logger.error(f"Wikipedia search failed for query '{search_query}': {e}")
            return f"Error searching Wikipedia for '{search_query}': {e!s}"

lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py:395

  • Logging exceptions with formatted strings drops traceback context, which makes production debugging harder. Consider (optional) using logger.exception(...) in the except blocks (or passing exc_info=True) so stack traces are retained; you can still keep the user-facing returned error strings as-is.
                logger.warning(
                    f"Failed to fetch details for Wikipedia page '{title}': {e}"
                )

from pydantic import BaseModel, ConfigDict, Field


logger = logging.getLogger(__name__)
WIKIPEDIA_AVAILABLE = True
except ImportError:
WIKIPEDIA_AVAILABLE = False

Copilot AI review requested due to automatic review settings August 6, 2026 21:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 8 changed files in this pull request and generated no new comments.

Suppressed comments (3)

lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py:23

  • This tool currently requires the third-party wikipedia package (WIKIPEDIA_AVAILABLE checks + package_dependencies=["wikipedia"] + optional extra), but the implementation does not use the wikipedia library APIs (it uses requests against the MediaWiki API directly). This adds an extra dependency and a hard runtime gate that doesn’t appear necessary given requests/beautifulsoup4 are already core dependencies.
WIKIPEDIA_AVAILABLE = importlib.util.find_spec("wikipedia") is not None

try:
    from wikipedia.exceptions import (  # type: ignore[import-untyped]
        DisambiguationError,
        PageError,
        WikipediaException,
    )

lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py:364

  • WikipediaClient(...) can raise ValueError for an invalid lang (see WikipediaClient.__init__), but _run constructs the client outside the try block. That means an invalid language code will raise and potentially crash tool execution instead of returning a user-friendly error string like the other failure paths.
        client: WikipediaClient = kwargs.get("client") or WikipediaClient(
            lang=target_lang, user_agent=self.user_agent
        )

lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/README.md:30

  • The installation command in this tool README uses uv add crewai-tools ..., but other tool READMEs in this repo consistently use uv add crewai[tools] .... Using the same pattern here avoids confusion and keeps the docs consistent.
uv add crewai-tools wikipedia

Copilot AI review requested due to automatic review settings August 6, 2026 21:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 8 changed files in this pull request and generated no new comments.

Suppressed comments (4)

lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py:12

  • WIKIPEDIA_AVAILABLE is intended to gate optional dependencies, but bs4 and requests are imported unconditionally at module import time. If either dependency is missing, importing this module will raise ImportError before _initialize_wikipedia() / _run() can emit the friendly error message, so the “missing dependencies” path can’t work as written.
from bs4 import BeautifulSoup, Tag
from crewai.tools import BaseTool, EnvVar
from pydantic import BaseModel, ConfigDict, Field
import requests

lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py:357

  • WikipediaClient(...) construction happens outside the try: block. If a caller passes an invalid lang (which raises ValueError in WikipediaClient.__init__), the tool will raise instead of returning a graceful error string.
        client: WikipediaClient = kwargs.get("client") or WikipediaClient(
            lang=target_lang, user_agent=self.user_agent
        )

lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/README.md:31

  • The installation instructions recommend installing the third-party wikipedia package, but the tool itself uses requests + beautifulsoup4 directly (and doesn’t import wikipedia). Since this PR adds a wikipedia extra in crewai-tools, it would be clearer/less error-prone to document installing via that extra (or explicitly list requests/beautifulsoup4).
Install the `crewai-tools` package along with the `wikipedia` dependency:

```bash
# Using pip
pip install 'crewai[tools]' wikipedia

lib/crewai-tools/pyproject.toml:157

  • This adds a wikipedia optional extra (wikipedia>=1.4.0), but the new tool implementation doesn’t import or use the wikipedia library anywhere (it calls the MediaWiki API via requests/beautifulsoup4 directly). This makes the extra/lockfile dependency look unused and potentially confusing for consumers.
wikipedia = [
    "wikipedia>=1.4.0",
]

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py (1)

22-34: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the public exception contract.

Add docstrings for WikipediaException, PageError, and DisambiguationError. Define when each exception occurs. Document the title and options attributes on DisambiguationError.

As per coding guidelines, “Document public APIs and complex logic in Python code.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py`
around lines 22 - 34, Document the public exception contract by adding class
docstrings to WikipediaException and PageError that describe when each is
raised, and to DisambiguationError that describes its occurrence and its title
and options attributes. Keep the existing inheritance, constructor behavior, and
stored attribute names unchanged.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py`:
- Around line 8-19: Make the Wikipedia dependencies lazy: remove the
module-level bs4 and requests imports, import requests inside
WikipediaClient._request(), and import BeautifulSoup and Tag only within the
disambiguation logic that uses them. Preserve WIKIPEDIA_AVAILABLE and the
documented dependency-error behavior in _initialize_wikipedia() and _run(), and
add module-load coverage in the WikipediaSearchTool tests for environments
without these optional packages.

---

Nitpick comments:
In
`@lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py`:
- Around line 22-34: Document the public exception contract by adding class
docstrings to WikipediaException and PageError that describe when each is
raised, and to DisambiguationError that describes its occurrence and its title
and options attributes. Keep the existing inheritance, constructor behavior, and
stored attribute names unchanged.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3c66d270-4f31-4628-b64e-04d1c636ef99

📥 Commits

Reviewing files that changed from the base of the PR and between 18c52c4 and 500403b.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • lib/crewai-tools/pyproject.toml
  • lib/crewai-tools/src/crewai_tools/__init__.py
  • lib/crewai-tools/src/crewai_tools/tools/__init__.py
  • lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/README.md
  • lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/__init__.py
  • lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py
  • lib/crewai-tools/tests/tools/test_wikipedia_search_tool.py
🚧 Files skipped from review as they are similar to previous changes (4)
  • lib/crewai-tools/src/crewai_tools/init.py
  • lib/crewai-tools/pyproject.toml
  • lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/README.md
  • lib/crewai-tools/src/crewai_tools/tools/init.py

Copilot AI review requested due to automatic review settings August 6, 2026 21:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 7 changed files in this pull request and generated 1 comment.

Suppressed comments (4)

lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py:394

  • This uses eager f-string interpolation in logging. Prefer parameterized logging (e.g., logger.warning(\"... %s\", ...)) to avoid unnecessary string formatting when the log level is disabled, and to keep logging consistent with the earlier logger.error usage.
                logger.warning(
                    f"Failed to fetch details for Wikipedia page '{title}': {e}"
                )

lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py:222

  • The fallback URL construction interpolates page_title directly into the path; titles can include spaces and other characters that should be URL-encoded. If fullurl is missing, this can generate invalid URLs. Consider URL-encoding the title when building the fallback (e.g., via urllib.parse.quote).
        page_title = str(page_info.get("title", title))
        page_url = str(
            page_info.get(
                "fullurl",
                f"https://{self.lang.lower()}.wikipedia.org/wiki/{page_title}",
            )
        )

lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py:152

  • The auto_suggest parameter is exposed but not used in page() (and similarly in summary()), which can mislead callers into thinking it changes behavior. Either implement the behavior, remove the parameter, or clearly document that it is currently ignored (and why) to avoid an ambiguous API.
    def page(self, title: str, auto_suggest: bool = False) -> WikipediaPage:

lib/crewai-tools/tests/tools/test_wikipedia_search_tool.py:368

  • Indexing into call_args_list[3] makes this test fragile to harmless internal changes (e.g., adding an extra request). Prefer asserting based on matching a specific call (e.g., filtering calls by params['prop'] == 'extracts' or params containing 'exintro') rather than relying on a fixed call index.
    summary_call_params = mock_get.call_args_list[3].kwargs["params"]

Comment on lines +118 to +120
response = requests.get(
self.api_url, params=params, headers=headers, timeout=10
)
Copilot AI review requested due to automatic review settings August 6, 2026 21:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 7 changed files in this pull request and generated no new comments.

Suppressed comments (2)

lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/README.md:31

  • The installation instructions suggest installing beautifulsoup4 and requests separately, but crewai-tools already declares both as required dependencies (see lib/crewai-tools/pyproject.toml). Recommending them explicitly here is redundant and can confuse users about what they need to install.
Install the `crewai-tools` package along with the `beautifulsoup4` and `requests` dependencies:

```bash
# Using pip
pip install 'crewai[tools]' beautifulsoup4 requests

lib/crewai-tools/src/crewai_tools/tools/wikipedia_search_tool/wikipedia_search_tool.py:162

  • auto_suggest is documented as a supported parameter on WikipediaClient.page(), but it is never used in the implementation. Passing auto_suggest=True currently has no effect, which is misleading for API consumers.
    def page(self, title: str, auto_suggest: bool = False) -> WikipediaPage:
        """Retrieves page information and constructs a WikipediaPage instance.

        Args:
            title (str): Title of the Wikipedia page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants