Repository navigation
fix(ao-agent): add Tavily input_form, wire real search component, and port TavilyExtract to Go - #16693
Conversation
📝 WalkthroughWalkthroughAdds 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. ChangesTavily Extract feature and Search enhancements
Proxy DNS pinning test rewrite
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
internal/agent/component/universe_a_wrappers.go (1)
97-106: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicate error-handling shape between
tavilySearchComponent.InvokeandtavilyExtractComponent.Invoke.Both methods repeat the same "unmarshal envelope → if err, check
_ERRORelse 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 valueDrop the exported
TavilySearchStub.GetInputFormor add a direct stub test
internal/agent/component/tavily_component_test.gocovers the productiontavilySearchComponent, but nothing in the repo callsTavilySearchStub.GetInputForm. If the stub only exists as a fallback fixture, keep this helper unexported or add a parity test that instantiatesNewTavilySearchStubdirectly.🤖 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
📒 Files selected for processing (9)
internal/agent/component/fixture_stubs.gointernal/agent/component/invoke_test.gointernal/agent/component/tavily_component_test.gointernal/agent/component/universe_a_wrappers.gointernal/agent/component/verify_p1_test.gointernal/agent/tool/registry.gointernal/agent/tool/registry_test.gointernal/agent/tool/tavily.gointernal/agent/tool/tavily_test.go
| 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, |
There was a problem hiding this comment.
🎯 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.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/agent/component/tavily_component_test.go (1)
90-102: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd injection and non-override tests for TavilyExtract.
TestTavilyExtract_StoresAPIKeyonly verifies key storage. TavilySearch and BGPT both have injection and non-override tests, but TavilyExtract has neither. The injection intavilyExtractComponent.Invokeoccurs beforeInvokableRun, so you can verifyinputs["api_key"]afterInvokeeven 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
📒 Files selected for processing (5)
internal/agent/canvas/decode.gointernal/agent/component/bgpt_component_test.gointernal/agent/component/tavily_component_test.gointernal/agent/component/universe_a_wrappers.gointernal/service/canvas_decode_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- internal/agent/component/universe_a_wrappers.go
Summary
Tests: build.sh --test ./internal/agent/component ./internal/service — all pass.