Repository navigation
feat(core): Add JDK HTTP client in chat model - #338
Conversation
Change-Id: Ie5b50fcc4e497c1fcabb62d093900755dc8f1bcc
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Change-Id: I762ff285500f32a4925e0bb379adddc6931bff20
Change-Id: I24ad8f5dbbbdf44feb5e2d0c7823934a623c5346
There was a problem hiding this comment.
Pull request overview
This PR adds a JDK HTTP client implementation as a pure Java alternative to the existing OkHttp-based transport. The implementation provides HTTP request/response handling and Server-Sent Events (SSE) streaming capabilities using only JDK built-in libraries.
Key Changes:
- Implemented
JdkHttpTransportclass usingjava.net.http.HttpClient(JDK 11+) - Added support for synchronous HTTP requests and SSE streaming via reactive Flux
- Included comprehensive test suite with 809 lines covering various HTTP methods, streaming scenarios, error handling, and edge cases
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
JdkHttpTransport.java |
Core implementation of HTTP transport using JDK's HttpClient with connection pooling, configurable timeouts, and SSE streaming support |
JdkHttpTransportTest.java |
Comprehensive test suite covering HTTP methods (GET, POST, PUT, DELETE, PATCH, OPTIONS), streaming, error handling, connection lifecycle, and edge cases |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Change-Id: I2237431c90ec14df28ca23b19d8dad393e2b2816
Change-Id: Ie7b85a656366bb04dad10b2400deece1ed83125e
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Change-Id: Iaf7c22811bfd1abe13706ce4296152cd83ebbde0
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Change-Id: Iffbdaf7b97d67c5f67ebfa45c40b610965fc79c3
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| closeQuietly(inputStream); | ||
| } | ||
| }) | ||
| .subscribeOn(Schedulers.boundedElastic()); |
There was a problem hiding this comment.
The stream method uses subscribeOn(Schedulers.boundedElastic()) but OkHttpTransport uses publishOn(Schedulers.boundedElastic()). There is an important difference:
- subscribeOn controls where the subscription and initial setup happens
- publishOn controls where downstream operators execute
Using subscribeOn here means the blocking I/O operations (readLine) execute on the boundedElastic scheduler, which is correct for blocking operations. However, this differs from the OkHttpTransport pattern. For consistency and to ensure the blocking HTTP call and stream reading happen on the correct scheduler, this implementation is actually more appropriate than OkHttpTransport's publishOn.
That said, the inconsistency between the two implementations could be confusing. Consider using publishOn for consistency with OkHttpTransport, or update OkHttpTransport to use subscribeOn if that's the preferred pattern.
| .build(); | ||
|
|
||
| List<String> events = new ArrayList<>(); | ||
| transport.stream(request).doOnNext(events::add).blockLast(); |
There was a problem hiding this comment.
The test uses blockLast() without a timeout, which could cause the test to hang indefinitely if something goes wrong with the stream. While the test does work in normal scenarios, consider adding a timeout for robustness, similar to line 628 which uses blockLast(Duration.ofSeconds(5)).
| transport.stream(request).doOnNext(events::add).blockLast(); | |
| transport.stream(request).doOnNext(events::add).blockLast(Duration.ofSeconds(5)); |
…g semantics Follow-up to the re-review (all 4 warnings + 3 infos addressed): - Capability contract (agentscope-ai#338): ReActAgent validates the chain at build time and warns when a candidate reports a smaller context window or different structured-output support than the primary (the chain reports the primary's capabilities). FallbackChainModel javadoc documents the compatibility requirement; agent.md EN+ZH updated. - Cooldown semantics (agentscope-ai#185, agentscope-ai#240): auth failures (401/403) are no longer cooled — a wrong credential will not fix itself and the real auth error must surface; they still switch. Mid-stream failures only cool the candidate when classified SWITCHABLE (request-shaped failures like oversized payloads do not park the primary for other sessions). The all-cooling error now propagates the last real failure as cause (remembered per candidate) instead of a bare synthetic message; wording no longer counts the primary as a 'fallback candidate'. - Cooldown key (agentscope-ai#286): replaced System.identityHashCode with the stable chain index (collision-free across wrapper instances sharing a table with the same candidate order). - Cleanup (agentscope-ai#258): removed the tautological size() > 0 && !isEmpty() guard (removeIf is a no-op on an empty map). - Docs (agentscope-ai#657, agentscope-ai#626): agent.md EN capability bullet now matches the code (reports the primary); added the ZH fallbackModels section mirroring the EN one. Tests: 3 new cases (auth-not-cooled, mid-stream request-side not cooled, all-cooling preserves cause); existing cooldown-message test updated to assert the propagated last failure; FallbackChainModelTest 29/29, ReActAgentFallbackChainTest 9/9, model+agent package 373 green.
AgentScope-Java Version
1.0.4-SNAPSHOT
Description
Closes #221
Checklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)