Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions core/src/main/java/com/google/adk/tools/FunctionTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,18 @@ public class FunctionTool extends BaseTool {
new ObjectMapper().registerModule(new Jdk8Module());
private static final Logger logger = LoggerFactory.getLogger(FunctionTool.class);

@Nullable private final Object instance;
private final @Nullable Object instance;
private final Method func;
private final FunctionDeclaration funcDeclaration;

public static FunctionTool create(Object instance, Method func) {
if (!areParametersAnnotatedWithSchema(func) && wasCompiledWithDefaultParameterNames(func)) {
logger.error(
"Functions used in tools must have their parameters annotated with @Schema or at least"
+ " the code must be compiled with the -parameters flag as a fallback. Your function"
+ " tool will likely not work as expected and exit at runtime.");
"""
Functions used in tools must have their parameters annotated with @Schema or at least
the code must be compiled with the -parameters flag as a fallback. Your function
tool will likely not work as expected and exit at runtime.
""");
}
if (!Modifier.isStatic(func.getModifiers()) && !func.getDeclaringClass().isInstance(instance)) {
throw new IllegalArgumentException(
Expand All @@ -70,9 +72,11 @@ public static FunctionTool create(Object instance, Method func) {
public static FunctionTool create(Method func) {
if (!areParametersAnnotatedWithSchema(func) && wasCompiledWithDefaultParameterNames(func)) {
logger.error(
"Functions used in tools must have their parameters annotated with @Schema or at least"
+ " the code must be compiled with the -parameters flag as a fallback. Your function"
+ " tool will likely not work as expected and exit at runtime.");
"""
Functions used in tools must have their parameters annotated with @Schema or at least
the code must be compiled with the -parameters flag as a fallback. Your function
tool will likely not work as expected and exit at runtime.
""");
}
if (!Modifier.isStatic(func.getModifiers())) {
throw new IllegalArgumentException("The method provided must be static.");
Expand Down Expand Up @@ -189,11 +193,11 @@ private Maybe<Map<String, Object>> call(Map<String, Object> args, ToolContext to
&& !parameters[i].getAnnotation(Annotations.Schema.class).name().isEmpty()
? parameters[i].getAnnotation(Annotations.Schema.class).name()
: parameters[i].getName();
if (paramName.equals("toolContext")) {
if ("toolContext".equals(paramName)) {
arguments[i] = toolContext;
continue;
}
if (paramName.equals("inputStream")) {
if ("inputStream".equals(paramName)) {
arguments[i] = null;
continue;
}
Expand Down Expand Up @@ -261,11 +265,11 @@ public Flowable<Map<String, Object>> callLive(
&& !parameters[i].getAnnotation(Annotations.Schema.class).name().isEmpty()
? parameters[i].getAnnotation(Annotations.Schema.class).name()
: parameters[i].getName();
if (paramName.equals("toolContext")) {
if ("toolContext".equals(paramName)) {
arguments[i] = toolContext;
continue;
}
if (paramName.equals("inputStream")) {
if ("inputStream".equals(paramName)) {
if (invocationContext.activeStreamingTools().containsKey(this.name())
&& invocationContext.activeStreamingTools().get(this.name()).stream() != null) {
arguments[i] = invocationContext.activeStreamingTools().get(this.name()).stream();
Expand Down