[BUG] BraveSearchTool ignores the documented api_key argument

オープン 初心者向け
#9,762 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@Kiko0301 がすでに取り組んでいます。

2026年11月25日 から。

  • #9766 @Kiko0301 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
tooling

調査の方向性

lib/crewai-tools/src/crewai_tools/tools/brave_search_tool/brave_search_tool.py から始めてください。そこでは BraveSearchTool.__init__ は BRAVE_API_KEY のみを確認し、_run は環境を読み取ります。同じツールパッケージ内の BraveSearchToolBase を読み、api_key をどのように宣言し、環境より優先しているかを確認してから、BraveSearchTool がそのパターンに従うようにしてください。issue のスクリプトで再現し、brave search tool のテストを実行してください。完了とは、api_key= が環境変数なしで機能し、両方が設定されている場合に優先されることを意味します。

索引モデルが issue の本文から書いたものです。

説明

Description

The docs for BraveSearchTool say the API key can be passed directly:

  • docs/edge/en/tools/search-research/bravesearchtool.mdx:45 - "store your key as BRAVE_API_KEY, or pass it directly via the api_key parameter"
  • docs/edge/en/tools/search-research/bravesearchtool.mdx:115 - | api_key | str \| None | None | Brave API key. Falls back to the BRAVE_API_KEY environment variable. |

The exported class (lib/crewai-tools/src/crewai_tools/tools/brave_search_tool/brave_search_tool.py, imported as crewai_tools.BraveSearchTool) has no api_key field, so pydantic silently drops the argument, and its __init__ only checks the environment:

    def __init__(self, *args: Any, **kwargs: Any) -> None:
        super().__init__(*args, **kwargs)
        if "BRAVE_API_KEY" not in os.environ:
            raise ValueError(
                "BRAVE_API_KEY environment variable is required for BraveSearchTool"
            )

and _run sends os.environ["BRAVE_API_KEY"] in the X-Subscription-Token header.

The newer Brave tools (BraveWebSearchTool, BraveNewsSearchTool, ...) inherit BraveSearchToolBase, whose constructor does accept api_key= and use it over the environment - so the same documented behavior works for them but not for BraveSearchTool itself.

Steps to Reproduce

import os

os.environ.pop("BRAVE_API_KEY", None)

from crewai_tools import BraveSearchTool

tool = BraveSearchTool(api_key="explicit-key")

Raises:

ValueError: BRAVE_API_KEY environment variable is required for BraveSearchTool

With BRAVE_API_KEY set to env-key and BraveSearchTool(api_key="explicit-key"), construction succeeds but the tool has no api_key attribute and the request still sends env-key.

Expected Behavior

BraveSearchTool(api_key=...) should work without the environment variable and should take precedence over it, with BRAVE_API_KEY kept as the fallback - as documented and as BraveSearchToolBase already implements for the other Brave tools.

AI assistance

I used an AI coding agent to investigate, reproduce, and prepare this report, and reviewed its results. Per CONTRIBUTING.md, please apply the llm-generated label; external contributors cannot add it with my current permissions.

主要言語
Python
スター
61.2k
フォーク
9.2k
平均マージ
1日 12時間
マージ済み PR(30日)
228

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

crewAIInc/crewAI のほかの issue

crewAIInc/crewAI の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。