Skip to content

Port agent PRs to GO - 3 - #16596

Merged
yuzhichang merged 2 commits into
infiniflow:mainfrom
qinling0210:port_to_go
Jul 3, 2026
Merged

yuzhichang merged 2 commits into
infiniflow:mainfrom
qinling0210:port_to_go

Conversation

@qinling0210

Copy link
Copy Markdown
Contributor

Summary

Port
#16415
#16417

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 3, 2026
@coderabbitai

coderabbitai Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Replaces the AkShare stub with an HTTP-backed Eastmoney stock news tool, renames the crawler tool's primary input from url to query with legacy support, and updates registry wiring, tests, and inventory coverage.

Changes

AkShare Stock News Tool

Layer / File(s) Summary
Argument model, data types, and constructors
internal/agent/tool/akshare.go
Defines the query-based AkShare argument model, Eastmoney request/response types, and AkShareTool state with injected HTTP helper and configurable topN.
Fetch, parse, and format stock news
internal/agent/tool/akshare.go
Updates Info and InvokableRun to validate arguments, build the Eastmoney URL, fetch and parse JSONP, normalize articles, and return content plus structured articles.
AkShare tool tests
internal/agent/tool/akshare_test.go
Adds JSONP fetch coverage, updates malformed-args and missing-query assertions, rewrites Info checks, and extends URL-builder and top_n validation tests.
Registry wiring and tool inventory coverage
internal/agent/tool/registry.go, internal/agent/tool/registry_test.go, tools/gen-component-parity/main.go
Adds buildAkShareTool with top_n validation, registers web_crawler, expands registry alias coverage, and adds web_crawler to the parity tool list.

Web Crawler Query Argument Rename

Layer / File(s) Summary
Query argument contract and entry validation
internal/agent/tool/crawler.go
Renames the tool to web_crawler, adds query-first argument resolution with legacy url fallback, updates Info, and validates the resolved target URL before fetch execution.
Crawler tests for query argument and legacy url support
internal/agent/tool/crawler_test.go
Updates fetch and validation tests to use query, adds legacy url acceptance coverage, and expands Info assertions for the query-based schema.

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

Suggested labels: size:XXL, 🧪 test

Suggested reviewers: yingfeng, yuzhichang, JinHai-CN

Poem

A rabbit hops through bytes today,
For stock news and web paths, hooray! 🐇
Query in, and URLs too,
The tools now speak a clearer view.
With tests that bounce and registry rings,
I nibble code and celebrate these things.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description only says "Port" and links two PRs, but it lacks the required summary and background context. Add a brief Summary that explains what was ported, why it was needed, and any relevant background or impact.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and correctly indicates this PR ports agent work to Go, matching the main changeset.
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.

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

🧹 Nitpick comments (1)
internal/agent/tool/registry_test.go (1)

119-190: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Coverage gap: no test exercises buildAkShareTool's top_n validation.

The alias/schema sweep here only builds akshare with empty params, so the unknown-key and non-positive/invalid top_n error paths in buildAkShareTool (registry.go Lines 110-126) aren't covered here, unlike the dedicated TestBuildAll_KeenableRejectsEmptyNodeAPIKey pattern (Lines 95-105). If akshare's own test file doesn't cover this either, consider adding a similar rejection test here.

🤖 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_test.go` around lines 119 - 190, Add coverage
for buildAkShareTool’s top_n validation by introducing a dedicated rejection
test that exercises the akshare registry path with invalid input, since the
current BuildAll alias/schema sweep only uses empty params and misses the
unknown-key and non-positive/invalid top_n cases. Follow the pattern used by
TestBuildAll_KeenableRejectsEmptyNodeAPIKey, and reference buildAkShareTool and
BuildAll in the new test so the failure path is covered even if akshare’s own
test file does not already assert it.
🤖 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/akshare_test.go`:
- Around line 31-40: The assertions inside the HTTP handler in akshare_test.go
should not use t.Fatalf because they run in a separate goroutine and can leave
the test in an inconsistent state. Update the handler logic in the test around
the request validation for r.URL.Path, json.Unmarshal, and req.Keyword to use
t.Errorf for failures and return immediately from the handler after each failed
check, so the main test can observe the error cleanly.

In `@internal/agent/tool/akshare.go`:
- Around line 156-207: The Eastmoney request is ignoring the resolved topN and
always using the default page size, so larger requested counts are never
honored. Update InvokableRun’s call path into buildAkShareStockNewsURL so the
effective topN is passed through, and change buildAkShareStockNewsURL to use
that value in the request payload instead of defaultAkShareTopN. Make sure the
generated URL/request in akshare.go reflects the caller’s requested top_n while
preserving the existing error handling and response parsing.
- Around line 177-183: The akshare response handling in parse flow currently
uses io.ReadAll on resp.Body without any size limit, which can consume unbounded
memory if the upstream payload is too large. Update the response reading logic
in the akshare request path to cap the body size before parsing the JSONP
payload, and keep the existing error wrapping and akshareErrJSON handling intact
when the read fails or the limit is exceeded.

In `@internal/agent/tool/registry.go`:
- Around line 110-126: The AkShare tool builder currently treats an unparsable
top_n as missing and silently falls back to the default, which hides
misconfiguration. Update buildAkShareTool to distinguish between an absent top_n
and a present-but-invalid one by checking the key before calling intParam, and
return an error when top_n exists but cannot be parsed as an integer. Keep the
existing validation and return path in buildAkShareTool/NewAkShareToolWithTopN,
but make sure invalid top_n inputs fail fast instead of using
defaultAkShareTopN.

---

Nitpick comments:
In `@internal/agent/tool/registry_test.go`:
- Around line 119-190: Add coverage for buildAkShareTool’s top_n validation by
introducing a dedicated rejection test that exercises the akshare registry path
with invalid input, since the current BuildAll alias/schema sweep only uses
empty params and misses the unknown-key and non-positive/invalid top_n cases.
Follow the pattern used by TestBuildAll_KeenableRejectsEmptyNodeAPIKey, and
reference buildAkShareTool and BuildAll in the new test so the failure path is
covered even if akshare’s own test file does not already assert it.
🪄 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: ea3e05b4-f447-4b53-8c1c-12c1fb57536f

📥 Commits

Reviewing files that changed from the base of the PR and between 7b34153 and bcdbe59.

📒 Files selected for processing (7)
  • internal/agent/tool/akshare.go
  • internal/agent/tool/akshare_test.go
  • internal/agent/tool/crawler.go
  • internal/agent/tool/crawler_test.go
  • internal/agent/tool/registry.go
  • internal/agent/tool/registry_test.go
  • tools/gen-component-parity/main.go

Comment thread internal/agent/tool/akshare_test.go Resolved
Comment thread internal/agent/tool/akshare.go Resolved
Comment thread internal/agent/tool/akshare.go Resolved
Comment on lines +110 to +126
func buildAkShareTool(params map[string]any) (einotool.BaseTool, error) {
topN := defaultAkShareTopN
if len(params) != 0 {
for key := range params {
if key != "top_n" {
return nil, fmt.Errorf("agent tool: tool %q only accepts node-level param top_n", "akshare")
}
}
if v, ok := intParam(params, "top_n"); ok {
topN = v
}
if topN <= 0 {
return nil, fmt.Errorf("agent tool: tool %q requires positive integer node-level param top_n", "akshare")
}
}
return NewAkShareToolWithTopN(nil, topN), nil
}

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
# Confirm intParam's ok-return semantics on type mismatch
rg -n -A15 'func intParam' internal/agent/tool/registry.go

Repository: infiniflow/ragflow

Length of output: 523


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect sibling tool builders and nearby validation patterns in registry.go
ast-grep outline internal/agent/tool/registry.go --view expanded || true
printf '\n---\n'
sed -n '1,260p' internal/agent/tool/registry.go | cat -n | sed -n '1,220p'

Repository: infiniflow/ragflow

Length of output: 10100


Reject non-integer top_n values
internal/agent/tool/registry.go:118 — if top_n is present but not an integer, intParam returns false and the builder silently falls back to defaultAkShareTopN, masking a misconfiguration. Return an error when the key is present but unparsable.

🤖 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` around lines 110 - 126, The AkShare tool
builder currently treats an unparsable top_n as missing and silently falls back
to the default, which hides misconfiguration. Update buildAkShareTool to
distinguish between an absent top_n and a present-but-invalid one by checking
the key before calling intParam, and return an error when top_n exists but
cannot be parsed as an integer. Keep the existing validation and return path in
buildAkShareTool/NewAkShareToolWithTopN, but make sure invalid top_n inputs fail
fast instead of using defaultAkShareTopN.

@yuzhichang yuzhichang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 3, 2026
@qinling0210 qinling0210 added the ci Continue Integration label Jul 3, 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: 1

🤖 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/akshare.go`:
- Around line 270-281: The raw JSON handling in stripJSONP is being bypassed
whenever the body contains any parentheses, which can cause valid JSON to be
truncated. Update stripJSONP to check for a JSON payload first (using the
existing strings.HasPrefix(s, "{") path) before searching for parentheses, then
only extract the content inside (...) when the response is actually JSONP. Keep
the behavior and error message in stripJSONP consistent for invalid akshare
responses.
🪄 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: 27eb9b61-4d92-4b1e-a702-d24b11044b9f

📥 Commits

Reviewing files that changed from the base of the PR and between bcdbe59 and e8c8ac4.

📒 Files selected for processing (7)
  • internal/agent/tool/akshare.go
  • internal/agent/tool/akshare_test.go
  • internal/agent/tool/crawler.go
  • internal/agent/tool/crawler_test.go
  • internal/agent/tool/registry.go
  • internal/agent/tool/registry_test.go
  • tools/gen-component-parity/main.go
🚧 Files skipped from review as they are similar to previous changes (6)
  • internal/agent/tool/crawler_test.go
  • tools/gen-component-parity/main.go
  • internal/agent/tool/registry_test.go
  • internal/agent/tool/registry.go
  • internal/agent/tool/crawler.go
  • internal/agent/tool/akshare_test.go

Comment on lines +270 to +281
func stripJSONP(s string) (string, error) {
s = strings.TrimSpace(s)
start := strings.IndexByte(s, '(')
end := strings.LastIndexByte(s, ')')
if start < 0 || end <= start {
if strings.HasPrefix(s, "{") {
return s, nil
}
return "", fmt.Errorf("akshare: invalid JSONP response")
}
return strings.TrimSpace(s[start+1 : end]), nil
}

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

Check for raw JSON before extracting between parentheses.

The HasPrefix(s, "{") fallback is only reached when no valid (...) pair exists. A raw JSON body that happens to contain parentheses (e.g. inside a string value) satisfies start >= 0 && end > start, so it gets truncated to the substring between the first ( and last ) instead of being returned intact. Reorder so the raw-JSON case is handled first.

🐛 Proposed fix
 func stripJSONP(s string) (string, error) {
 	s = strings.TrimSpace(s)
+	if strings.HasPrefix(s, "{") {
+		return s, nil
+	}
 	start := strings.IndexByte(s, '(')
 	end := strings.LastIndexByte(s, ')')
 	if start < 0 || end <= start {
-		if strings.HasPrefix(s, "{") {
-			return s, nil
-		}
 		return "", fmt.Errorf("akshare: invalid JSONP response")
 	}
 	return strings.TrimSpace(s[start+1 : end]), nil
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func stripJSONP(s string) (string, error) {
s = strings.TrimSpace(s)
start := strings.IndexByte(s, '(')
end := strings.LastIndexByte(s, ')')
if start < 0 || end <= start {
if strings.HasPrefix(s, "{") {
return s, nil
}
return "", fmt.Errorf("akshare: invalid JSONP response")
}
return strings.TrimSpace(s[start+1 : end]), nil
}
func stripJSONP(s string) (string, error) {
s = strings.TrimSpace(s)
if strings.HasPrefix(s, "{") {
return s, nil
}
start := strings.IndexByte(s, '(')
end := strings.LastIndexByte(s, ')')
if start < 0 || end <= start {
return "", fmt.Errorf("akshare: invalid JSONP response")
}
return strings.TrimSpace(s[start+1 : end]), nil
}
🧰 Tools
🪛 golangci-lint (2.12.2)

[error] 270-270: : # ragflow/internal/ingestion/compilation/extractor [ragflow/internal/ingestion/compilation/extractor.test]
internal/ingestion/compilation/extractor/dep_relation.go:270:9: undefined: Entity
internal/ingestion/compilation/extractor/dep_relation.go:281:69: undefined: Entity
internal/ingestion/compilation/extractor/dep_relation.go:281:109: undefined: Relation
internal/ingestion/compilation/extractor/dep_relation.go:353:27: undefined: Relation
internal/ingestion/compilation/extractor/dep_relation.go:401:37: undefined: Entity
internal/ingestion/compilation/extractor/dep_relation.go:416:56: undefined: Entity
internal/ingestion/compilation/extractor/dep_relation.go:430:97: undefined: Entity
internal/ingestion/compilation/extractor/dep_relation.go:505:90: undefined: Entity
internal/ingestion/compilation/extractor/dep_relation.go:505:113: undefined: Relation
internal/ingestion/compilation/extractor/dep_relation.go:604:88: undefined: Entity
internal/ingestion/compilation/extractor/dep_relation.go:604:88: too many errors

(typecheck)

🤖 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/akshare.go` around lines 270 - 281, The raw JSON handling
in stripJSONP is being bypassed whenever the body contains any parentheses,
which can cause valid JSON to be truncated. Update stripJSONP to check for a
JSON payload first (using the existing strings.HasPrefix(s, "{") path) before
searching for parentheses, then only extract the content inside (...) when the
response is actually JSONP. Keep the behavior and error message in stripJSONP
consistent for invalid akshare responses.

@yuzhichang
yuzhichang merged commit ffc4d29 into infiniflow:main Jul 3, 2026
3 checks passed
xugangqiang pushed a commit to xugangqiang/ragflow that referenced this pull request Jul 3, 2026
xugangqiang pushed a commit to xugangqiang/ragflow that referenced this pull request Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration lgtm This PR has been approved by a maintainer 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