Empty-query search crashes for plain text and page-list documents
Description
BaseSearch.call() accepts documents as Record, plain strings, or lists of page strings. However, when query is an empty string, it calls _get_the_front_part() before format_docs(). The fallback expects Record objects and raises AttributeError for the documented text input forms.
The issue affects KeywordSearch, FrontPageSearch, and HybridSearch, which inherit this entry point. Preformatted Record inputs and an empty document list already work.
Reproduction
Environment: Windows, Python 3.12.13, Qwen-Agent 0.0.34 installed from main at 31a4d36d123688581a9e9744427272b33ce940e0. No model or API credentials are needed.
from qwen_agent.tools import KeywordSearch
KeywordSearch().call({"query": ""}, docs=["A text document"])Actual result:
File "qwen_agent/tools/search_tools/base_search.py", line 172, in _get_the_front_part
for page in doc.raw:
AttributeError: 'str' object has no attribute 'raw'Using docs=[["First page", "Second page"]] instead produces the corresponding 'list' object has no attribute 'raw' error.
Expected Behavior
Use the existing front-of-document fallback for all supported document forms, retaining the per-document token budget and generated document URLs.
Proposed Fix
Move the existing format_docs(docs) call before the empty-query branch and pass its normalized documents to _get_the_front_part(). Leave the no-document early return and non-empty-query ranking paths unchanged.
The local regression matrix covers three search classes, text/page/Record/mixed inputs, small and large token budgets, and None/empty document lists. Before the fix: 18 failed, 12 passed. After the fix: all 30 regression cases pass; the existing keyword and hybrid search tests also pass.
This report and the fix/tests were prepared with AI assistance. The reproduction and tests were run locally without external model requests.
Source: QwenLM/Qwen-Agent