4444public class FunctionTool extends BaseTool {
4545
4646 private static final Logger logger = LoggerFactory .getLogger (FunctionTool .class );
47- private static final ObjectMapper objectMapper = JsonBaseModel .getMapper ();
4847
4948 private final @ Nullable Object instance ;
5049 private final Method func ;
5150 private final FunctionDeclaration funcDeclaration ;
5251 private final boolean requireConfirmation ;
52+ private final ObjectMapper objectMapper ;
5353
5454 public static FunctionTool create (Object instance , Method func ) {
5555 return create (instance , func , /* requireConfirmation= */ false );
@@ -166,11 +166,26 @@ private static boolean wasCompiledWithDefaultParameterNames(Method func) {
166166 }
167167
168168 protected FunctionTool (@ Nullable Object instance , Method func , boolean isLongRunning ) {
169- this (instance , func , isLongRunning , /* requireConfirmation= */ false );
169+ this (
170+ instance , func , isLongRunning , /* requireConfirmation= */ false , JsonBaseModel .getMapper ());
170171 }
171172
172173 protected FunctionTool (
173174 @ Nullable Object instance , Method func , boolean isLongRunning , boolean requireConfirmation ) {
175+ this (instance , func , isLongRunning , requireConfirmation , JsonBaseModel .getMapper ());
176+ }
177+
178+ protected FunctionTool (
179+ @ Nullable Object instance , Method func , boolean isLongRunning , ObjectMapper objectMapper ) {
180+ this (instance , func , isLongRunning , /* requireConfirmation= */ false , objectMapper );
181+ }
182+
183+ protected FunctionTool (
184+ @ Nullable Object instance ,
185+ Method func ,
186+ boolean isLongRunning ,
187+ boolean requireConfirmation ,
188+ ObjectMapper objectMapper ) {
174189 super (
175190 func .isAnnotationPresent (Annotations .Schema .class )
176191 && !func .getAnnotation (Annotations .Schema .class ).name ().isEmpty ()
@@ -193,6 +208,7 @@ protected FunctionTool(
193208 FunctionCallingUtils .buildFunctionDeclaration (
194209 this .func , ImmutableList .of ("toolContext" , "inputStream" ));
195210 this .requireConfirmation = requireConfirmation ;
211+ this .objectMapper = objectMapper ;
196212 }
197213
198214 @ Override
@@ -365,7 +381,7 @@ private static Class<?> getTypeClass(Type type, String paramName) {
365381 }
366382 }
367383
368- private static List <Object > createList (List <Object > values , Class <?> type ) {
384+ private List <Object > createList (List <Object > values , Class <?> type ) {
369385 List <Object > list = new ArrayList <>();
370386 // List of parameterized type is not supported.
371387 if (type == null ) {
@@ -387,7 +403,7 @@ private static List<Object> createList(List<Object> values, Class<?> type) {
387403 return list ;
388404 }
389405
390- private static Object castValue (Object value , Class <?> type ) {
406+ private Object castValue (Object value , Class <?> type ) {
391407 if (type .equals (Integer .class ) || type .equals (int .class )) {
392408 if (value instanceof Integer ) {
393409 return value ;
0 commit comments