You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug description
In the latest version of the Spring AI framework (m7), the validateToolContextSupport method has a bug introduced during refactoring. Specifically, the variable handling in the if condition is incorrect, causing an IllegalArgumentException to be thrown erroneously when ToolContext is non-null and its context is non-empty. This behavior worked correctly in version m6, but the refactoring in m7 introduced this issue.
Below is a code comparison:
m6 version:
privatevoidvalidateToolContextSupport(@NullableToolContexttoolContext) {
varisToolContextRequired = toolContext != null && !CollectionUtils.isEmpty(toolContext.getContext());
varisToolContextAcceptedByMethod = Stream.of(toolMethod.getParameterTypes())
.anyMatch(type -> ClassUtils.isAssignable(type, ToolContext.class));
if (isToolContextRequired && !isToolContextAcceptedByMethod) {
thrownewIllegalArgumentException("ToolContext is not supported by the method as an argument");
}
}
m7 version:
privatevoidvalidateToolContextSupport(@NullableToolContexttoolContext) {
varisNonEmptyToolContextProvided = toolContext != null && !CollectionUtils.isEmpty(toolContext.getContext());
varisToolContextAcceptedByMethod = Stream.of(toolMethod.getParameterTypes())
.anyMatch(type -> ClassUtils.isAssignable(type, ToolContext.class));
if (isToolContextAcceptedByMethod && !isNonEmptyToolContextProvided) {
thrownewIllegalArgumentException("ToolContext is required by the method as an argument");
}
}
Although the code appears identical, in m7, the evaluation of isToolContextAcceptedByMethod seems to misbehave, likely due to incorrect variable scoping or context handling during refactoring, causing the exception to be thrown unexpectedly.
Environment
Spring AI version: spring-ai-M7
Java version: [Java 17]
Steps to reproduce
Using the Tools tool will cause this issue
Expected behavior
In version m7, the validateToolContextSupport method should behave as it did in m6, throwing an IllegalArgumentException only when ToolContext is non-null, its context is non-empty, and the method’s parameters do not support the ToolContext type. Currently, m7 incorrectly throws the exception, leading to functional issues.
Minimal Complete Reproducible example
Using Tools
The text was updated successfully, but these errors were encountered:
Bug description
In the latest version of the Spring AI framework (m7), the
validateToolContextSupport
method has a bug introduced during refactoring. Specifically, the variable handling in theif
condition is incorrect, causing anIllegalArgumentException
to be thrown erroneously whenToolContext
is non-null and its context is non-empty. This behavior worked correctly in version m6, but the refactoring in m7 introduced this issue.Below is a code comparison:
m6 version:
m7 version:
Although the code appears identical, in m7, the evaluation of
isToolContextAcceptedByMethod
seems to misbehave, likely due to incorrect variable scoping or context handling during refactoring, causing the exception to be thrown unexpectedly.Environment
Steps to reproduce
Using the Tools tool will cause this issue
Expected behavior
In version m7, the
validateToolContextSupport
method should behave as it did in m6, throwing anIllegalArgumentException
only whenToolContext
is non-null, its context is non-empty, and the method’s parameters do not support theToolContext
type. Currently, m7 incorrectly throws the exception, leading to functional issues.Minimal Complete Reproducible example
Using Tools
The text was updated successfully, but these errors were encountered: