Skip to content

fix(go-agent): unknown component "Wikipedia" canvas error. - #16784

Merged
yuzhichang merged 4 commits into
infiniflow:mainfrom
Harry-Hz-Zhang:fix/agent-wiki
Jul 10, 2026
Merged

yuzhichang merged 4 commits into
infiniflow:mainfrom
Harry-Hz-Zhang:fix/agent-wiki

Conversation

@Harry-Hz-Zhang

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

Copy link
Copy Markdown
Contributor

Summary

  • Register Wikipedia component + tool alias wikipedia/wikipedia_search
  • Use generator=search to get title/summary/url in one request (was N+1)
  • Node params top_n/language with validation
  • Return formalized_content for downstream
  • tests pass
image

…ki API

Register the missing 'Wikipedia' canvas component in Go by wiring a
wikipediaComponent wrapper (universe_a_wrappers.go) that delegates to
the existing WikipediaTool. The underlying tool is refactored to:

- Use MediaWiki generator=search with prop=extracts|info, collapsing
  the Python library's N+1 requests (search + per-page summary) into a
  single HTTP call while returning the same title/url/summary fields.

- Accept top_n and language as node-level params via
  NewWikipediaToolWithParams, validated against Python's language list.

- Expose only 'query' to the LLM in Info() per Python's meta schema;
  lang and max_results are accepted in InvokableRun JSON as optional
  overrides that fall back to node-level defaults.

- Return formalized_content in the envelope for canvas downstream
  references, matching Python's _retrieve_chunks / set_output contract.

- Register both 'wikipedia' (legacy alias) and 'wikipedia_search'
  (canonical Python name) in the tool registry.

Tests pass for tool package and component package (targeted tests).
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 9, 2026
@coderabbitai

coderabbitai Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The Wikipedia search tool now uses MediaWiki’s generator=search API with configurable language and result-count defaults, updated result formatting, registry aliases, and a new Wikipedia canvas component wrapper with registration and tests.

Changes

Wikipedia Search Feature

Layer / File(s) Summary
Wikipedia tool query and response rewrite
internal/agent/tool/wikipedia.go, internal/agent/tool/wikipedia_test.go
Switches to generator=search, adds language support and topN/lang defaults, and returns results with Title, Content, URL, and formalized content.
Tool registry wiring
internal/agent/tool/registry.go, internal/agent/tool/registry_test.go
Adds parameter validation for top_n and language, registers wikipedia and wikipedia_search, and updates canonical-name and alias tests.
Wikipedia canvas component
internal/agent/component/...
Adds the Wikipedia wrapper, registers it as "Wikipedia", adds interface checks and component tests, and expands the registry-size test allowance.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Canvas
  participant wikipediaComponent
  participant WikipediaTool
  participant MediaWikiAPI
  Canvas->>wikipediaComponent: Invoke(query)
  wikipediaComponent->>WikipediaTool: Pass query envelope
  WikipediaTool->>MediaWikiAPI: Request generator=search
  MediaWikiAPI-->>WikipediaTool: Return pages with extracts
  WikipediaTool-->>wikipediaComponent: Return formalized content and results
  wikipediaComponent-->>Canvas: Return component output
Loading

Suggested reviewers: yuzhichang

Poem

A rabbit hopped through wiki grass,
Found fresh extracts as pages pass.
With language set and results bright,
The canvas wrapper works just right.
Hop, hop — new searches take flight!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 38.89% 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
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 clearly matches the main change: fixing the unknown Wikipedia component canvas error.
Description check ✅ Passed The description includes the required Summary section and covers the main fix, context, and behavior changes.

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 (3)
internal/agent/tool/wikipedia.go (2)

76-86: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

MediaWiki API-level errors are silently swallowed.

MediaWiki can return HTTP 200 with an error body (e.g., {"error":{"code":"...","info":"..."}}). The wikipediaResponse struct only decodes query, so API-level errors produce empty results with no error returned to the caller. Consider adding an error field to the response struct and surfacing it.

♻️ Proposed fix
 type wikipediaResponse struct {
+	Error *struct {
+		Code string `json:"code"`
+		Info string `json:"info"`
+	} `json:"error"`
 	Query struct {
 		Pages map[string]struct {
 			Index   int    `json:"index"`
 			Title   string `json:"title"`
 			Extract string `json:"extract"`
 			FullURL string `json:"fullurl"`
 		} `json:"pages"`
 	} `json:"query"`
 }

Then after decoding (around line 201):

+	if raw.Error != nil {
+		return wikipediaErrJSON(fmt.Errorf("wikipedia: API error %s: %s", raw.Error.Code, raw.Error.Info)),
+			fmt.Errorf("wikipedia: API error %s: %s", raw.Error.Code, raw.Error.Info)
+	}

Also applies to: 197-201

🤖 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/wikipedia.go` around lines 76 - 86, The wikipediaResponse
decoding only handles the query payload, so MediaWiki API-level failures are
treated as empty successes. Update wikipediaResponse in the Wikipedia tool to
include the top-level error envelope, then adjust the response handling after
the decode in the Wikipedia search flow to detect that error field and return it
to the caller instead of continuing with empty results.

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

Doc comments reference Python behavior instead of describing the current Go runtime path.

Multiple doc comments throughout this file describe Go behavior in terms of Python ("mirrors Python WikipediaParam.check", "matching Python's WikipediaParam.top_n", "equivalent of Python ToolBase._retrieve_chunks", "Python reads from wikipedia.page()"). Per the project coding guidelines for internal/**/*.go, doc comments should be aligned with the current runtime path, not with migration history.

Rewrite these comments to describe what the Go code does without referencing the Python implementation.

♻️ Proposed comment rewrites
-// WikipediaLanguageSupported mirrors Python WikipediaParam.check's accepted
-// language list.
+// WikipediaLanguageSupported reports whether the given language code is
+// accepted as a Wikipedia edition by the tool.
 func WikipediaLanguageSupported(language string) bool {
-// wikipediaResult mirrors the fields Python passes to _retrieve_chunks:
-// title, url, and summary content.
+// wikipediaResult is a single Wikipedia search result row containing the
+// page title, summary extract, and canonical URL.
 type wikipediaResult struct {
-// wikipediaEnvelope is what the model sees. The formalized_content field
-// is the canvas-facing equivalent of Python ToolBase._retrieve_chunks().
+// wikipediaEnvelope is the JSON output the model receives. The
+// formalized_content field is a rendered string of all result blocks
+// for downstream LLM prompts.
 type wikipediaEnvelope struct {
-// NewWikipediaToolWithParams returns a WikipediaTool with node-level
-// parameters matching Python's WikipediaParam.top_n and language fields.
+// NewWikipediaToolWithParams returns a WikipediaTool configured with
+// node-level defaults for the maximum result count and language.
 func NewWikipediaToolWithParams(h *HTTPHelper, topN int, language string) *WikipediaTool {
-// buildWikipediaURL constructs a MediaWiki generator=search URL that returns
-// the same page fields Python reads from wikipedia.page(): title, url,
-// and summary-like introductory extract.
+// buildWikipediaURL constructs a MediaWiki generator=search URL that
+// requests page extracts and canonical URLs for the given query.
 func buildWikipediaURL(lang, query string, topN int) string {

Also applies to: 68-69, 88-90, 117-118, 147-149

🤖 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/wikipedia.go` around lines 51 - 56, Doc comments in this
file still describe migration history instead of the Go runtime path. Update the
comments on WikipediaLanguageSupported and the other referenced symbols in this
file to describe what the Go code does now, without mentioning Python or
“mirrors/equivalent” wording. Keep the comments accurate, current, and aligned
with the behavior of the related helpers and constants in
internal/agent/tool/wikipedia.go.

Source: Coding guidelines

internal/agent/component/universe_a_wrappers.go (1)

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

Doc comment references Python instead of current Go runtime path.

Lines 184-185 reference "Python's canvas component" which is migration history. Per the project coding guidelines for internal/**/*.go, doc comments should be aligned with the current runtime path.

♻️ Proposed comment rewrite
-// wikipediaComponent delegates to internal/agent/tool/WikipediaTool.
-// Python's canvas component is named "Wikipedia" and stores top_n/language
-// on the node params while accepting query at runtime.
+// wikipediaComponent delegates to internal/agent/tool/WikipediaTool.
+// The component stores top_n/language as node-level params and accepts
+// query at runtime via Invoke.
 type wikipediaComponent struct {
🤖 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 183 - 185,
Update the doc comment on wikipediaComponent to describe the current Go runtime
behavior instead of Python migration history. Keep the comment aligned with
internal/agent/tool/WikipediaTool and the wrapper’s current behavior in the Go
path, and remove references to “Python’s canvas component” while preserving the
note about query being accepted at runtime and top_n/language being stored on
node params.

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/wikipedia.go`:
- Around line 233-236: The fallback URL in the Wikipedia lookup path is using
the tool’s default language instead of the resolved runtime language, so align
it with the same `lang` value used in the request flow. Update the fallback
construction in the `Wikipedia` tool logic where `fullURL` is synthesized to use
the resolved language variable rather than `w.lang`, ensuring `p.Lang` overrides
are reflected consistently.

---

Nitpick comments:
In `@internal/agent/component/universe_a_wrappers.go`:
- Around line 183-185: Update the doc comment on wikipediaComponent to describe
the current Go runtime behavior instead of Python migration history. Keep the
comment aligned with internal/agent/tool/WikipediaTool and the wrapper’s current
behavior in the Go path, and remove references to “Python’s canvas component”
while preserving the note about query being accepted at runtime and
top_n/language being stored on node params.

In `@internal/agent/tool/wikipedia.go`:
- Around line 76-86: The wikipediaResponse decoding only handles the query
payload, so MediaWiki API-level failures are treated as empty successes. Update
wikipediaResponse in the Wikipedia tool to include the top-level error envelope,
then adjust the response handling after the decode in the Wikipedia search flow
to detect that error field and return it to the caller instead of continuing
with empty results.
- Around line 51-56: Doc comments in this file still describe migration history
instead of the Go runtime path. Update the comments on
WikipediaLanguageSupported and the other referenced symbols in this file to
describe what the Go code does now, without mentioning Python or
“mirrors/equivalent” wording. Keep the comments accurate, current, and aligned
with the behavior of the related helpers and constants in
internal/agent/tool/wikipedia.go.
🪄 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: 66b9a186-b3b5-4dc3-b51d-c0709586f239

📥 Commits

Reviewing files that changed from the base of the PR and between b29a4a6 and 239aac1.

📒 Files selected for processing (8)
  • internal/agent/component/fixture_stubs.go
  • internal/agent/component/universe_a_wrappers.go
  • internal/agent/component/verify_p1_test.go
  • internal/agent/component/wikipedia_component_test.go
  • internal/agent/tool/registry.go
  • internal/agent/tool/registry_test.go
  • internal/agent/tool/wikipedia.go
  • internal/agent/tool/wikipedia_test.go

Comment thread internal/agent/tool/wikipedia.go Resolved
@Harry-Hz-Zhang Harry-Hz-Zhang added ci Continue Integration 🐞 bug Something isn't working, pull request that fix bug. labels Jul 10, 2026
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as draft July 10, 2026 02:27
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as ready for review July 10, 2026 02:27

@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/wikipedia_component_test.go (1)

112-132: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicated transport helper across packages.

componentRewriteHostTransport, componentHostSwapRT, and its RoundTrip method are identical to the helpers in internal/agent/tool/wikipedia_test.go:112-132. Per coding guidelines, duplicate implementations should be collapsed to one path. Consider extracting these to a shared internal test utility package (e.g., internal/agent/testutil) so both the component and tool test packages can import a single implementation.

♻️ Suggested extraction

Create a shared package, e.g. internal/agent/testutil/http.go:

package testutil

import (
	"net/http"
	"net/url"
)

func RewriteHostTransport(srvURL string) http.RoundTripper {
	u, err := url.Parse(srvURL)
	if err != nil {
		panic("RewriteHostTransport: bad srvURL: " + err.Error())
	}
	return &hostSwapRT{inner: http.DefaultTransport, host: u.Host, scheme: u.Scheme}
}

type hostSwapRT struct {
	inner  http.RoundTripper
	host   string
	scheme string
}

func (t *hostSwapRT) RoundTrip(req *http.Request) (*http.Response, error) {
	r2 := req.Clone(req.Context())
	r2.URL.Scheme = t.scheme
	r2.URL.Host = t.host
	r2.Host = t.host
	return t.inner.RoundTrip(r2)
}

Then in both test files, replace the local definitions with:

-func componentRewriteHostTransport(srvURL string) http.RoundTripper { ... }
-type componentHostSwapRT struct { ... }
-func (t *componentHostSwapRT) RoundTrip(...) { ... }
+Transport: testutil.RewriteHostTransport(srv.URL),
🤖 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/wikipedia_component_test.go` around lines 112 - 132,
Extract the duplicated componentRewriteHostTransport, componentHostSwapRT, and
RoundTrip implementation into a shared internal/agent/testutil helper, exposing
RewriteHostTransport and keeping the swap transport type private. Update both
wikipedia component and tool tests to import and use the shared helper, then
remove their local implementations.

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.

Nitpick comments:
In `@internal/agent/component/wikipedia_component_test.go`:
- Around line 112-132: Extract the duplicated componentRewriteHostTransport,
componentHostSwapRT, and RoundTrip implementation into a shared
internal/agent/testutil helper, exposing RewriteHostTransport and keeping the
swap transport type private. Update both wikipedia component and tool tests to
import and use the shared helper, then remove their local implementations.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 271adccc-b537-4fa5-ba17-27d7a7b8a9e6

📥 Commits

Reviewing files that changed from the base of the PR and between 66f8397 and fd619ea.

📒 Files selected for processing (4)
  • internal/agent/component/universe_a_wrappers.go
  • internal/agent/component/wikipedia_component_test.go
  • internal/agent/tool/wikipedia.go
  • internal/agent/tool/wikipedia_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • internal/agent/tool/wikipedia_test.go
  • internal/agent/component/universe_a_wrappers.go
  • internal/agent/tool/wikipedia.go

@yuzhichang
yuzhichang merged commit 07a3523 into infiniflow:main Jul 10, 2026
4 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 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