Repository navigation
fix(go-agent): unknown component "Wikipedia" canvas error. - #16784
Conversation
…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).
📝 WalkthroughWalkthroughThe Wikipedia search tool now uses MediaWiki’s ChangesWikipedia Search Feature
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
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 (3)
internal/agent/tool/wikipedia.go (2)
76-86: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winMediaWiki API-level errors are silently swallowed.
MediaWiki can return HTTP 200 with an error body (e.g.,
{"error":{"code":"...","info":"..."}}). ThewikipediaResponsestruct only decodesquery, 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 winDoc 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 valueDoc 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
📒 Files selected for processing (8)
internal/agent/component/fixture_stubs.gointernal/agent/component/universe_a_wrappers.gointernal/agent/component/verify_p1_test.gointernal/agent/component/wikipedia_component_test.gointernal/agent/tool/registry.gointernal/agent/tool/registry_test.gointernal/agent/tool/wikipedia.gointernal/agent/tool/wikipedia_test.go
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/agent/component/wikipedia_component_test.go (1)
112-132: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicated transport helper across packages.
componentRewriteHostTransport,componentHostSwapRT, and itsRoundTripmethod are identical to the helpers ininternal/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 thecomponentandtooltest 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
📒 Files selected for processing (4)
internal/agent/component/universe_a_wrappers.gointernal/agent/component/wikipedia_component_test.gointernal/agent/tool/wikipedia.gointernal/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
Summary
wikipedia/wikipedia_searchgenerator=searchto get title/summary/url in one request (was N+1)top_n/languagewith validationformalized_contentfor downstream