Repository navigation
fix(tools-serpex): send only valid Serpex params, typed responses, clear errors - #23665
Open
divyeshradadiya wants to merge 4 commits into
Open
divyeshradadiya wants to merge 4 commits into
divyeshradadiya wants to merge 4 commits into
Conversation
Checked against the current Serpex API (backend code and live responses). - search() sends only q (plus include_content / content_results when page content is on). It used to send engine, category=web, num and time_range, none of which the API reads (engine also triggers a Deprecation response header). engine and time_range stay accepted for backward compatibility, emit a DeprecationWarning and are not sent; they are kept out of the tool schema the agent sees, so the LLM only gets search(query, num_results). num_results caps results client-side (1-10; the API returns at most 10). - New include_content / content_results (5 or 10) constructor options: page markdown for the top results, content_error in metadata when a page could not be fetched. - Responses typed with TypedDicts. Errors raise SerpexAPIError (a requests.HTTPError subclass, so existing except clauses still work) with one sentence per HTTP status: 400, 401, 402 with the balance, 429 with the wait and plan limit, 5xx not charged. - Timeout 60 s (100 s with page content) instead of 30 s, which was shorter than the server's own budget. User-Agent header added. - Example no longer calls methods that do not exist (search_with_location, gl/hl); README updated. - Tests use sanitized responses recorded from the API on 2026-10-23 (personal data replaced with placeholders). Formatted with the repo's pre-commit hooks (ruff-format, blacken-docs, prettier). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
divyeshradadiya
force-pushed
the
docs/serpex-tool-description
branch
from
October 23, 2026 08:36
f21010e to
1eb6226
Compare
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.
Description
This brings
llama-index-tools-serpexin line with the current Serpex API: what it sends, how it reads the response, how it reports errors, and the docs. I checked each point against the Serpex backend and against live responses.Request.
search()used to sendengine,category=web,numandtime_range. The API reads none of them, andenginealso earns aDeprecationresponse header. Now it sends onlyq, plusinclude_content/content_resultswhen page content is on.engine(constructor andsearch()) andtime_rangestay accepted for backward compatibility. They emit aDeprecationWarningand are not sent.search(query, num_results). Before, the LLM was offered atime_range"filter" that did nothing. The README now points toafter:YYYY-MM-DD/before:YYYY-MM-DDin the query.num_resultslimits results client-side to 1-10, since the API returns at most 10. The docstring used to say "max: 100".Page content. New optional
include_content/content_results(5 or 10) on the constructor. The top results' page markdown is appended to the document text, andmetadata["content_error"]explains a page that could not be fetched.Typed responses.
SerpexSearchResponse,SerpexSearchResultandSerpexErrorBodyare TypedDicts. Document metadata addspositionandcredits_used.enginestays in the metadata as the constant"auto", so existing readers keep working.Errors. A failed request raises
SerpexAPIError, a subclass ofrequests.exceptions.HTTPError, so existingexceptclauses still work. Its message is one sentence per status:SERPEX_API_KEY.It also carries
status_code,detailsandretryable.Timeout. 60 s, or 100 s with page content. The old 30 s was shorter than the server's own budget. Requests also send a
User-Agent.Example.
examples/serpex_example.pyno longer calls methods that don't exist (search_with_location,gl/hl). The README is updated.The version stays at 0.3.1, the unreleased bump from the first commit of this PR.
New Package?
Version Bump?
Type of Change
How Has This Been Tested?
uv run -- pytestin the packageThe tests use sanitized responses recorded from the live API (
tests/fixtures/), withrequests.getpatched, so they need no network. They cover:num_resultscapping;content_error;The pinned
mypy==0.991in this package's dev group cannot parse the numpy 2.x stubs that llama-index-core pulls in ("Type statement is only supported in Python 3.12"), with or without this change. That is why mypy was run with a current release.Suggested Checklist
I maintain Serpex.