Skip to content

feat(core): Add JDK HTTP client in chat model - #338

Merged
AlbumenJ merged 7 commits into
agentscope-ai:mainfrom
uuuyuqi:main
Dec 29, 2025
Merged

AlbumenJ merged 7 commits into
agentscope-ai:mainfrom
uuuyuqi:main

Conversation

@uuuyuqi

@uuuyuqi uuuyuqi commented Dec 24, 2025 •

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

1.0.4-SNAPSHOT

Description

Closes #221

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

Change-Id: Ie5b50fcc4e497c1fcabb62d093900755dc8f1bcc
@uuuyuqi
uuuyuqi requested a review from a team December 24, 2025 13:28
@codecov

codecov Bot commented Dec 24, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.96296% with 23 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ntscope/core/model/transport/JdkHttpTransport.java 82.96% 17 Missing and 6 partials ⚠️

📢 Thoughts on this report? Let us know!

Change-Id: I762ff285500f32a4925e0bb379adddc6931bff20
Change-Id: I24ad8f5dbbbdf44feb5e2d0c7823934a623c5346

Copilot AI 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.

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 JdkHttpTransport class using java.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.

Copilot AI 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.

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

Copilot AI 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.

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

Copilot AI 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.

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

Copilot AI 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.

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());

Copilot AI Dec 29, 2025

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
.build();

List<String> events = new ArrayList<>();
transport.stream(request).doOnNext(events::add).blockLast();

Copilot AI Dec 29, 2025

Copy link

Choose a reason for hiding this comment

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

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)).

Suggested change
transport.stream(request).doOnNext(events::add).blockLast();
transport.stream(request).doOnNext(events::add).blockLast(Duration.ofSeconds(5));

Copilot uses AI. Check for mistakes.
@AlbumenJ
AlbumenJ merged commit d40aea3 into agentscope-ai:main Dec 29, 2025
JGoP-L pushed a commit to JGoP-L/agentscope-java that referenced this pull request Dec 29, 2025
Letter2025 added a commit to Letter2025/agentscope-java that referenced this pull request Sep 16, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: JDK Http Client in Chat Model

3 participants