Skip to content

fix(ao-agent): add Tavily input_form, wire real search component, and port TavilyExtract to Go - #16693

Merged
yuzhichang merged 7 commits into
infiniflow:mainfrom
Harry-Hz-Zhang:fix/agent-tavily-search-extract
Jul 9, 2026
Merged

yuzhichang merged 7 commits into
infiniflow:mainfrom
Harry-Hz-Zhang:fix/agent-tavily-search-extract

Conversation

@Harry-Hz-Zhang

@Harry-Hz-Zhang Harry-Hz-Zhang commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • TavilySearch now stores api_key from component params and injects it into tool calls when runtime inputs omit it.
  • TavilyExtract and BGPT now follow the same stored api_key behavior.
  • Canvas decoding now recovers api_key from graph.nodes[].data.form when components[].obj.params.api_key is empty, matching frontend payload behavior without changing frontend data.
  • Added regression tests for graph form key recovery and stored key injection / caller key precedence.

Tests: build.sh --test ./internal/agent/component ./internal/service — all pass.

image image

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. 💞 feature Feature request, pull request that fullfill a new feature. 🧪 test Pull requests that update test cases. labels Jul 7, 2026
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as draft July 7, 2026 07:26
@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds Tavily Extract support, expands Tavily Search and BGPT component handling, merges canvas form data into component params, updates registry wiring, and rewrites the proxy DNS pinning test to use a local httptest proxy server.

Changes

Tavily Extract feature and Search enhancements

Layer / File(s) Summary
Tavily tool models and constructors
internal/agent/tool/tavily.go
Extends Tavily search request/result shapes, adds Tavily Extract request and envelope types, introduces the extract endpoint, and adds extract tool constructors.
Tavily tool invocation and metadata
internal/agent/tool/tavily.go
Extends Tavily Search Info and request body fields, implements Tavily Extract invocation and envelope helpers, and adds URL normalization and defaulting helpers.
Tavily Extract tool tests
internal/agent/tool/tavily_test.go
Adds tests for extract request construction, response parsing, API key validation, and tool metadata.
Canvas form merging and component wrappers
internal/agent/canvas/decode.go, internal/agent/component/universe_a_wrappers.go, internal/agent/component/tavily_component_test.go, internal/agent/component/bgpt_component_test.go, internal/service/canvas_decode_test.go
Decodes graph node form data into component params, updates Tavily Search and BGPT wrappers to use build-time API keys, adds Tavily Extract wrapper behavior, and renders Tavily Search results text.
Component registration and fixture wiring
internal/agent/component/fixture_stubs.go, internal/agent/component/verify_p1_test.go
Updates Tavily fixture stubs, registers production Tavily components, and widens the component registration count check.
Tool registry wiring and tests
internal/agent/tool/registry.go, internal/agent/tool/registry_test.go
Registers tavily_extract and updates registry count expectations.

Proxy DNS pinning test rewrite

Layer / File(s) Summary
Local proxy server-based DNS pin test
internal/agent/component/invoke_test.go
Rewrites TestInvoke_ProxyDNSPin to use a local httptest proxy server, stubbed DNS lookup, and proxy-hit assertions.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

Suggested labels: 🐞 bug, 💞 feature, ci, size:XL

Suggested reviewers: yingfeng, yuzhichang, JinHai-CN

Poem

A rabbit found a Tavily trail,
With extract hops and search that sail.
Form fields bloomed from canvas clay,
And proxy pins held firm today.
🥕 A tidy burrow, bright and new,
With JSON clover peeking through.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title accurately summarizes the main Tavily search/input form and TavilyExtract changes in this PR.
Description check ✅ Passed The description includes the required Summary section and clearly explains the PR purpose and testing context.

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.

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

🧹 Nitpick comments (2)
internal/agent/component/universe_a_wrappers.go (1)

97-106: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate error-handling shape between tavilySearchComponent.Invoke and tavilyExtractComponent.Invoke.

Both methods repeat the same "unmarshal envelope → if err, check _ERROR else wrap error" logic. Consider extracting a shared helper to avoid the two paths drifting as more Tavily (or other tool) wrappers are added.

♻️ Suggested helper
+// toolInvokeOutputs standardizes the "call tool, decode envelope, surface
+// _ERROR or wrap the invocation error" pattern shared by Tavily wrappers.
+func toolInvokeOutputs(err error, decoded map[string]any, errOutputs map[string]any, wrapMsg string) (map[string]any, error) {
+	if err == nil {
+		return nil, nil
+	}
+	if len(decoded) > 0 {
+		errOutputs["_ERROR"] = decoded["_ERROR"]
+		return errOutputs, nil
+	}
+	return nil, fmt.Errorf("%s: %w", wrapMsg, err)
+}

Also applies to: 157-161

🤖 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/universe_a_wrappers.go` around lines 97 - 106, The
error-handling flow in tavilySearchComponent.Invoke and
tavilyExtractComponent.Invoke is duplicated and should be centralized. Extract
the shared “unmarshal envelope, inspect decoded/_ERROR on failure, otherwise
wrap the error” logic into a helper used by both Invoke methods, and keep the
current return shape identical so future Tavily wrapper additions reuse the same
path.
internal/agent/component/fixture_stubs.go (1)

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

Drop the exported TavilySearchStub.GetInputForm or add a direct stub test

internal/agent/component/tavily_component_test.go covers the production tavilySearchComponent, but nothing in the repo calls TavilySearchStub.GetInputForm. If the stub only exists as a fallback fixture, keep this helper unexported or add a parity test that instantiates NewTavilySearchStub directly.

🤖 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/fixture_stubs.go` around lines 161 - 168, The
exported TavilySearchStub.GetInputForm helper is unused, so either remove the
export and keep the fixture helper internal, or add a direct parity test that
instantiates NewTavilySearchStub and asserts its input form. Update the fixture
in fixture_stubs.go accordingly, and if you keep the method, make sure there is
a test in tavily_component_test.go or a new stub test that exercises
GetInputForm directly so the exported API is actually covered.

Source: Coding guidelines

🤖 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/tool/tavily.go`:
- Around line 305-315: The Tavily request builder in tavilyParams is ignoring
user input by hardcoding IncludeRawContent and IncludeImages to false, and it
still forwards IncludeImageDescriptions even though images are disabled. Update
the request construction in the Tavily tool path so these flags either pass
through the corresponding fields from tavilyParams or remove the unused fields
entirely from the input contract, keeping the behavior consistent in the
function that maps tavilyParams into the API request.

---

Nitpick comments:
In `@internal/agent/component/fixture_stubs.go`:
- Around line 161-168: The exported TavilySearchStub.GetInputForm helper is
unused, so either remove the export and keep the fixture helper internal, or add
a direct parity test that instantiates NewTavilySearchStub and asserts its input
form. Update the fixture in fixture_stubs.go accordingly, and if you keep the
method, make sure there is a test in tavily_component_test.go or a new stub test
that exercises GetInputForm directly so the exported API is actually covered.

In `@internal/agent/component/universe_a_wrappers.go`:
- Around line 97-106: The error-handling flow in tavilySearchComponent.Invoke
and tavilyExtractComponent.Invoke is duplicated and should be centralized.
Extract the shared “unmarshal envelope, inspect decoded/_ERROR on failure,
otherwise wrap the error” logic into a helper used by both Invoke methods, and
keep the current return shape identical so future Tavily wrapper additions reuse
the same path.
🪄 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: 417bfc59-582b-4b49-ba20-55bfa9984135

📥 Commits

Reviewing files that changed from the base of the PR and between 9eba452 and 7c8cfde.

📒 Files selected for processing (9)
  • internal/agent/component/fixture_stubs.go
  • internal/agent/component/invoke_test.go
  • internal/agent/component/tavily_component_test.go
  • internal/agent/component/universe_a_wrappers.go
  • internal/agent/component/verify_p1_test.go
  • internal/agent/tool/registry.go
  • internal/agent/tool/registry_test.go
  • internal/agent/tool/tavily.go
  • internal/agent/tool/tavily_test.go

Comment on lines +305 to +315
Query: p.Query,
MaxResults: p.MaxResults,
SearchDepth: p.SearchDepth,
Topic: defaultString(p.Topic, "general"),
Days: p.Days,
IncludeAnswer: p.IncludeAnswer,
IncludeRawContent: false,
IncludeImages: false,
IncludeImageDescriptions: p.IncludeImageDescriptions,
IncludeDomains: p.IncludeDomains,
ExcludeDomains: p.ExcludeDomains,

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

file="internal/agent/tool/tavily.go"

echo "== file outline =="
ast-grep outline "$file" --view expanded || true

echo
echo "== relevant lines around search body =="
sed -n '280,330p' "$file" | cat -n

echo
echo "== tavilyParams definition and uses =="
rg -n "type tavilyParams|IncludeRawContent|IncludeImages|IncludeImageDescriptions|tavilyParams" "$file"

Repository: infiniflow/ragflow

Length of output: 7801


Honor the Tavily image/raw-content flags

IncludeRawContent and IncludeImages are accepted in tavilyParams but always sent as false, so those inputs are ignored. IncludeImageDescriptions is still forwarded even though images are disabled here, so that knob cannot have any effect.

Either pass through the user-supplied booleans or remove the unused fields from the input contract.

🤖 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/tavily.go` around lines 305 - 315, The Tavily request
builder in tavilyParams is ignoring user input by hardcoding IncludeRawContent
and IncludeImages to false, and it still forwards IncludeImageDescriptions even
though images are disabled. Update the request construction in the Tavily tool
path so these flags either pass through the corresponding fields from
tavilyParams or remove the unused fields entirely from the input contract,
keeping the behavior consistent in the function that maps tavilyParams into the
API request.

@Harry-Hz-Zhang Harry-Hz-Zhang added 🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration and removed 🧪 test Pull requests that update test cases. labels Jul 8, 2026
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as ready for review July 8, 2026 05:23
@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jul 8, 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.

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

90-102: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add injection and non-override tests for TavilyExtract.

TestTavilyExtract_StoresAPIKey only verifies key storage. TavilySearch and BGPT both have injection and non-override tests, but TavilyExtract has neither. The injection in tavilyExtractComponent.Invoke occurs before InvokableRun, so you can verify inputs["api_key"] after Invoke even when the call errors (e.g., missing URLs).

🧪 Suggested additional tests
 func TestTavilyExtract_StoresAPIKey(t *testing.T) {
 	c, err := New("TavilyExtract", map[string]any{"api_key": "tvly-extract"})
 	if err != nil {
 		t.Fatalf("New(TavilyExtract): %v", err)
 	}
 	tc, ok := c.(*tavilyExtractComponent)
 	if !ok {
 		t.Fatalf("New(TavilyExtract) returned %T, want *tavilyExtractComponent", c)
 	}
 	if tc.apiKey != "tvly-extract" {
 		t.Fatalf("stored apiKey = %q, want tvly-extract", tc.apiKey)
 	}
 }
+
+func TestTavilyExtract_InjectsStoredAPIKeyWhenInputOmitsIt(t *testing.T) {
+	c, err := New("TavilyExtract", map[string]any{"api_key": "tvly-extract"})
+	if err != nil {
+		t.Fatalf("New(TavilyExtract): %v", err)
+	}
+	tc := c.(*tavilyExtractComponent)
+
+	inputs := map[string]any{}
+	_, _ = tc.Invoke(context.Background(), inputs) // expected to error (no URLs)
+	if got := inputs["api_key"]; got != "tvly-extract" {
+		t.Fatalf("injected api_key = %v, want tvly-extract", got)
+	}
+}
+
+func TestTavilyExtract_DoesNotOverrideCallerAPIKey(t *testing.T) {
+	c, err := New("TavilyExtract", map[string]any{"api_key": "tvly-extract"})
+	if err != nil {
+		t.Fatalf("New(TavilyExtract): %v", err)
+	}
+	tc := c.(*tavilyExtractComponent)
+
+	inputs := map[string]any{"api_key": "tvly-call"}
+	_, _ = tc.Invoke(context.Background(), inputs) // expected to error (no URLs)
+	if got := inputs["api_key"]; got != "tvly-call" {
+		t.Fatalf("api_key = %v, want caller key", got)
+	}
+}
🤖 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/tavily_component_test.go` around lines 90 - 102,
`TestTavilyExtract_StoresAPIKey` only checks that New stores the API key; add
tests for tavilyExtractComponent.Invoke to cover injection and non-override
behavior like TavilySearch and BGPT. Use Invoke on a tavilyExtractComponent with
an apiKey and inspect inputs["api_key"] after the call, even when Invoke returns
an error from missing URLs, and verify that a preexisting api_key input is not
overwritten.
🤖 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.

Nitpick comments:
In `@internal/agent/component/tavily_component_test.go`:
- Around line 90-102: `TestTavilyExtract_StoresAPIKey` only checks that New
stores the API key; add tests for tavilyExtractComponent.Invoke to cover
injection and non-override behavior like TavilySearch and BGPT. Use Invoke on a
tavilyExtractComponent with an apiKey and inspect inputs["api_key"] after the
call, even when Invoke returns an error from missing URLs, and verify that a
preexisting api_key input is not overwritten.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cbb2365e-7569-43cf-be15-17a9901bba82

📥 Commits

Reviewing files that changed from the base of the PR and between 240b8ee and 1c27cbf.

📒 Files selected for processing (5)
  • internal/agent/canvas/decode.go
  • internal/agent/component/bgpt_component_test.go
  • internal/agent/component/tavily_component_test.go
  • internal/agent/component/universe_a_wrappers.go
  • internal/service/canvas_decode_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/agent/component/universe_a_wrappers.go

@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as draft July 8, 2026 07:24
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as ready for review July 8, 2026 07:24
@Harry-Hz-Zhang Harry-Hz-Zhang changed the title fix(agent): add Tavily input_form, wire real search component, and port TavilyExtract to Go fix(ao-agent): add Tavily input_form, wire real search component, and port TavilyExtract to Go Jul 8, 2026
Comment thread internal/agent/canvas/decode.go Resolved
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Jul 8, 2026
@yuzhichang yuzhichang added ci Continue Integration and removed ci Continue Integration labels Jul 8, 2026
@Harry-Hz-Zhang
Harry-Hz-Zhang requested a review from yuzhichang July 9, 2026 03:53
@yuzhichang
yuzhichang merged commit b29a4a6 into infiniflow:main Jul 9, 2026
3 checks passed
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 💞 feature Feature request, pull request that fullfill a new feature. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants