Skip to content

Conversation

@YunKuiLu
Copy link
Contributor

@YunKuiLu YunKuiLu commented Jul 25, 2025

  • If the cause is non-RuntimeException (e.g., IOException, OutOfMemoryError), rethrow the tool exception.
  • Update the relevant description in docs

explain

When users declare a tool using the @Tool annotation, they might throw a checked exception or an Error exception, like in the example below:

@Tool(description = "query weather")
public String queryWeather(@ToolParam(description = "city") String city) throws IOException {
    // call rpc service...
    // throw new OutOfMemoryError();
    throw new IOException("RPC service call failed");
}

Currently, the default behavior of DefaultToolExecutionExceptionProcessor is to pass checked exceptions and Errors to the AI Mode, which may cause users to fail to detect issues in a timely manner.

We should rethrow non-RuntimeException exceptions to remind users to handle them manually, rather than letting the AI Mode deal with them.


By the way (I just learned this too), when we use reflection to invoke a method, if the method throws an Error(no Exception), it will also be caught as an InvocationTargetException.
image

@YunKuiLu YunKuiLu force-pushed the tool_throw_checked_exception branch from c46a5c3 to 597f8a4 Compare July 25, 2025 16:42
- If the cause is a non-RuntimeException (e.g., IOException, OutOfMemoryError), rethrow the tool exception.
- Update the relevant description in docs

Signed-off-by: YunKui Lu <luyunkui95@gmail.com>
@YunKuiLu YunKuiLu force-pushed the tool_throw_checked_exception branch from 597f8a4 to af30705 Compare July 25, 2025 16:46
@sobychacko sobychacko added this to the 1.1.0.M1 milestone Aug 6, 2025
@sobychacko sobychacko merged commit 879350a into spring-projects:main Aug 6, 2025
2 checks passed
spring-builds pushed a commit that referenced this pull request Aug 6, 2025
Fixes #3915

- If the cause is a non-RuntimeException (e.g., IOException, OutOfMemoryError), rethrow the tool exception.
- Update the relevant description in docs

Signed-off-by: YunKui Lu <luyunkui95@gmail.com>
(cherry picked from commit 879350a)
juntae6942 pushed a commit to juntae6942/spring-ai that referenced this pull request Aug 7, 2025
…projects#3915)

Fixes spring-projects#3915

Auto-cherry-pick to 1.0.x

- If the cause is a non-RuntimeException (e.g., IOException, OutOfMemoryError), rethrow the tool exception.
- Update the relevant description in docs

Signed-off-by: YunKui Lu <luyunkui95@gmail.com>
@YunKuiLu YunKuiLu deleted the tool_throw_checked_exception branch August 8, 2025 16:23
scionaltera pushed a commit to scionaltera/spring-ai that referenced this pull request Sep 3, 2025
…projects#3915)

Fixes spring-projects#3915

Auto-cherry-pick to 1.0.x

- If the cause is a non-RuntimeException (e.g., IOException, OutOfMemoryError), rethrow the tool exception.
- Update the relevant description in docs

Signed-off-by: YunKui Lu <luyunkui95@gmail.com>
chedim pushed a commit to couchbaselabs/spring-ai that referenced this pull request Sep 19, 2025
…projects#3915)

Fixes spring-projects#3915

Auto-cherry-pick to 1.0.x

- If the cause is a non-RuntimeException (e.g., IOException, OutOfMemoryError), rethrow the tool exception.
- Update the relevant description in docs

Signed-off-by: YunKui Lu <luyunkui95@gmail.com>
Willam2004 pushed a commit to Willam2004/spring-ai that referenced this pull request Oct 11, 2025
…projects#3915)

Fixes spring-projects#3915

Auto-cherry-pick to 1.0.x

- If the cause is a non-RuntimeException (e.g., IOException, OutOfMemoryError), rethrow the tool exception.
- Update the relevant description in docs

Signed-off-by: YunKui Lu <luyunkui95@gmail.com>
Signed-off-by: 家娃 <guanjing.pangj@alibaba-inc.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants