-
Notifications
You must be signed in to change notification settings - Fork 128
feat(hook): Hook notifier optimize(#266) #267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sun-jin-xin
wants to merge
6
commits into
agentscope-ai:main
Choose a base branch
from
sun-jin-xin:HookNotifier_optimize
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
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
…uential execution of hooks.
…uential execution of hooks.
|
|
…uential execution of hooks.
AlbumenJ
requested changes
Dec 20, 2025
agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java
Outdated
Show resolved
Hide resolved
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…ic sync refresh of sortedHooks.
AlbumenJ
requested changes
Dec 22, 2025
agentscope-core/src/main/java/io/agentscope/core/agent/AgentBase.java
Outdated
Show resolved
Hide resolved
agentscope-core/src/main/java/io/agentscope/core/agent/AgentBase.java
Outdated
Show resolved
Hide resolved
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.
AgentScope-Java Version
1.0.4-SNAPSHOT
Description
Background
The group has long promoted the internalization of AI capabilities. Early business systems were built on a custom native agent framework, which hinders long-term iterative optimization and maintenance. To address this, we selected the lightweight AgentScope framework for system reconstruction. Notably, the business has strict requirements for high system throughput, and the current Hook event notification mechanism of ReActAgent has exposed prominent performance bottlenecks that cannot meet business needs:
Redundant Repeated Sorting Overhead
The
getSortedHooks()method is invoked to re-sort the Hook list on every event trigger (e.g., PreReasoning, ReasoningChunk). In high-frequency scenarios (e.g., streaming models returning 100+ Chunks), this generates unnecessary CPU consumption and invalid computations, wasting system resources.Inefficient Synchronous Blocking Execution
Hooks are executed sequentially through
forloops combined with flatMap, which fails to leverage Reactor's asynchronous non-blocking advantages. This leads to linear latency growth as the number of Hooks increases, severely restricting concurrent processing capabilities.Quantified Performance Limitations
These bottlenecks result in subpar system performance:
Optimization Objectives
Key Implementation Changes
1. Pre-Sorting and Caching of Hook List (Eliminate Redundant Sorting)
sortedHooksinReActAgentto cache the pre-sorted Hook list, avoiding repeated sorting during subsequent event notifications.ReActAgentconstructor, the Hook list is sorted once by priority (ascending order: lower priority indicates earlier execution) via Stream API, and collected into an unmodifiable list to ensure cache immutability and thread safety.getSortedHooks()in Hook notification methods, and uniformly used the cachedsortedHookslist to eliminate invalid CPU computations.2. Asynchronous Sequential Execution of Hooks (Optimize Execution Efficiency)
HookNotifierclass (includingnotifyPreReasoning,notifyPostReasoning,notifyPreActing,notifyReasoningChunk, etc.):notifyPreReasoning): AdoptedFlux.reduceto implement asynchronous sequential execution, ensuring Hook priority order while leveraging Reactor's non-blocking capabilities.notifyReasoningChunk,notifyActingChunk): UsedFlux.concatMapto guarantee execution order and improve asynchronous processing throughput.forloop + sequentialflatMapsynchronous blocking logic with reactive stream processing, reducing thread blocking time and improving concurrent processing performance.3. Compatibility and Standardization Optimization
sortedHooksvariable and all refactored methods, complying with the project's documentation conventions.mvn spotless:applyto align with the project's coding style requirements.Test Plan for This PR
To fully verify the performance improvement and functional stability of the optimization, the following multi-layered test plan is executed:
1. Micro-Benchmark Test (Isolated Hook Notification Performance)
HookNotifier.notifyPreReasoning())2. Integration Test (End-to-End Agent Performance)
3. High Concurrency Pressure Test (System-Level Throughput)
4. Functional Compatibility Test (Prevent Regression)
mvn testto ensure 100% test case pass rate.Checklist
mvn spotless:applymvn test)