From 824c88423cb3d6c498fa2b09d85c533d085156b7 Mon Sep 17 00:00:00 2001 From: Willsgao <43256529+Willsgao@users.noreply.github.com> Date: Thu, 25 Jun 2026 13:10:29 +0800 Subject: [PATCH] =?UTF-8?q?fix(agent):=20log=20Wikipedia=20disambiguation?= =?UTF-8?q?=20and=20page=20errors=20instead=20of=20s=E2=80=A6=20(#16207)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Problem The Wikipedia tool silently swallows all exceptions with `except Exception: pass`, making it impossible to debug failures when fetching Wikipedia pages. ## Fix Replace the bare `except Exception: pass` with specific exception handling: - `DisambiguationError`: log available options - `PageError`: log page not found - `Exception`: log unexpected errors with full traceback Co-authored-by: wills Co-authored-by: Zhichang Yu --- agent/tools/wikipedia.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/agent/tools/wikipedia.py b/agent/tools/wikipedia.py index 8e0b9c3fe6..5bd76d80ee 100644 --- a/agent/tools/wikipedia.py +++ b/agent/tools/wikipedia.py @@ -62,10 +62,20 @@ class WikipediaParam(ToolParamBase): } class Wikipedia(ToolBase, ABC): + """Wikipedia search tool that retrieves and processes Wikipedia articles.""" + component_name = "Wikipedia" @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 60))) def _invoke(self, **kwargs): + """Search Wikipedia for articles matching the query and return formalized content. + + Args: + **kwargs: Must include 'query' key with the search keyword. + + Returns: + Formatted Wikipedia content or error message. + """ if self.check_if_canceled("Wikipedia processing"): return @@ -88,8 +98,12 @@ class Wikipedia(ToolBase, ABC): try: pages.append(wikipedia.page(p)) - except Exception: - pass + except wikipedia.exceptions.DisambiguationError as e: + logging.info(f"Wikipedia disambiguation for '{p}', options: {e.options[:5]}") + except wikipedia.exceptions.PageError: + logging.info(f"Wikipedia page not found: '{p}'") + except Exception as e: + logging.exception(f"Unexpected error fetching Wikipedia page '{p}': {e}") self._retrieve_chunks(pages, get_title=lambda r: r.title, get_url=lambda r: r.url,