Skip to content

feat: migrate web search to support Tavily alongside DuckDuckGo#4

Open
tavily-integrations wants to merge 1 commit intotysonchamp:mainfrom
Tavily-FDE:feat/tavily-migration/active-web-search-ddgs
Open

feat: migrate web search to support Tavily alongside DuckDuckGo#4
tavily-integrations wants to merge 1 commit intotysonchamp:mainfrom
Tavily-FDE:feat/tavily-migration/active-web-search-ddgs

Conversation

@tavily-integrations
Copy link
Copy Markdown

Summary

Adds Tavily as an opt-in search backend in tools/web_search.py. When the TAVILY_API_KEY environment variable is set, web searches use the Tavily API; otherwise the existing DuckDuckGo (ddgs) path is used as a fallback.

This is an additive change — no existing functionality is removed.

Changes

  • tools/web_search.py: Refactored perform_web_search() to dispatch to _tavily_search() or _ddgs_search() based on whether TAVILY_API_KEY is present in the environment. Added import os.
  • requirements.txt: Added tavily-python dependency (kept ddgs).
  • env.example: Added TAVILY_API_KEY= so operators know the variable is available.

Dependency changes

  • Added tavily-python to requirements.txt

Environment variable changes

  • Added TAVILY_API_KEY (optional; activates Tavily when set)

Notes for reviewers

  • The DuckDuckGo code path is fully preserved as the default fallback.
  • Tavily search uses search_depth="basic" and max_results=5 to match existing behavior.

🤖 Generated with Claude Code

Automated Review

  • Passed after 1 attempt(s)
  • Final review: The migration correctly adds Tavily as a configurable search provider alongside DuckDuckGo. The implementation is clean, scoped to only the three stated files, preserves existing functionality, and follows recommended Tavily SDK patterns. No critical or major issues found.

Copy link
Copy Markdown

@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 an alternative web search provider alongside DuckDuckGo, refactoring the search logic into modular functions. Feedback was provided to ensure DuckDuckGo results are correctly validated by converting the generator to a list and to improve observability by adding error logging to the search wrapper.

Comment on lines +28 to +30
results = DDGS().text(query, max_results=5)
if not results:
return "No results found."
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The DDGS().text() method in the duckduckgo_search library (and similar wrappers) often returns a generator. In Python, a generator object is always truthy, so the if not results check will fail to detect empty results. Converting the results to a list ensures the check works correctly and allows for safe iteration.

Suggested change
results = DDGS().text(query, max_results=5)
if not results:
return "No results found."
results = list(DDGS().text(query, max_results=5))
if not results:
return "No results found."

Comment on lines 43 to 44
except Exception as e:
return f"Error performing search: {e}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This try...except block catches all exceptions and returns them as a string, which is then passed to the LLM. However, it doesn't log the error, making it difficult to debug issues (like API failures or network errors) from the server logs. Since the caller web_search also has a try...except block with logging, it would be better to either log the error here or let the exception bubble up.

Suggested change
except Exception as e:
return f"Error performing search: {e}"
except Exception as e:
logging.error(f"Web search error: {e}", exc_info=True)
return f"Error performing search: {e}"

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