Skip to content

feat(web): expose limit for web_search#16808

Closed
BlackishGreen33 wants to merge 1 commit into
NousResearch:mainfrom
BlackishGreen33:bg/feat-web-search-limit
Closed

feat(web): expose limit for web_search#16808
BlackishGreen33 wants to merge 1 commit into
NousResearch:mainfrom
BlackishGreen33:bg/feat-web-search-limit

Conversation

@BlackishGreen33

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds an optional limit parameter to the web_search tool schema and wires it through to the existing web_search_tool() handler.

The default stays at 5 results, so existing tool calls keep the same behavior. Callers can now request a larger or smaller result set when needed.

Related Issue

Fixes #16696

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • Added optional limit to the web_search tool schema with min 1, max 100, and default 5.
  • Passed the requested limit from the registered handler into web_search_tool().
  • Clamped runtime limit values to 1..100 before calling the configured backend.
  • Updated the tool description to mention common query operators such as site:, filetype:, intitle:, -term, and exact phrases, while noting that support depends on the backend.
  • Added tests for schema shape, handler wiring, default limit behavior, and runtime clamping.

How to Test

  1. source /Users/blackishgreen03/workspace/hermes-agent/venv/bin/activate && python -m pytest tests/tools/test_web_tools_config.py -q
  2. Result: 49 passed
  3. Full suite was attempted locally on the same latest upstream base with python -m pytest tests/ -q, but this local environment is not clean for the whole repository: it fails with missing optional packages such as acp, numpy, and fastapi, plus many unrelated existing gateway/web/tool failures (16556 passed, 117 skipped, 191 failed, 66 errors).

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS, Python 3.11 using the existing local repo venv

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

For New Skills

N/A

Screenshots / Logs

Targeted test:

49 passed in 2.25s

@BlackishGreen33 BlackishGreen33 force-pushed the bg/feat-web-search-limit branch from 7c7c0ce to 8d63e82 Compare April 28, 2026 04:12
@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have tool/web Web search and extraction labels Apr 28, 2026
@BlackishGreen33

Copy link
Copy Markdown
Contributor Author

CI note after rebasing onto latest upstream main (d7528d43): all checks pass except the full test job. The current upstream main Tests workflow is also failing on the same commit, and the failed tests are outside this PR change (tools/web_tools.py and tests/tools/test_web_tools_config.py). Targeted test for this PR passes: python -m pytest tests/tools/test_web_tools_config.py -q -> 49 passed in 3.55s.

@BlackishGreen33 BlackishGreen33 marked this pull request as ready for review April 28, 2026 04:26
Copilot AI review requested due to automatic review settings April 28, 2026 04:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the web_search tool by exposing an optional limit parameter in the tool schema and wiring it through to web_search_tool(), while keeping the default behavior (5 results) unchanged.

Changes:

  • Added optional limit (min 1, max 100, default 5) to WEB_SEARCH_SCHEMA, plus updated schema/query descriptions to mention common query operators.
  • Plumbed limit through the registered web_search handler into web_search_tool().
  • Added runtime coercion/clamping for limit and added tests covering schema shape, handler wiring/defaulting, and clamping behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
tools/web_tools.py Adds limit to schema, passes it through registry handler, and clamps/coerces runtime limit to 1..100.
tests/tools/test_web_tools_config.py Adds targeted tests for schema/handler wiring and runtime clamping behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tools/web_tools.py
Comment on lines +2064 to +2069
"limit": {
"type": "integer",
"description": "Maximum number of results to return. Defaults to 5.",
"minimum": 1,
"maximum": 100,
"default": 5

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WEB_SEARCH_SCHEMA hardcodes limit bounds/default (1..100, default 5) separately from the runtime clamp and handler default. To prevent future inconsistencies, consider referencing shared constants for these values (or generating the schema from them).

Copilot uses AI. Check for mistakes.
Comment thread tools/web_tools.py
toolset="web",
schema=WEB_SEARCH_SCHEMA,
handler=lambda args, **kw: web_search_tool(args.get("query", ""), limit=5),
handler=lambda args, **kw: web_search_tool(args.get("query", ""), limit=args.get("limit", 5)),

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The handler default for limit is another hardcoded '5'. If you introduce shared constants for limit defaults/bounds, wire them through here as well so schema + runtime behavior stay in sync.

Copilot uses AI. Check for mistakes.
Comment thread tools/web_tools.py
Comment on lines +1069 to +1073
try:
limit = int(limit)
except (TypeError, ValueError):
limit = 5
limit = min(max(limit, 1), 100)

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The limit sanitization duplicates the default value (5) and clamp bounds (1..100) as literals. Consider defining module-level constants (e.g., WEB_SEARCH_DEFAULT_LIMIT/MIN/MAX) and using them here to avoid the schema/handler/default getting out of sync if the defaults change later.

Copilot uses AI. Check for mistakes.
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #16934 — your commit was cherry-picked onto current main with your authorship preserved in git log. Thanks for the contribution! Also updated the tools-reference doc page to document the new limit param and query operators. Closes #16696.

@teknium1 teknium1 closed this Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low — cosmetic, nice to have tool/web Web search and extraction type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Expose limit parameter and document query operators in web_search tool

4 participants