Skip to content

fix: prefer explicit dates in Tavily searches#9234

Open
Last-emo-boy wants to merge 1 commit into
AstrBotDevs:masterfrom
Last-emo-boy:fix/8154-tavily-date-filters
Open

fix: prefer explicit dates in Tavily searches#9234
Last-emo-boy wants to merge 1 commit into
AstrBotDevs:masterfrom
Last-emo-boy:fix/8154-tavily-date-filters

Conversation

@Last-emo-boy

@Last-emo-boy Last-emo-boy commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #8154

Modifications / 改动点

  • Prefer explicit start/end dates when a Tavily request also contains time_range.

  • Preserve the existing time_range behavior when no explicit date is provided.

  • Add regression coverage for both dates, either single date, and empty dates.

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

  • uv run pytest -q tests/unit/test_web_search_tools.py: 27 passed
  • ruff format --check .: passed
  • ruff check .: passed

Checklist / 检查清单

  • This change is covered by the linked issue.
  • My changes have been well-tested, and verification results are provided above.
  • No new dependencies are introduced.
  • My changes do not introduce malicious code.

Summary by Sourcery

Normalize Tavily web search date filters to prefer explicit start/end dates over time_range while preserving existing behavior when no valid dates are provided.

Bug Fixes:

  • Ensure Tavily searches use provided start/end dates instead of time_range when explicit non-empty dates are given.
  • Fall back to time_range when start/end date inputs are empty or whitespace-only, avoiding invalid date payloads.

Tests:

  • Add parametrized async tests covering Tavily date filter normalization for time_range-only, explicit dates, single-date, and empty/whitespace date cases.

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

Copy link
Copy Markdown
Contributor

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 updates the Tavily web search tool to prioritize start_date and end_date over time_range when constructing the search payload, and adds comprehensive unit tests for this normalization logic. The feedback recommends stripping whitespace from start_date and end_date to prevent whitespace-only strings from being incorrectly treated as truthy values, which could cause API 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 thread astrbot/core/tools/web_search_tools.py Outdated
@Last-emo-boy Last-emo-boy force-pushed the fix/8154-tavily-date-filters branch from feede96 to add2ba8 Compare July 13, 2026 06:19
@Last-emo-boy Last-emo-boy force-pushed the fix/8154-tavily-date-filters branch from add2ba8 to f15a1ba Compare July 14, 2026 02:43
@Last-emo-boy Last-emo-boy marked this pull request as ready for review July 14, 2026 02:46
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. area:core The bug / feature is about astrbot's core, backend labels Jul 14, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The allowed time_range values ("day", "week", "month", "year") are now duplicated inline in this logic; consider centralizing them as a shared constant or enum so future changes don’t require hunting through call sites.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The allowed `time_range` values (`"day"`, `"week"`, `"month"`, `"year"`) are now duplicated inline in this logic; consider centralizing them as a shared constant or enum so future changes don’t require hunting through call sites.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Last-emo-boy

Copy link
Copy Markdown
Contributor Author

Reviewed: the allowed time_range list is not duplicated by this change; the existing check was moved unchanged into the mutually exclusive branch. Keeping this single-use validation inline follows the repository Inline-First rule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] web_search_tavily conflicting time_range and date parameters always raises ERROR

1 participant