Skip to content

feat: add Tavily as parallel search provider option in backend#208

Open
tavily-integrations wants to merge 1 commit intogoogle-gemini:mainfrom
Tavily-FDE:feat/tavily-migration/backend-google-search
Open

feat: add Tavily as parallel search provider option in backend#208
tavily-integrations wants to merge 1 commit intogoogle-gemini:mainfrom
Tavily-FDE:feat/tavily-migration/backend-google-search

Conversation

@tavily-integrations
Copy link
Copy Markdown

Summary

  • Added tavily-python dependency to backend/pyproject.toml
  • Added TAVILY_API_KEY to backend/.env.example (optional, only needed when search_provider=tavily)
  • Added search_provider field (default 'google') to Configuration model in configuration.py
  • Branched web_research node in graph.py: existing Google grounding path preserved as default, new Tavily path added that maps Tavily results into the same sources_gathered / web_research_result state shape

Files changed

  • backend/pyproject.toml — added tavily-python dependency
  • backend/.env.example — documented TAVILY_API_KEY env var
  • backend/src/agent/configuration.py — added search_provider config field
  • backend/src/agent/graph.py — imported TavilyClient, refactored web_research into provider-specific helpers

Dependency changes

  • Added tavily-python to backend/pyproject.toml dependencies

Environment variable changes

  • Added TAVILY_API_KEY to backend/.env.example (required only when search_provider=tavily)

Notes for reviewers

  • The Google Search path is completely unchanged and remains the default
  • Tavily branch uses search_depth="advanced" and max_results=5 for high-quality results
  • Tavily results are mapped to the same {label, short_url, value} source schema used by the Google path
  • short_url placeholders for Tavily use https://tavily.com/id/ prefix to stay consistent with the URL replacement logic in finalize_answer

🤖 Generated with Claude Code

Automated Review

  • Passed after 1 attempt(s)
  • Final review: The Tavily migration is additive and correct. All four reported files are changed appropriately: the dependency is added to pyproject.toml, the API key is documented in .env.example, a search_provider config field is added with a safe default of 'google', and the web_research node dispatches to a new _web_research_tavily helper that maps Tavily results into the existing sources_gathered/web_research_result state shape. All existing Google Search logic is fully preserved and no regressions were found. A few minor issues exist but none block approval.

@google-cla
Copy link
Copy Markdown

google-cla bot commented Mar 30, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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 integrates Tavily as an alternative search provider for web research, adding the necessary environment variables, dependencies, and configuration options. The core logic in the agent's graph has been refactored to support multiple search providers. Feedback focuses on improving the flexibility and performance of the Tavily integration by making search parameters configurable and caching the client instance.

Comment on lines +32 to +37
search_provider: str = Field(
default="google",
metadata={
"description": "The search provider to use for web research. Options: 'google' (default) or 'tavily'."
},
)
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

To make the Tavily integration more flexible, consider making max_results and search_depth configurable instead of hardcoding them in graph.py. This allows adjusting the search behavior without changing the code.

Suggested change
search_provider: str = Field(
default="google",
metadata={
"description": "The search provider to use for web research. Options: 'google' (default) or 'tavily'."
},
)
search_provider: str = Field(
default="google",
metadata={
"description": "The search provider to use for web research. Options: 'google' (default) or 'tavily'."
},
)
tavily_max_results: int = Field(
default=5,
metadata={"description": "The maximum number of results to return from Tavily search."},
)
tavily_search_depth: str = Field(
default="advanced",
metadata={"description": "The depth of search for Tavily. Options: 'basic' or 'advanced'."},
)

Comment on lines +151 to +156
tavily_client = TavilyClient()
response = tavily_client.search(
query=state["search_query"],
max_results=5,
search_depth="advanced",
)
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

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

  1. Client Caching: To improve performance, the TavilyClient should be instantiated only once. Creating a new client on every call is inefficient, especially since this function can be called multiple times. You can cache the client instance, for example, as a function attribute.
  2. Configurability: The max_results and search_depth are hardcoded. It would be more flexible to make these configurable via the Configuration model, similar to other settings.

This suggestion addresses both points and assumes you add tavily_max_results and tavily_search_depth to configuration.py.

Suggested change
tavily_client = TavilyClient()
response = tavily_client.search(
query=state["search_query"],
max_results=5,
search_depth="advanced",
)
if not hasattr(_web_research_tavily, "client"):
_web_research_tavily.client = TavilyClient()
response = _web_research_tavily.client.search(
query=state["search_query"],
max_results=configurable.tavily_max_results,
search_depth=configurable.tavily_search_depth,
)

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