Skip to content

feat: add Tavily Extract as configurable WebFetch backend alongside Jina#5

Open
manisrinivasan2k1 wants to merge 1 commit into
InternScience:mainfrom
Tavily-FDE:feat/tavily-migration/webfetch-jina-additive
Open

feat: add Tavily Extract as configurable WebFetch backend alongside Jina#5
manisrinivasan2k1 wants to merge 1 commit into
InternScience:mainfrom
Tavily-FDE:feat/tavily-migration/webfetch-jina-additive

Conversation

@manisrinivasan2k1

Copy link
Copy Markdown

Summary

Adds Tavily Extract as a selectable parallel backend for the WebFetch tool, alongside the existing Jina provider. A new WEBFETCH_PROVIDER environment variable (jina | tavily, default jina) controls which backend is invoked at runtime.

What changed

  • agent_base/tools/tool_web.py: Added readpage_tavily() method to WebFetch that uses TavilyClient.extract(urls=[url]) for content extraction. Modified call() to dispatch based on WEBFETCH_PROVIDER env var. Existing Jina paths (jina_readpage, html_readpage_jina, readpage_jina) are untouched.
  • .env.example: Documented WEBFETCH_PROVIDER and TAVILY_API_KEY as optional env vars.
  • requirements.txt: Added tavily-python>=0.5.0.

Files changed

  • agent_base/tools/tool_web.py
  • .env.example
  • requirements.txt

Dependency changes

  • Added tavily-python>=0.5.0 to requirements.txt

Environment variable changes

  • Added WEBFETCH_PROVIDER (optional, default: jina; values: jina | tavily)
  • Added TAVILY_API_KEY reference in .env.example (required when WEBFETCH_PROVIDER=tavily)
  • Existing JINA_KEY unchanged

Notes for reviewers

  • This is an additive change — Jina remains the default and all existing code paths are preserved.
  • The Tavily extract() response's raw_content field is passed through the existing _format_page_content() for consistent line-range and max_chars formatting.
  • The TAVILY_API_KEY guard mirrors the existing JINA_KEY guard pattern.

Automated Review

  • Passed after 1 attempt(s)
  • Final review: The implementation correctly adds Tavily Extract as a parallel WebFetch backend. The Tavily SDK usage (TavilyClient.extract(urls=[url]) with raw_content extraction) is correct, error handling is consistent with the existing codebase, and the Jina path is fully preserved. Two minor issues exist: (1) tavily-python>=0.5.0 is added to requirements.txt in this diff, but it was already added by the prerequisite unit (web-search-serper-additive), creating a potential duplicate on merge. (2) TAVILY_API_KEY is added to .env.example here, despite the migration plan noting "TAVILY_API_KEY shared with web-search unit; no duplicate addition needed" — same duplicate risk. Neither issue blocks correctness, and neither was added to the sensitive env masking list (appropriately deferred to the prerequisite unit).

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

Copy link
Copy Markdown

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 WebFetch provider alongside Jina, adding configuration options, updating dependencies, and implementing the readpage_tavily method. Feedback on these changes suggests ensuring consistency with the Jina backend by passing and respecting the runtime_deadline parameter in readpage_tavily to enforce the agent's runtime budget. Additionally, it is recommended to add a type check to verify that the first element of the Tavily API results is a dictionary before accessing its keys, preventing potential runtime errors.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +360 to +365
response = self.readpage_tavily(
url,
start_line=start_line,
end_line=end_line,
max_chars=max_chars,
)

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

Pass the runtime_deadline parameter to readpage_tavily to ensure consistency with the Jina backend and respect the agent's runtime budget.

Suggested change
response = self.readpage_tavily(
url,
start_line=start_line,
end_line=end_line,
max_chars=max_chars,
)
response = self.readpage_tavily(
url,
start_line=start_line,
end_line=end_line,
max_chars=max_chars,
runtime_deadline=runtime_deadline,
)

Comment on lines +447 to +455
def readpage_tavily(
self,
url: str,
*,
start_line: int = 1,
end_line: Optional[int] = None,
max_chars: int = DEFAULT_WEBFETCH_MAX_CHARS,
) -> str:
tavily_api_key = os.getenv("TAVILY_API_KEY", "").strip()

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

Add the runtime_deadline parameter to readpage_tavily and check the remaining budget before proceeding with the Tavily API call. This ensures the tool respects the agent's runtime limit, matching the behavior of the Jina backend.

    def readpage_tavily(
        self,
        url: str,
        *,
        start_line: int = 1,
        end_line: Optional[int] = None,
        max_chars: int = DEFAULT_WEBFETCH_MAX_CHARS,
        runtime_deadline: Optional[float] = None,
    ) -> str:
        remaining = self._remaining_budget_seconds(runtime_deadline)
        if remaining is not None and remaining <= 0:
            return "[WebFetch] Failed to read page: agent runtime limit reached."
        tavily_api_key = os.getenv("TAVILY_API_KEY", "").strip()

Comment on lines +464 to +466
results = result.get("results", [])
if not results or not results[0].get("raw_content"):
return "[WebFetch] Failed to read page: the provided webpage content could not be accessed. Please check the URL or file format."

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

Add a check to ensure results[0] is a dictionary before calling .get() on it. If the API returns an unexpected structure or None in the results list, this prevents a potential AttributeError.

Suggested change
results = result.get("results", [])
if not results or not results[0].get("raw_content"):
return "[WebFetch] Failed to read page: the provided webpage content could not be accessed. Please check the URL or file format."
results = result.get("results", [])
if not results or not isinstance(results[0], dict) or not results[0].get("raw_content"):
return "[WebFetch] Failed to read page: the provided webpage content could not be accessed. Please check the URL or file format."

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