Skip to content

feat(agent): add Querit search tool - #17548

Merged
wangq8 merged 17 commits into
infiniflow:mainfrom
QueritOps:feat/querit-search-tool
Jul 30, 2026
Merged

wangq8 merged 17 commits into
infiniflow:mainfrom
QueritOps:feat/querit-search-tool

Conversation

@ethan7zhanghx

Copy link
Copy Markdown
Contributor

Summary

Add Querit as a built-in web search tool for RAGFlow Agents and Canvas workflows.

Querit provides real-time web search through the Querit Search API. This integration supports two usage modes:

  • A standalone QueritSearch node in Canvas workflows.
  • An embedded search tool available to RAGFlow Agents.

What changed

  • Added Querit support to the Python and Go agent runtimes.
  • Added Agent and Canvas configuration forms.
  • Added tool registration, icons, timeline labels, and English/Chinese UI text.
  • Preserved the complete Querit JSON response for downstream workflow usage.
  • Added reference-formatted content for prompts and retrieval-style consumers.
  • Added API key sanitization when exporting Agent or Canvas DSL, including supported Querit aliases.
  • Added validation, cancellation-aware retries, and transient error handling.
  • Added Python, Go, and frontend unit tests.

Supported parameters

Parameter Description
query Search query.
count Maximum number of results. Defaults to 10.
chunks_per_doc Summary chunks per document, from 1 to 3. Defaults to 3.
site_include Sites that results must include.
site_exclude Sites that results must exclude.
time_range Supports dN, wN, mN, yN, or YYYY-MM-DDtoYYYY-MM-DD.
country_include Countries that results must include.
language_include Languages that results must include.

Authentication

The API key can be configured on the Querit node or through the QUERIT_API_KEY environment variable. A node-level key takes precedence.

Querit API keys can be created at https://www.querit.ai/en/dashboard/api-keys.

Request behavior

  • Maps the flat RAGFlow form parameters to the Querit API filters payload.
  • Returns the original Querit JSON response without response normalization.
  • Retries transient network failures, HTTP 429, and retryable 5xx responses up to three attempts.
  • Does not retry non-transient errors such as authentication failures.
  • Stops retrying when the workflow is canceled.

Testing

  • Python Querit unit tests: 31 passed.
  • Frontend Querit unit tests: 7 suites passed, 43 tests passed.
  • Python lint and formatting checks passed.
  • Frontend formatting and lint checks passed.
  • Full upstream CI matrix pending.

Screenshots

Canvas node configuration

Querit Canvas node configuration

Canvas search result

Querit Canvas search result

Agent tool configuration

Querit Agent tool configuration

Agent search result

Querit Agent search result

ethan7zhanghx and others added 16 commits July 27, 2026 16:12
Establish the compile-safe Querit operator contract, shared defaults, minimal frontend registrations, and English/Chinese copy for parallel implementation.
Adds the standalone Querit Canvas form, validated field serialization, node rehydration, and guarded persistence for invalid or blank values.
feat(agent): add Querit Agent tool UI
* feat(agent): add Querit search tool

* fix(agent): align Querit time range contract

* fix(agent): address Querit Go review feedback

* fix(agent): align Querit Go runtime boundaries

---------

Co-authored-by: zengzhaoxin <[email protected]>
Co-authored-by: EthanZhang <[email protected]>
* fix(agent): harden Querit integration boundaries

* fix(agent): align Querit language guidance

* fix(agent): scope Querit Canvas export redaction
…upstream-ready

# Conflicts:
#	web/src/pages/agent/hooks/use-export-json.ts
@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f23903f9-cfa7-44e9-945a-11fcc8c93bff

📥 Commits

Reviewing files that changed from the base of the PR and between eb0222c and a9efbee.

📒 Files selected for processing (13)
  • internal/agent/component/tool_component_test.go
  • internal/agent/tool/querit.go
  • internal/agent/tool/querit_test.go
  • internal/agent/tool/tool2component.go
  • test/unit_test/agent/tools/test_querit_unit.py
  • web/src/pages/agent/constant/index.tsx
  • web/src/pages/agent/form/querit-form/use-watch-change.test.tsx
  • web/src/pages/agent/form/querit-form/use-watch-change.ts
  • web/src/pages/agent/form/querit-form/utils.test.ts
  • web/src/pages/agent/form/querit-form/utils.ts
  • web/src/pages/agent/hooks/use-agent-tool-initial-values.test.ts
  • web/src/pages/agent/log-sheet/tool-name.test.ts
  • web/src/pages/agent/log-sheet/tool-name.ts
🚧 Files skipped from review as they are similar to previous changes (13)
  • web/src/pages/agent/log-sheet/tool-name.test.ts
  • web/src/pages/agent/hooks/use-agent-tool-initial-values.test.ts
  • web/src/pages/agent/constant/index.tsx
  • web/src/pages/agent/form/querit-form/use-watch-change.test.tsx
  • web/src/pages/agent/form/querit-form/use-watch-change.ts
  • web/src/pages/agent/log-sheet/tool-name.ts
  • web/src/pages/agent/form/querit-form/utils.ts
  • internal/agent/tool/tool2component.go
  • web/src/pages/agent/form/querit-form/utils.test.ts
  • internal/agent/component/tool_component_test.go
  • internal/agent/tool/querit.go
  • test/unit_test/agent/tools/test_querit_unit.py
  • internal/agent/tool/querit_test.go

📝 Walkthrough

Walkthrough

Querit web search is added across Python and Go runtimes, Canvas component registration, request validation and retries, lossless JSON handling, reference extraction, registry aliases, and the web interface with forms, persistence, localization, icons, and sensitive-field removal.

Changes

Querit search implementation

Layer / File(s) Summary
Python search execution and validation
agent/tools/querit.py, test/unit_test/agent/tools/test_querit_unit.py
Adds Querit request construction, validation, retries, cancellation, error redaction, response parsing, and reference retrieval.
Go tool and registry integration
internal/agent/tool/querit.go, internal/agent/tool/registry.go, internal/common/environments.go, tools/gen-component-parity/main.go, internal/agent/tool/*_test.go
Adds the Go Querit tool, aliases, environment-key support, response/reference processing, and registry coverage.
Canvas JSON and component integration
internal/agent/component/tool_component.go, internal/agent/tool/tool2component.go, internal/agent/component/tool_component_test.go
Registers Querit and preserves JSON numeric tokens through lossless envelope parsing.
Querit forms and persistence
web/src/pages/agent/form/querit-form/*, web/src/pages/agent/form/tool-form/querit-form/*, web/src/pages/agent/constant/index.tsx
Adds validated forms, dynamic filter lists, serialization, change watchers, defaults, and graph/tool mappings.
UI display and data sanitization
web/src/pages/agent/hooks/*, web/src/pages/agent/log-sheet/*, web/src/pages/agent/operator-icon.tsx, web/src/locales/*, web/src/constants/agent.tsx
Adds Querit initialization, export sanitization, menus, icons, timeline labels, and translations.

Estimated code review effort: 5 (Critical) | ~120 minutes

Poem

A rabbit searched the web at dawn,
Querit found the facts to spawn.
Forms hopped neatly, keys hid tight,
JSON numbers stayed just right.
“Sniff!” said Bun, “the flow is bright!”

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.35% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding the Querit search tool.
Description check ✅ Passed The description includes the required Summary section and provides clear context plus useful implementation and testing details.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

@ethan7zhanghx
ethan7zhanghx marked this pull request as ready for review July 29, 2026 12:37
@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. 🌈 python Pull requests that update Python code 💞 feature Feature request, pull request that fullfill a new feature. 🧰 typescript Pull requests that update Typescript code labels Jul 29, 2026

@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: 7

🧹 Nitpick comments (6)
internal/agent/component/tool_component.go (1)

106-117: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

null payload returns a nil map rather than _raw.

json.Decoder.Decode on null succeeds and leaves out nil, so the envelope passes the _raw check and flows into BuildComponentOutputs as a nil map. Reads are safe, but the failure surfaces as an empty result instead of canvas: ...: invalid tool result. A nil check would make it explicit.

🛡️ Proposed guard
 	if err := decoder.Decode(&struct{}{}); err != io.EOF {
 		return map[string]any{"_raw": jsonStr}
 	}
+	if out == nil {
+		return map[string]any{"_raw": jsonStr}
+	}
 	return out
🤖 Prompt for 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.

In `@internal/agent/component/tool_component.go` around lines 106 - 117, Update
parseToolEnvelopeLossless to detect a nil out map after decoding, including JSON
null, and return the existing _raw fallback in that case so invalid payloads
reach BuildComponentOutputs as an invalid tool result.
internal/agent/tool/registry.go (1)

553-553: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use queritToolName instead of repeating the literal.

The constant already exists in internal/agent/tool/querit.go; using it keeps the error strings in sync if the canonical name changes.

Also applies to: 560-560, 567-567, 584-584, 589-589

🤖 Prompt for 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.

In `@internal/agent/tool/registry.go` at line 553, Replace the repeated
"querit_search" literals in the error messages within the tool parameter
validation logic with the existing queritToolName constant from querit.go,
including the noted occurrences, so all messages stay synchronized with the
canonical tool name.
agent/tools/querit.py (1)

210-212: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Consider honoring Retry-After and draining the body on retryable statuses.

For 429/503 the upstream commonly returns Retry-After; the fixed delay_after_error ignores it. Also, the response body is neither read nor closed before continue, so the connection can't be returned to the pool cleanly.

♻️ Sketch
                 if response.status_code in QUERIT_RETRYABLE_STATUS_CODES and attempt + 1 < QUERIT_MAX_ATTEMPTS:
+                    response.close()
+                    logger.warning("Querit returned %s; retrying (attempt %s).", response.status_code, attempt + 1)
                     self._wait_before_retry()
                     continue
🤖 Prompt for 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.

In `@agent/tools/querit.py` around lines 210 - 212, Update the retry branch in the
request method around QUERIT_RETRYABLE_STATUS_CODES to consume and close the
response before continuing, and use its Retry-After header when present to
determine the wait duration, falling back to the existing delay_after_error
otherwise.
internal/agent/tool/querit.go (1)

277-280: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Response is decoded twice on the Canvas path.

decodeQueritResponse fully decodes raw only for validation, then the string is re-decoded by parseToolEnvelopeLossless in internal/agent/component/tool_component.go. For large search payloads that doubles parse cost/allocations. Acceptable if you prefer keeping the raw string contract, but worth noting.

🤖 Prompt for 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.

In `@internal/agent/tool/querit.go` around lines 277 - 280, Update the Canvas
response flow around decodeQueritResponse to reuse its decoded result when
constructing the tool envelope, instead of returning raw and causing
parseToolEnvelopeLossless to decode it again. Preserve the existing
queritErrorJSON handling for decode failures and the response behavior for valid
payloads.
web/src/pages/agent/form/querit-form/dynamic-list.tsx (1)

56-68: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract the click handlers.

Lines 61 and 68 use inline JSX handlers. Move them to named handlers before passing them to the buttons.

Proposed change
+  const handleRemove = (index: number) => () => remove(index);
+  const handleAppend = () => append({ value: '' });
+
   return (
...
-              onClick={() => remove(index)}
+              onClick={handleRemove(index)}
...
-      <BlockButton type="button" onClick={() => append({ value: '' })}>
+      <BlockButton type="button" onClick={handleAppend}>

As per coding guidelines, “Avoid inline JSX event handlers such as onClick={() => ...}.”

🤖 Prompt for 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.

In `@web/src/pages/agent/form/querit-form/dynamic-list.tsx` around lines 56 - 68,
Replace the inline onClick callbacks in the remove Button and BlockButton within
the dynamic list rendering with named handler functions declared before the JSX,
preserving the existing remove(index) and append({ value: '' }) behavior. Pass
the handlers to each button, using the item index where required.

Source: Coding guidelines

web/src/pages/agent/form/querit-form/utils.ts (1)

19-21: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a message to the time_range refine for clearer form feedback.

Without a custom message, FormMessage will surface Zod's generic default error text when a user types an invalid time_range (e.g. "last week"), rather than a hint like "expected d7, w2, m1, y1, or a YYYY-MM-DDtoYYYY-MM-DD range".

♻️ Suggested fix
   time_range: z
     .string()
-    .refine((value) => value === '' || QueritTimeRangePattern.test(value)),
+    .refine((value) => value === '' || QueritTimeRangePattern.test(value), {
+      message: 'Expected d7, w2, m1, y1, or YYYY-MM-DDtoYYYY-MM-DD',
+    }),
🤖 Prompt for 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.

In `@web/src/pages/agent/form/querit-form/utils.ts` around lines 19 - 21, Update
the time_range Zod refinement to provide a custom validation message when
QueritTimeRangePattern rejects a non-empty value. Preserve the existing
allowance for an empty string and use the requested hint describing valid d7,
w2, m1, y1, or YYYY-MM-DDtoYYYY-MM-DD formats.
🤖 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 `@internal/agent/component/tool_component_test.go`:
- Around line 479-506: Replace the plain serverCalls counter in the QueritSearch
test with an atomic.Int32, increment it atomically inside the httptest handler,
and atomically load it when validating the empty-query result. Update the
assertion and failure message to use the loaded value while preserving the
expectation that no server request occurs.

In `@internal/agent/tool/querit.go`:
- Around line 214-229: Update InvokableRun so query validation occurs after
mergeQueritParams combines q.defaults, runtimeParams, and provided values,
allowing q.defaults.Query to satisfy an omitted node-level query. Reject only
when the merged query is absent, null, or not a string, while preserving the
existing empty-query response behavior.

In `@test/unit_test/agent/tools/test_querit_unit.py`:
- Line 521: Update the test secret assignment in the relevant test function to
explicitly suppress Ruff S105 for this intentional fixture value, preserving the
existing "secret-test-key" behavior.

In `@web/src/pages/agent/constant/index.tsx`:
- Around line 575-596: The json output definition in initialQueritValues uses
the wrong case for its type token. Update outputs.json.type from 'Object' to the
canonical lowercase 'object', preserving the remaining query defaults and output
structure.

In `@web/src/pages/agent/form/querit-form/use-watch-change.ts`:
- Around line 6-20: The useWatchFormChange effect currently persists normalized
values on the initial render, potentially marking unchanged forms as modified.
Add an initialization/change guard within useWatchFormChange so updateNodeForm
runs only after the watched form values have changed or become dirty, while
preserving persistence for subsequent edits.

In `@web/src/pages/agent/form/querit-form/utils.ts`:
- Around line 12-24: Update the query field in QueritFormSchema to reject empty
strings at schema validation, ensuring validateQueritFormValuesForPersistence
cannot save a node without a query. Keep the existing string validation and
other schema fields unchanged.

In `@web/src/pages/agent/log-sheet/tool-name.ts`:
- Around line 3-5: Update getToolOperatorName to handle missing, null, or empty
toolName values before calling replaceAll, preserving the existing safe fallback
returned by the formatter. Keep normalization unchanged for valid names, and add
a regression test covering an empty or missing tool_name input.

---

Nitpick comments:
In `@agent/tools/querit.py`:
- Around line 210-212: Update the retry branch in the request method around
QUERIT_RETRYABLE_STATUS_CODES to consume and close the response before
continuing, and use its Retry-After header when present to determine the wait
duration, falling back to the existing delay_after_error otherwise.

In `@internal/agent/component/tool_component.go`:
- Around line 106-117: Update parseToolEnvelopeLossless to detect a nil out map
after decoding, including JSON null, and return the existing _raw fallback in
that case so invalid payloads reach BuildComponentOutputs as an invalid tool
result.

In `@internal/agent/tool/querit.go`:
- Around line 277-280: Update the Canvas response flow around
decodeQueritResponse to reuse its decoded result when constructing the tool
envelope, instead of returning raw and causing parseToolEnvelopeLossless to
decode it again. Preserve the existing queritErrorJSON handling for decode
failures and the response behavior for valid payloads.

In `@internal/agent/tool/registry.go`:
- Line 553: Replace the repeated "querit_search" literals in the error messages
within the tool parameter validation logic with the existing queritToolName
constant from querit.go, including the noted occurrences, so all messages stay
synchronized with the canonical tool name.

In `@web/src/pages/agent/form/querit-form/dynamic-list.tsx`:
- Around line 56-68: Replace the inline onClick callbacks in the remove Button
and BlockButton within the dynamic list rendering with named handler functions
declared before the JSX, preserving the existing remove(index) and append({
value: '' }) behavior. Pass the handlers to each button, using the item index
where required.

In `@web/src/pages/agent/form/querit-form/utils.ts`:
- Around line 19-21: Update the time_range Zod refinement to provide a custom
validation message when QueritTimeRangePattern rejects a non-empty value.
Preserve the existing allowance for an empty string and use the requested hint
describing valid d7, w2, m1, y1, or YYYY-MM-DDtoYYYY-MM-DD formats.
🪄 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 Plus

Run ID: 180ffe39-a642-4ae3-b444-e3a345a44682

📥 Commits

Reviewing files that changed from the base of the PR and between a586998 and eb0222c.

⛔ Files ignored due to path filters (1)
  • web/src/assets/querit.png is excluded by !**/*.png
📒 Files selected for processing (44)
  • agent/tools/querit.py
  • internal/agent/component/tool_component.go
  • internal/agent/component/tool_component_test.go
  • internal/agent/tool/querit.go
  • internal/agent/tool/querit_test.go
  • internal/agent/tool/registry.go
  • internal/agent/tool/registry_test.go
  • internal/agent/tool/tool2component.go
  • internal/common/environments.go
  • test/unit_test/agent/tools/test_querit_unit.py
  • tools/gen-component-parity/main.go
  • web/src/constants/agent.tsx
  • web/src/locales/en.ts
  • web/src/locales/zh.ts
  • web/src/pages/agent/canvas/node/dropdown/accordion-operators.tsx
  • web/src/pages/agent/constant/index.tsx
  • web/src/pages/agent/form-sheet/form-config-map.tsx
  • web/src/pages/agent/form/agent-form/tool-popover/tool-command.tsx
  • web/src/pages/agent/form/querit-form/dynamic-list.tsx
  • web/src/pages/agent/form/querit-form/index.tsx
  • web/src/pages/agent/form/querit-form/use-values.ts
  • web/src/pages/agent/form/querit-form/use-watch-change.test.tsx
  • web/src/pages/agent/form/querit-form/use-watch-change.ts
  • web/src/pages/agent/form/querit-form/utils.test.ts
  • web/src/pages/agent/form/querit-form/utils.ts
  • web/src/pages/agent/form/tool-form/constant.tsx
  • web/src/pages/agent/form/tool-form/querit-form/index.tsx
  • web/src/pages/agent/form/tool-form/querit-form/use-watch-change.test.tsx
  • web/src/pages/agent/form/tool-form/querit-form/use-watch-change.ts
  • web/src/pages/agent/form/tool-form/querit-form/utils.test.ts
  • web/src/pages/agent/form/tool-form/querit-form/utils.ts
  • web/src/pages/agent/hooks/clear-sensitive-fields.ts
  • web/src/pages/agent/hooks/querit-agent-initial-values.ts
  • web/src/pages/agent/hooks/use-add-node.ts
  • web/src/pages/agent/hooks/use-agent-tool-initial-values.test.ts
  • web/src/pages/agent/hooks/use-agent-tool-initial-values.ts
  • web/src/pages/agent/hooks/use-export-json.test.ts
  • web/src/pages/agent/hooks/use-export-json.ts
  • web/src/pages/agent/log-sheet/tool-name.test.ts
  • web/src/pages/agent/log-sheet/tool-name.ts
  • web/src/pages/agent/log-sheet/tool-timeline-item.tsx
  • web/src/pages/agent/log-sheet/workflow-timeline.tsx
  • web/src/pages/agent/operator-icon.tsx
  • web/src/pages/agent/webhook-sheet/timeline.tsx

Comment thread internal/agent/tool/querit.go Resolved
Comment thread web/src/pages/agent/constant/index.tsx Resolved
@yingfeng yingfeng added the ci Continue Integration label Jul 29, 2026
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.65%. Comparing base (a586998) to head (a9efbee).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #17548   +/-   ##
=======================================
  Coverage   90.65%   90.65%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          650      650           
  Misses         39       39           
  Partials       28       28           

☔ 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.

@wangq8
wangq8 merged commit 33e581a into infiniflow:main Jul 30, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. 🌈 python Pull requests that update Python code size:XXL This PR changes 1000+ lines, ignoring generated files. 🧰 typescript Pull requests that update Typescript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants