Skip to content

Commit 7af0f33

Browse files
committed
style: apply Spring Java Format to async tool classes
Applied spring-javaformat:apply to fix formatting violations: - AsyncToolCallback.java: Fixed line length and annotation formatting - ToolExecutionMode.java: Fixed line length and Javadoc formatting Changes: ✅ Line length compliance (max 120 chars) ✅ Proper @annotation escaping in Javadoc ✅ Consistent spacing and indentation Signed-off-by: Spring AI Contributor <contributor@example.com> Signed-off-by: shaojie <741047428@qq.com>
1 parent ef817db commit 7af0f33

File tree

2 files changed

+67
-56
lines changed

2 files changed

+67
-56
lines changed

spring-ai-model/src/main/java/org/springframework/ai/model/tool/ToolExecutionMode.java

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@
2020
* Tool execution mode enumeration.
2121
*
2222
* <p>
23-
* Defines different execution modes for tool calls, used for performance optimization
24-
* and resource management.
23+
* Defines different execution modes for tool calls, used for performance optimization and
24+
* resource management.
2525
*
2626
* <h2>Usage Scenarios</h2>
2727
* <ul>
2828
* <li><strong>SYNC</strong>: Fast-executing tools (< 100ms), pure computation tasks</li>
29-
* <li><strong>ASYNC</strong>: I/O-involving operations (HTTP requests, database queries), long-running tasks (> 1 second)</li>
30-
* <li><strong>PARALLEL</strong>: Multiple independent tools that need parallel execution</li>
29+
* <li><strong>ASYNC</strong>: I/O-involving operations (HTTP requests, database queries),
30+
* long-running tasks (> 1 second)</li>
31+
* <li><strong>PARALLEL</strong>: Multiple independent tools that need parallel
32+
* execution</li>
3133
* <li><strong>STREAMING</strong>: Long-running tasks that require real-time feedback</li>
3234
* </ul>
3335
*
@@ -49,13 +51,12 @@ public enum ToolExecutionMode {
4951
* </ul>
5052
*
5153
* <p>
52-
* <strong>Performance Impact</strong>: Occupies threads in the thread pool and may become
53-
* a bottleneck in high concurrency scenarios. By default, synchronous tools execute
54-
* in the boundedElastic thread pool (maximum 80 threads).
54+
* <strong>Performance Impact</strong>: Occupies threads in the thread pool and may
55+
* become a bottleneck in high concurrency scenarios. By default, synchronous tools
56+
* execute in the boundedElastic thread pool (maximum 80 threads).
5557
*
56-
* <h3>Example</h3>
57-
* <pre>{@code
58-
* @Tool("calculate_sum")
58+
* <h3>Example</h3> <pre>{@code
59+
* &#64;Tool("calculate_sum")
5960
* public int calculateSum(int a, int b) {
6061
* // Pure computation, suitable for sync mode
6162
* return a + b;
@@ -68,7 +69,8 @@ public enum ToolExecutionMode {
6869
* Asynchronous execution mode.
6970
*
7071
* <p>
71-
* Tool execution doesn't block the calling thread, using reactive programming model. Suitable for:
72+
* Tool execution doesn't block the calling thread, using reactive programming model.
73+
* Suitable for:
7274
* <ul>
7375
* <li>Network I/O operations (HTTP requests, RPC calls)</li>
7476
* <li>Database queries and updates</li>
@@ -78,15 +80,14 @@ public enum ToolExecutionMode {
7880
* </ul>
7981
*
8082
* <p>
81-
* <strong>Performance Advantage</strong>: Doesn't occupy threads and can support thousands
82-
* or even tens of thousands of concurrent tool calls. In high concurrency scenarios,
83-
* performance improvement can reach 5-10x.
83+
* <strong>Performance Advantage</strong>: Doesn't occupy threads and can support
84+
* thousands or even tens of thousands of concurrent tool calls. In high concurrency
85+
* scenarios, performance improvement can reach 5-10x.
8486
*
85-
* <h3>Example</h3>
86-
* <pre>{@code
87-
* @Component
87+
* <h3>Example</h3> <pre>{@code
88+
* &#64;Component
8889
* public class AsyncWeatherTool implements AsyncToolCallback {
89-
* @Override
90+
* &#64;Override
9091
* public Mono<String> callAsync(String input, ToolContext context) {
9192
* // Network I/O, suitable for async mode
9293
* return webClient.get()
@@ -125,14 +126,14 @@ public enum ToolExecutionMode {
125126
* Parallel execution mode (future extension).
126127
*
127128
* <p>
128-
* Multiple tool calls can execute in parallel rather than sequentially.
129-
* Suitable for scenarios where tool calls have no dependencies.
129+
* Multiple tool calls can execute in parallel rather than sequentially. Suitable for
130+
* scenarios where tool calls have no dependencies.
130131
*
131132
* <p>
132-
* <strong>Note</strong>: This mode is not currently implemented, reserved for future extension.
133+
* <strong>Note</strong>: This mode is not currently implemented, reserved for future
134+
* extension.
133135
*
134-
* <h3>Future Usage</h3>
135-
* <pre>{@code
136+
* <h3>Future Usage</h3> <pre>{@code
136137
* // Possible future API
137138
* toolManager.executeInParallel(
138139
* toolCall1, // Get weather
@@ -152,14 +153,14 @@ public enum ToolExecutionMode {
152153
* Suitable for long-running tasks that require real-time feedback.
153154
*
154155
* <p>
155-
* <strong>Note</strong>: This mode is not currently implemented, reserved for future extension.
156+
* <strong>Note</strong>: This mode is not currently implemented, reserved for future
157+
* extension.
156158
*
157-
* <h3>Future Usage</h3>
158-
* <pre>{@code
159+
* <h3>Future Usage</h3> <pre>{@code
159160
* // Possible future API
160-
* @Component
161+
* &#64;Component
161162
* public class StreamingAnalysisTool implements StreamingToolCallback {
162-
* @Override
163+
* &#64;Override
163164
* public Flux<ToolExecutionChunk> executeStreaming(String input) {
164165
* return Flux.interval(Duration.ofSeconds(1))
165166
* .take(10)

spring-ai-model/src/main/java/org/springframework/ai/tool/AsyncToolCallback.java

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@
2727
* Asynchronous tool callback interface that supports non-blocking tool execution.
2828
*
2929
* <p>
30-
* Unlike traditional {@link ToolCallback}, async tools don't block threads and are suitable
31-
* for scenarios involving external API calls, database operations, and other I/O operations.
30+
* Unlike traditional {@link ToolCallback}, async tools don't block threads and are
31+
* suitable for scenarios involving external API calls, database operations, and other I/O
32+
* operations.
3233
*
3334
* <p>
3435
* <strong>Using async tools can significantly improve concurrency performance and prevent
3536
* thread pool exhaustion.</strong>
3637
*
37-
* <h2>Basic Usage</h2>
38-
* <pre>{@code
39-
* @Component
38+
* <h2>Basic Usage</h2> <pre>{@code
39+
* &#64;Component
4040
* public class AsyncWeatherTool implements AsyncToolCallback {
4141
*
4242
* private final WebClient webClient;
@@ -45,7 +45,8 @@
4545
* this.webClient = builder.baseUrl("https://api.weather.com").build();
4646
* }
4747
*
48-
* @Override
48+
49+
* &#64;Override
4950
* public Mono<String> callAsync(String toolInput, ToolContext context) {
5051
* WeatherRequest request = parseInput(toolInput);
5152
* return webClient.get()
@@ -55,7 +56,8 @@
5556
* .timeout(Duration.ofSeconds(5));
5657
* }
5758
*
58-
* @Override
59+
*
60+
&#64;Override
5961
* public ToolDefinition getToolDefinition() {
6062
* return ToolDefinition.builder()
6163
* .name("get_weather")
@@ -68,8 +70,9 @@
6870
*
6971
* <h2>Backward Compatibility</h2>
7072
* <p>
71-
* If only the async method is implemented, the synchronous {@link #call(String, ToolContext)}
72-
* method will automatically call {@link #callAsync(String, ToolContext)} and block for the result.
73+
* If only the async method is implemented, the synchronous
74+
* {@link #call(String, ToolContext)} method will automatically call
75+
* {@link #callAsync(String, ToolContext)} and block for the result.
7376
*
7477
* <h2>Performance Benefits</h2>
7578
* <table border="1">
@@ -109,15 +112,15 @@ public interface AsyncToolCallback extends ToolCallback {
109112
*
110113
* <h3>Best Practices</h3>
111114
* <ul>
112-
* <li>Use {@link Mono#timeout(java.time.Duration)} to set timeout and avoid infinite waiting</li>
115+
* <li>Use {@link Mono#timeout(java.time.Duration)} to set timeout and avoid infinite
116+
* waiting</li>
113117
* <li>Use {@link Mono#retry(long)} to handle temporary failures</li>
114118
* <li>Use {@link Mono#onErrorResume(Function)} to handle errors gracefully</li>
115119
* <li>Avoid blocking calls (like {@code Thread.sleep}) in async methods</li>
116120
* </ul>
117121
*
118-
* <h3>Example</h3>
119-
* <pre>{@code
120-
* @Override
122+
* <h3>Example</h3> <pre>{@code
123+
* &#64;Override
121124
* public Mono<String> callAsync(String toolInput, ToolContext context) {
122125
* return webClient.get()
123126
* .uri("/api/data")
@@ -131,22 +134,24 @@ public interface AsyncToolCallback extends ToolCallback {
131134
* @param toolInput the tool input arguments (JSON format)
132135
* @param context the tool execution context, may be null
133136
* @return a Mono that asynchronously returns the tool execution result
134-
* @throws org.springframework.ai.tool.execution.ToolExecutionException if tool execution fails
137+
* @throws org.springframework.ai.tool.execution.ToolExecutionException if tool
138+
* execution fails
135139
*/
136140
Mono<String> callAsync(String toolInput, @Nullable ToolContext context);
137141

138142
/**
139143
* Check if async execution is supported.
140144
*
141145
* <p>
142-
* Returns {@code true} by default. If a subclass overrides this method and returns {@code false},
143-
* the framework will use synchronous call {@link #call(String, ToolContext)} and execute it
144-
* in a separate thread pool (boundedElastic).
146+
* Returns {@code true} by default. If a subclass overrides this method and returns
147+
* {@code false}, the framework will use synchronous call
148+
* {@link #call(String, ToolContext)} and execute it in a separate thread pool
149+
* (boundedElastic).
145150
*
146151
* <p>
147152
* Can dynamically decide whether to use async based on runtime conditions:
148153
* <pre>{@code
149-
* @Override
154+
* &#64;Override
150155
* public boolean supportsAsync() {
151156
* // Use async only in production environment
152157
* return "production".equals(environment.getActiveProfiles()[0]);
@@ -159,13 +164,16 @@ default boolean supportsAsync() {
159164
}
160165

161166
/**
162-
* Execute tool call synchronously (backward compatibility - single parameter version).
167+
* Execute tool call synchronously (backward compatibility - single parameter
168+
* version).
163169
*
164170
* <p>
165-
* Default implementation delegates to the two-parameter version {@link #call(String, ToolContext)}.
171+
* Default implementation delegates to the two-parameter version
172+
* {@link #call(String, ToolContext)}.
166173
* @param toolInput the tool input arguments (JSON format)
167174
* @return the tool execution result
168-
* @throws org.springframework.ai.tool.execution.ToolExecutionException if tool execution fails
175+
* @throws org.springframework.ai.tool.execution.ToolExecutionException if tool
176+
* execution fails
169177
*/
170178
@Override
171179
default String call(String toolInput) {
@@ -176,20 +184,22 @@ default String call(String toolInput) {
176184
* Execute tool call synchronously (backward compatibility).
177185
*
178186
* <p>
179-
* Default implementation calls {@link #callAsync(String, ToolContext)} and blocks for the result.
180-
* This ensures backward compatibility but loses the performance benefits of async execution.
187+
* Default implementation calls {@link #callAsync(String, ToolContext)} and blocks for
188+
* the result. This ensures backward compatibility but loses the performance benefits
189+
* of async execution.
181190
*
182191
* <p>
183-
* <strong>Note</strong>: If your tool needs to support both sync and async calls,
184-
* you can override this method to provide an optimized synchronous implementation.
192+
* <strong>Note</strong>: If your tool needs to support both sync and async calls, you
193+
* can override this method to provide an optimized synchronous implementation.
185194
*
186195
* <p>
187-
* <strong>Warning</strong>: This method blocks the current thread until the async operation completes.
188-
* Avoid calling this method directly in reactive contexts.
196+
* <strong>Warning</strong>: This method blocks the current thread until the async
197+
* operation completes. Avoid calling this method directly in reactive contexts.
189198
* @param toolInput the tool input arguments (JSON format)
190199
* @param context the tool execution context, may be null
191200
* @return the tool execution result
192-
* @throws org.springframework.ai.tool.execution.ToolExecutionException if tool execution fails
201+
* @throws org.springframework.ai.tool.execution.ToolExecutionException if tool
202+
* execution fails
193203
*/
194204
@Override
195205
default String call(String toolInput, @Nullable ToolContext context) {

0 commit comments

Comments
 (0)