Skip to content

Conversation

@T-rav
Copy link
Collaborator

@T-rav T-rav commented Oct 10, 2025

Summary

  • Added max_results parameter (default: 5) to search tool for controlling number of results returned
  • Updated entire search pipeline to support max_results from tool → service → API clients
  • Serper API now requests exact number of results via num parameter
  • All unit tests updated and passing (16/16 search-related tests)

Changes

  • tools/search_tool.py: Added max_results: int = 5 parameter
  • services/search_service.py: Pass max_results through fallback chain
  • clients/serper_client.py: Request specific number from Serper API
  • tests/unit/services/test_search_service_with_serper.py: Updated test expectations

Test Plan

  • ✅ All unit tests passing
  • ✅ Function signature verified with default value
  • ✅ Authentication flow tested and working

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • You can now limit the number of search results with a new “max results” option (default: 5).
    • The limit is enforced consistently across primary search and fallback to alternative providers.
    • Search output and behavior now reliably cap results to the chosen maximum.
  • Documentation

    • Updated help text and logs to reflect the new results limit option.
  • Tests

    • Unit tests updated to validate the new max results behavior across search paths.

- Add max_results parameter with default value of 5 to search_tool()
- Update fetch_with_fallback() to accept and pass max_results
- Update Serper client to request exact number of results via API
- Update DuckDuckGo client calls to use max_results
- Update test expectations to include new parameter
- All search-related unit tests passing (16/16)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@coderabbitai
Copy link

coderabbitai bot commented Oct 10, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds a max_results parameter (default 5) to the search flow, propagating from the tool to the service and client. The Serper client includes this in its request payload and truncates returned results. Tests are updated to reflect the extra argument in the Serper fetch call.

Changes

Cohort / File(s) Change Summary
Serper client param + capping
docker/clients/serper_client.py
Adds optional max_results arg; includes "num" in request payload; slices converted organic results to max_results; updates docstring; clarifies empty-return paths.
Service propagation
docker/services/search_service.py
Adds max_results to fetch_with_fallback signature and docstring; forwards max_results to Serper and DuckDuckGo fetchers; preserves existing fallback logic.
Tool integration
docker/tools/search_tool.py
Adds max_results to search_tool signature and docstring; logs "(max N results)"; passes max_results to fetch_with_fallback.
Unit test update
docker/tests/unit/services/test_search_service_with_serper.py
Updates mock assertion to expect third argument (5) in Serper fetch call.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Tool as search_tool
  participant Service as search_service.fetch_with_fallback
  participant Serper as SerperClient.fetch_search_results
  participant DDG as DuckDuckGoClient.fetch_duckduckgo_search_results

  User->>Tool: search_tool(query, max_results=5)
  Tool->>Service: fetch_with_fallback(query, api_key, max_results)

  alt Serper API key present
    Service->>Serper: fetch_search_results(query, api_key, max_results)
    Serper-->>Service: results (sliced to max_results)
    alt results not empty
      Service-->>Tool: results, "serper"
    else no results
      Service->>DDG: fetch_duckduckgo_search_results(query, max_results)
      DDG-->>Service: results (capped)
      Service-->>Tool: results, "duckduckgo"
    end
  else no Serper API key
    Service->>DDG: fetch_duckduckgo_search_results(query, max_results)
    DDG-->>Service: results (capped)
    Service-->>Tool: results, "duckduckgo"
  end

  Tool-->>User: { results <= max_results, source }
  note over Serper,DDG: Both paths respect max_results in request and response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nudge the knobs to cap the finds,
Five carrots tall, neatly aligned.
From Serper burrows or DuckDuck glades,
I ferry snippets, trimmed like blades.
Hop, hop—results in tidy stacks,
A basket full, no overflowed tracks. 🥕✨

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/add-max-results-parameter

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 634ab91 and 2fbb167.

📒 Files selected for processing (4)
  • docker/clients/serper_client.py (2 hunks)
  • docker/services/search_service.py (2 hunks)
  • docker/tests/unit/services/test_search_service_with_serper.py (1 hunks)
  • docker/tools/search_tool.py (3 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@T-rav T-rav merged commit 9298117 into main Oct 10, 2025
11 checks passed
@T-rav T-rav deleted the feat/add-max-results-parameter branch October 10, 2025 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants