Skip to content

Commit 9bd2bd6

Browse files
google-genai-botcopybara-github
authored andcommitted
feat: Allow LongRunningFunctionTool to be created with an instance
PiperOrigin-RevId: 784644549
1 parent 5ab8b14 commit 9bd2bd6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

core/src/main/java/com/google/adk/tools/LongRunningFunctionTool.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,22 @@ public static LongRunningFunctionTool create(Class<?> cls, String methodName) {
3535
String.format("Method %s not found in class %s.", methodName, cls.getName()));
3636
}
3737

38+
public static LongRunningFunctionTool create(Object instance, String methodName) {
39+
Class<?> cls = instance.getClass();
40+
for (Method method : cls.getMethods()) {
41+
if (method.getName().equals(methodName)) {
42+
return new LongRunningFunctionTool(instance, method);
43+
}
44+
}
45+
throw new IllegalArgumentException(
46+
String.format("Method %s not found in class %s.", methodName, cls.getName()));
47+
}
48+
3849
private LongRunningFunctionTool(Method func) {
3950
super(null, func, /* isLongRunning= */ true);
4051
}
52+
53+
private LongRunningFunctionTool(Object instance, Method func) {
54+
super(instance, func, /* isLongRunning= */ true);
55+
}
4156
}

0 commit comments

Comments
 (0)