Skip to content

fix(agent): filter TuShare news with upstream keyword input - #16361

Merged
yuzhichang merged 7 commits into
infiniflow:mainfrom
Harsh23Kashyap:Harsh23Kashyap/fix/tushare-keyword-input
Jul 1, 2026
Merged

yuzhichang merged 7 commits into
infiniflow:mainfrom
Harsh23Kashyap:Harsh23Kashyap/fix/tushare-keyword-input

Conversation

@Harsh23Kashyap

Copy link
Copy Markdown
Collaborator

Summary

TuShare required non-empty upstream input but filtered fetched news with the static keyword param (default empty string), so agent-provided keywords were ignored.

Use self._param.keyword or ans when filtering, matching how AkShare uses upstream input for its query.

Fixes #16360

Test plan

  • test_tushare_filters_with_upstream_keyword_when_param_empty mocks the API and asserts only rows matching the upstream keyword are returned

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. 🧪 test Pull requests that update test cases. labels Jun 25, 2026
@coderabbitai

coderabbitai Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

TuShare filtering now chooses the match keyword from the configured parameter or upstream input, logs which source was used, and filters content with explicit missing-value and regex handling. Tests cover both keyword selection paths.

Changes

TuShare keyword filtering

Layer / File(s) Summary
Keyword fallback in filtering
agent/tools/tushare.py
The news content filter selects the configured keyword when present, otherwise the upstream input keyword, logs the source, and applies case-insensitive filtering with missing values excluded and regex disabled.
Keyword source unit tests
test/unit_test/agent/tools/test_tushare.py
Adds a TuShare test harness plus two cases that verify upstream input is used when the parameter is empty and the configured keyword takes precedence when set.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I hopped through the feed with a nose so keen,
Upstream or param—both paths are seen.
When Google or Apple come hopping by,
The right one now filters beneath the sky.
Hop hop, little keywords, behave for me!

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description lacks the required template headings and the Type of change section. Rewrite it to match the template with a problem summary and a filled Type of change choice.
Linked Issues check ⚠️ Warning The PR uses self._param.keyword before upstream input, which reverses the linked issue's expected precedence. Change the filter to prefer upstream keyword input first, then fall back to the configured param when needed.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main TuShare keyword-filtering fix.
Out of Scope Changes check ✅ Passed The logging tweak and test additions are directly related to the TuShare keyword-filtering fix.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Harsh23Kashyap

Copy link
Copy Markdown
Collaborator Author

Could a maintainer add the ci label when convenient? Thanks.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@agent/tools/tushare.py`:
- Around line 75-76: The new keyword fallback in the Tushare tool currently
switches between self._param.keyword and ans without any observability; update
the logic in the method that builds tus_res to emit a log entry indicating
whether the keyword came from the explicit parameter or the upstream answer,
while avoiding logging the raw keyword value. Use the existing logger in
agent/tools/tushare.py so the new flow is traceable without exposing sensitive
content.
- Around line 75-76: The filtering in TushareTool around keyword handling uses
pandas str.contains with a user-supplied value, so update the content-matching
expression in the append logic to treat the keyword as a literal string by
setting regex=False. Keep the change localized to the
df[df['content'].str.contains(...)] call so keywords with special characters do
not trigger regex behavior or runtime errors.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 911abe7e-d5f5-4a4b-86ce-a186713e322f

📥 Commits

Reviewing files that changed from the base of the PR and between 0af5d43 and beb9c5b.

📒 Files selected for processing (2)
  • agent/tools/tushare.py
  • test/unit_test/agent/tools/test_tushare.py

Comment thread agent/tools/tushare.py Resolved
@yingfeng
yingfeng requested a review from yuzhichang June 25, 2026 13:07
@yingfeng yingfeng added the ci Continue Integration label Jun 25, 2026
@yingfeng
yingfeng marked this pull request as draft June 25, 2026 13:08
@yingfeng
yingfeng marked this pull request as ready for review June 25, 2026 13:08
@codecov

codecov Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (828c578) to head (acb1db2).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16361   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Harsh23Kashyap

Harsh23Kashyap commented Jun 26, 2026 •

Copy link
Copy Markdown
Collaborator Author

Addressed the CodeRabbit logging feedback in 8ec7c1f. The TuShare tool now logs whether the filter keyword came from param.keyword or upstream input, without logging the keyword value itself.

Verification:

  • python3 -m py_compile agent/tools/tushare.py
  • uvx ruff check agent/tools/tushare.py

@yuzhichang yuzhichang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Re-reviewed the current head. The behavior change itself looks good: the filter now handles empty keywords safely and adds observability for whether the effective keyword came from explicit config or upstream input. I did not find any remaining correctness issue in the current diff.

One thing to double-check with maintainers is product intent: the implementation still prefers param.keyword when present and only falls back to upstream input when it is empty. If that precedence matches the intended UX for #16360, I'm happy with this PR as-is.

@Harsh23Kashyap

Copy link
Copy Markdown
Collaborator Author

Quick CI note after syncing this branch with latest main today.

On run https://github.com/infiniflow/ragflow/actions/runs/28306891563 (before the sync), preflight, elasticsearch, and infinity all passed on commit 7bfa16b.

After updating the branch, the new preflight run https://github.com/infiniflow/ragflow/actions/runs/28311062428 failed during test collection with the same external tiktoken download error:

SSLError: UNEXPECTED_EOF_WHILE_READING while fetching cl100k_base.tiktoken from openaipublic.blob.core.windows.net

The failure is in test_browser_use_component.py collection, not in the TuShare changes. CodeRabbit is still green and the branch is current with main (behind_by: 0).

Could a maintainer rerun preflight when the tiktoken download is stable? The precedence-test fix for #16360 is in 7bfa16b and had full green CI on the prior run.

@yuzhichang
yuzhichang force-pushed the main branch 2 times, most recently from 78db4e9 to f86a0e7 Compare June 29, 2026 01:47
@yuzhichang
yuzhichang force-pushed the Harsh23Kashyap/fix/tushare-keyword-input branch from d868d03 to dc964bd Compare June 29, 2026 05:01
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Jun 29, 2026
@Harsh23Kashyap

Copy link
Copy Markdown
Collaborator Author

Synced with latest main. Could a maintainer add the ci label so workflows can run? Okay, please review it.

@Harsh23Kashyap
Harsh23Kashyap force-pushed the Harsh23Kashyap/fix/tushare-keyword-input branch from e23e9e1 to 47e87f3 Compare June 30, 2026 04:48
@Harsh23Kashyap
Harsh23Kashyap force-pushed the Harsh23Kashyap/fix/tushare-keyword-input branch from 0b2da21 to 8164f71 Compare June 30, 2026 13:43
@Harsh23Kashyap

Copy link
Copy Markdown
Collaborator Author

Follow-up: branch is current with main (behind_by: 0). CodeRabbit passed; no unresolved review threads. Last CI run had elasticsearch fail (infra/docker setup); preflight and infinity passed. Fork workflows may need the ci label on reruns. Ready for review when you have a chance.

@yuzhichang
yuzhichang merged commit 508f622 into infiniflow:main Jul 1, 2026
2 of 3 checks passed
@Harsh23Kashyap
Harsh23Kashyap deleted the Harsh23Kashyap/fix/tushare-keyword-input branch July 1, 2026 15:06
yuzhichang pushed a commit that referenced this pull request Jul 2, 2026
### Summary

Port the following PRs to GO in this PR

#14210
#14641
#15220
#15228
#15384
#15754
#16413
#16483
#16419
#16361   
#16050
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:S This PR changes 10-29 lines, ignoring generated files. 🧪 test Pull requests that update test cases.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: TuShare component ignores upstream keyword input when filtering news

3 participants