Repository navigation
Conversation
…he batched scholar call
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Scholar.google_scholar_with_serpis designed to never raise: its retry loop returns a timeout string, and the parsing/rendering block is wrapped in a bareexceptthat returns a "No results found" string. Two lines break that contract:res.read()andjson.loads(data.decode("utf-8"))run outside everytryblock. When the Serper endpoint answers with anything that is not JSON — an HTML 403/502 error page from a proxy or gateway, an empty body, a truncated response —json.loadsraisesjson.JSONDecodeErrorstraight out of the tool.That matters most for the batched path.
Scholar.callruns multiple queries vialist(executor.map(self.google_scholar_with_serp, query)), andexecutor.mappropagates the first exception, so a single malformed response for one query discards the successful results of every other query in the batch. The escaping exception then hits the bareexceptaroundcustom_call_toolinMultiTurnReactAgent._runand is reported to the model as the misleading messageError: Tool call is not a valid JSON....The fix wraps
res.read()+json.loadsin atry/exceptthat returns a per-query error string consistent with the existing timeout message, so a malformed response degrades to one failed query instead of killing the whole batch:Validation
Offline regression tests (no network;
http.client.HTTPSConnectionis stubbed):inference/tests/test_tool_scholar_response_parsing.pypython -m pytest inference/tests/test_tool_scholar_response_parsing.py -vtest_non_json_body_returns_error_string_instead_of_raising,test_empty_body_returns_error_string_instead_of_raising,test_batch_survives_one_malformed_responseall crash withjson.JSONDecodeError: Expecting value: line 1 column 1 (char 0);test_valid_json_still_renders_resultspassed.qwen-agent==0.0.26(the version pinned inrequirements.txt).git diff --checkclean.Note:
google_search_with_serpininference/tool_search.pyhas the same unguardedres.read()/json.loadspattern. It is intentionally left out of this PR to keep the change minimal — that file is currently being modified by several open provider-integration PRs.AI assistance
This change was developed with the help of an AI coding agent (code analysis, patch drafting, and test writing); the analysis and patch were human-reviewed before submission.