Skip to content

feat: add Tavily search provider to legacy web_search skill#3

Open
mani2001 wants to merge 1 commit intotysonchamp:mainfrom
mani2001:feat/tavily-migration/legacy-web-search-duckduckgo
Open

feat: add Tavily search provider to legacy web_search skill#3
mani2001 wants to merge 1 commit intotysonchamp:mainfrom
mani2001:feat/tavily-migration/legacy-web-search-duckduckgo

Conversation

@mani2001
Copy link

Summary

  • Added Tavily as a configurable search provider alongside DuckDuckGo in _legacy/skills/web_search.py
  • The SEARCH_PROVIDER environment variable controls which provider is used (tavily or duckduckgo, default: duckduckgo)
  • Existing DuckDuckGo behavior is fully preserved when SEARCH_PROVIDER is unset or set to duckduckgo

Files changed

  • _legacy/skills/web_search.py — Refactored perform_web_search() into provider-specific helpers (_perform_tavily_search, _perform_ddgs_search) with env-var-based dispatch
  • requirements.txt — Added tavily-python dependency

Dependency changes

  • Added tavily-python to requirements.txt

Environment variable changes

  • SEARCH_PROVIDER — Set to "tavily" to use Tavily, defaults to "duckduckgo"
  • TAVILY_API_KEY — Required when SEARCH_PROVIDER=tavily (read automatically by the Tavily SDK)

Notes for reviewers

  • This is an additive/parallel migration — no existing functionality is removed or changed
  • The legacy skill mirrors the provider dispatch pattern used in the active tools directory

🤖 Generated with Claude Code

Automated Review

  • Passed after 1 attempt(s)
  • Final review: The migration correctly implements the additive strategy: perform_web_search() is split into a private _perform_ddgs_search() (unchanged logic) and a new _perform_tavily_search(), with a dispatcher checking the SEARCH_PROVIDER env var. tavily-python is added to requirements.txt. The Tavily SDK is used correctly — TavilyClient() auto-reads TAVILY_API_KEY from the environment, the client.search() call is valid, and response fields (title, url, content) match the Tavily API response schema. DuckDuckGo behavior is fully preserved as the default. No regressions, no dead code, no unintended changes. Two minor points noted but neither is blocking.

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces Tavily as a configurable search provider for the legacy web_search skill, providing an alternative to the existing DuckDuckGo search. It preserves the original DuckDuckGo functionality while adding a new option controlled by an environment variable. The change includes refactoring the search logic into provider-specific helpers and adding a new dependency.

Highlights

  • New Feature: Introduced Tavily as an alternative search provider for the web_search skill.
  • Configuration: The SEARCH_PROVIDER environment variable allows switching between Tavily and DuckDuckGo.
  • Dependencies: Added tavily-python as a new dependency.
  • Backward Compatibility: Maintained existing DuckDuckGo functionality as the default search provider.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces Tavily as a new search provider, which can be configured via an environment variable. The implementation is a good step forward, but there are a few areas for improvement regarding error handling to make the code more robust. Specifically, potential ImportErrors are not handled within the try...except blocks, which could lead to application crashes. I've provided suggestions to move the imports inside the try blocks and to improve exception handling. I also noted an opportunity to make dictionary access safer in the DuckDuckGo search implementation and to make the provider selection logic more explicit.

Comment on lines +11 to +24
from tavily import TavilyClient
try:
client = TavilyClient()
response = client.search(query=query, max_results=5, search_depth="basic")
results = response.get("results", [])
if not results:
return "No results found."

summary = ""
for r in results:
summary += f"- [{r['title']}]({r['url']}): {r.get('content', '')}\n"
return summary
except Exception as e:
return f"Error performing search: {e}"

Choose a reason for hiding this comment

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

high

The try...except block does not cover the import statement. If the tavily-python package is not installed, an ImportError will be raised and crash the application instead of being handled gracefully. The import should be moved inside the try block. Additionally, it's good practice to log exceptions before returning an error message to aid in debugging.

Suggested change
from tavily import TavilyClient
try:
client = TavilyClient()
response = client.search(query=query, max_results=5, search_depth="basic")
results = response.get("results", [])
if not results:
return "No results found."
summary = ""
for r in results:
summary += f"- [{r['title']}]({r['url']}): {r.get('content', '')}\n"
return summary
except Exception as e:
return f"Error performing search: {e}"
try:
from tavily import TavilyClient
client = TavilyClient()
response = client.search(query=query, max_results=5, search_depth="basic")
results = response.get("results", [])
if not results:
return "No results found."
summary = ""
for r in results:
summary += f"- [{r['title']}]({r['url']}): {r.get('content', '')}\n"
return summary
except ImportError:
logging.error("Tavily SDK not installed. Please run 'pip install tavily-python'.")
return "Error: Tavily search provider is not available."
except Exception as e:
logging.error(f"Error performing Tavily search: {e}")
return f"Error performing search: {e}"

Comment on lines 27 to 38
from ddgs import DDGS
try:
results = DDGS().text(query, max_results=5)
if not results:
return "No results found."

summary = ""
for r in results:
summary += f"- [{r['title']}]({r['href']}): {r['body']}\n"
return summary
except Exception as e:
return f"Error performing search: {e}"

Choose a reason for hiding this comment

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

high

There are a couple of improvements that can be made here:

  1. The try...except block does not cover the import statement. If the ddgs package is not installed, an ImportError will be raised and crash the application. The import should be moved inside the try block.
  2. Using r['body'] can raise a KeyError if the body key is missing in a result. It's safer to use r.get('body', '') for robustness, which is consistent with the Tavily implementation.

The suggestion below addresses both points.

Suggested change
from ddgs import DDGS
try:
results = DDGS().text(query, max_results=5)
if not results:
return "No results found."
summary = ""
for r in results:
summary += f"- [{r['title']}]({r['href']}): {r['body']}\n"
return summary
except Exception as e:
return f"Error performing search: {e}"
try:
from ddgs import DDGS
results = DDGS().text(query, max_results=5)
if not results:
return "No results found."
summary = ""
for r in results:
summary += f"- [{r['title']}]({r['href']}): {r.get('body', '')}\n"
return summary
except ImportError:
logging.error("DDGS SDK not installed. Please run 'pip install ddgs'.")
return "Error: DuckDuckGo search provider is not available."
except Exception as e:
logging.error(f"Error performing DDGS search: {e}")
return f"Error performing search: {e}"

Comment on lines +42 to +44
if provider == "tavily":
return _perform_tavily_search(query)
return _perform_ddgs_search(query)

Choose a reason for hiding this comment

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

medium

The current implementation silently defaults to DuckDuckGo for any SEARCH_PROVIDER value other than "tavily". This could be confusing if a user makes a typo (e.g., "tavilyy"). It would be more user-friendly to explicitly handle the "duckduckgo" case and log a warning for unknown providers before defaulting.

    if provider == "tavily":
        return _perform_tavily_search(query)
    elif provider == "duckduckgo":
        return _perform_ddgs_search(query)
    else:
        logging.warning(f"Unknown SEARCH_PROVIDER '{provider}', defaulting to duckduckgo.")
        return _perform_ddgs_search(query)

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.

1 participant