feat(rag): add ExternalApiReader for third-party document parsing int…#318
Merged
AlbumenJ merged 17 commits intoagentscope-ai:mainfrom Dec 29, 2025
Merged
feat(rag): add ExternalApiReader for third-party document parsing int…#318AlbumenJ merged 17 commits intoagentscope-ai:mainfrom
AlbumenJ merged 17 commits intoagentscope-ai:mainfrom
Conversation
…egration - Add generic external API document parsing reader - Support custom HTTP request construction and response parsing - Support polling for asynchronous task completion - Include comprehensive tests and MinerU Tianshu integration example - Support multiple document formats (PDF, DOCX, PPTX, XLSX, TXT)
…egration - Add generic external API document parsing reader - Support custom HTTP request construction and response parsing - Support polling for asynchronous task completion - Include comprehensive tests and MinerU Tianshu integration example - Support multiple document formats (PDF, DOCX, PPTX, XLSX, TXT)
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a generic ExternalApiReader to enable seamless integration with third-party document parsing services in the RAG module. The implementation follows a functional interface approach with customizable HTTP request building and response parsing.
Key Changes:
- Adds
ExternalApiReaderwith functional interfaces (RequestBuilderandResponseParser) for flexible API integration - Implements retry mechanism with exponential backoff and configurable timeouts
- Includes comprehensive unit tests with MockWebServer for HTTP interactions
- Provides a complete MinerU Tianshu integration example demonstrating async task polling
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 19 comments.
| File | Description |
|---|---|
| ExternalApiReader.java | Core implementation extending AbstractChunkingReader with builder pattern, retry logic, and support for custom HTTP client configuration |
| ExternalApiReaderTest.java | Comprehensive unit tests covering sync/async APIs, authentication, multipart uploads, retry behavior, and custom interceptors |
| MinerUTianshuReaderExample.java | Production-ready integration example with MinerU Tianshu API showing task submission, polling, and various configuration options |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...extensions-rag-simple/src/test/java/io/agentscope/core/rag/reader/ExternalApiReaderTest.java
Outdated
Show resolved
Hide resolved
...extensions-rag-simple/src/test/java/io/agentscope/core/rag/reader/ExternalApiReaderTest.java
Outdated
Show resolved
Hide resolved
...ope-extensions-rag-simple/src/main/java/io/agentscope/core/rag/reader/ExternalApiReader.java
Show resolved
Hide resolved
...extensions-rag-simple/src/test/java/io/agentscope/core/rag/reader/ExternalApiReaderTest.java
Outdated
Show resolved
Hide resolved
...extensions-rag-simple/src/test/java/io/agentscope/core/rag/reader/ExternalApiReaderTest.java
Outdated
Show resolved
Hide resolved
...extensions-rag-simple/src/test/java/io/agentscope/core/rag/reader/ExternalApiReaderTest.java
Outdated
Show resolved
Hide resolved
...ope-extensions-rag-simple/src/main/java/io/agentscope/core/rag/reader/ExternalApiReader.java
Show resolved
Hide resolved
...extensions-rag-simple/src/test/java/io/agentscope/core/rag/reader/ExternalApiReaderTest.java
Outdated
Show resolved
Hide resolved
...extensions-rag-simple/src/test/java/io/agentscope/core/rag/reader/ExternalApiReaderTest.java
Outdated
Show resolved
Hide resolved
...ope-extensions-rag-simple/src/main/java/io/agentscope/core/rag/reader/ExternalApiReader.java
Outdated
Show resolved
Hide resolved
Collaborator
…y and improve CI stability - Refactor ExternalApiReaderTest to use configuration validation instead of network mocking - Remove MockWebServer dependency to eliminate timeout issues (907s -> <1s) - Convert all Chinese comments to English - Add 11 focused unit tests covering builder validation, error handling, and usage patterns - Mark MinerUTianshuReaderExample as final with private constructor to clarify it's not a test class - Add explicit documentation that example class won't be executed in CI/CD - Improve test execution speed and reliability for CI environments Fixes the test timeout issue where testSimpleSyncApi was taking 907 seconds due to: - Long default readTimeout (5 minutes) - Multiple retry attempts (4 total attempts) - Network socket timeout errors The new test approach focuses on testing the API design and configuration rather than actual HTTP communication, making tests more stable and faster.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
Author
AlbumenJ
approved these changes
Dec 29, 2025
JGoP-L
pushed a commit
to JGoP-L/agentscope-java
that referenced
this pull request
Dec 29, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Closes #317
This PR adds a generic
ExternalApiReaderto enable seamless integration with third-party document parsing services in the RAG module.Changes Made
AgentScope-Java Version
1.0.4-SNAPSHOT
Description
Background:
The existing RAG module lacks a flexible way to integrate with external document parsing services. This limitation prevents users from leveraging powerful third-party APIs like MinerU Tianshu, cloud OCR services, or enterprise document processing systems.
Solution:
This PR introduces
ExternalApiReader, a highly configurable reader that uses functional interfaces to adapt to any external API. It extendsAbstractChunkingReaderto maintain consistency with existing readers while providing maximum flexibility.Key Features:
RequestBuilderandResponseParserallow users to customize HTTP requests and response parsing logicExample Usage:
ExternalApiReader reader = ExternalApiReader.builder()
.requestBuilder((filePath, client) -> {
// Custom request building
return new Request.Builder()
.url("https://api.example.com/parse")
.header("Authorization", "Bearer TOKEN")
.post(createRequestBody(filePath))
.build();
})
.responseParser((response, client) -> {
// Custom response parsing
return extractMarkdown(response);
})
.chunkSize(512)
.splitStrategy(SplitStrategy.PARAGRAPH)
.build();
List docs = reader.read(ReaderInput.fromString("file.pdf")).block();Testing:
Checklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)Additional Notes
Files Added:
ExternalApiReader.java(444 lines) - Core implementationExternalApiReaderTest.java(434 lines) - Comprehensive unit testsMinerUTianshuReaderExample.java(363 lines) - Production-ready integration exampleIntegration Example:
The included
MinerUTianshuReaderExampledemonstrates integration with MinerU Tianshu (https://github.com/magicyuan876/mineru-tianshu), a powerful open-source document parsing service. This example can serve as a template for integrating other similar services.Benefits:
Related Issue: #317