Skip to content

Commit 7623186

Browse files
Merge pull request #485 from vorburger:issue-473_FunctionTool-clean
PiperOrigin-RevId: 821706270
2 parents 391e049 + a2295a3 commit 7623186

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,18 @@ public class FunctionTool extends BaseTool {
4646
private static final Logger logger = LoggerFactory.getLogger(FunctionTool.class);
4747
private static final ObjectMapper OBJECT_MAPPER = JsonBaseModel.getMapper();
4848

49-
@Nullable private final Object instance;
49+
private final @Nullable Object instance;
5050
private final Method func;
5151
private final FunctionDeclaration funcDeclaration;
5252

5353
public static FunctionTool create(Object instance, Method func) {
5454
if (!areParametersAnnotatedWithSchema(func) && wasCompiledWithDefaultParameterNames(func)) {
5555
logger.error(
56-
"Functions used in tools must have their parameters annotated with @Schema or at least"
57-
+ " the code must be compiled with the -parameters flag as a fallback. Your function"
58-
+ " tool will likely not work as expected and exit at runtime.");
56+
"""
57+
Functions used in tools must have their parameters annotated with @Schema or at least
58+
the code must be compiled with the -parameters flag as a fallback. Your function
59+
tool will likely not work as expected and exit at runtime.
60+
""");
5961
}
6062
if (!Modifier.isStatic(func.getModifiers()) && !func.getDeclaringClass().isInstance(instance)) {
6163
throw new IllegalArgumentException(
@@ -70,9 +72,11 @@ public static FunctionTool create(Object instance, Method func) {
7072
public static FunctionTool create(Method func) {
7173
if (!areParametersAnnotatedWithSchema(func) && wasCompiledWithDefaultParameterNames(func)) {
7274
logger.error(
73-
"Functions used in tools must have their parameters annotated with @Schema or at least"
74-
+ " the code must be compiled with the -parameters flag as a fallback. Your function"
75-
+ " tool will likely not work as expected and exit at runtime.");
75+
"""
76+
Functions used in tools must have their parameters annotated with @Schema or at least
77+
the code must be compiled with the -parameters flag as a fallback. Your function
78+
tool will likely not work as expected and exit at runtime.
79+
""");
7680
}
7781
if (!Modifier.isStatic(func.getModifiers())) {
7882
throw new IllegalArgumentException("The method provided must be static.");
@@ -189,11 +193,11 @@ private Maybe<Map<String, Object>> call(Map<String, Object> args, ToolContext to
189193
&& !parameters[i].getAnnotation(Annotations.Schema.class).name().isEmpty()
190194
? parameters[i].getAnnotation(Annotations.Schema.class).name()
191195
: parameters[i].getName();
192-
if (paramName.equals("toolContext")) {
196+
if ("toolContext".equals(paramName)) {
193197
arguments[i] = toolContext;
194198
continue;
195199
}
196-
if (paramName.equals("inputStream")) {
200+
if ("inputStream".equals(paramName)) {
197201
arguments[i] = null;
198202
continue;
199203
}
@@ -261,11 +265,11 @@ public Flowable<Map<String, Object>> callLive(
261265
&& !parameters[i].getAnnotation(Annotations.Schema.class).name().isEmpty()
262266
? parameters[i].getAnnotation(Annotations.Schema.class).name()
263267
: parameters[i].getName();
264-
if (paramName.equals("toolContext")) {
268+
if ("toolContext".equals(paramName)) {
265269
arguments[i] = toolContext;
266270
continue;
267271
}
268-
if (paramName.equals("inputStream")) {
272+
if ("inputStream".equals(paramName)) {
269273
if (invocationContext.activeStreamingTools().containsKey(this.name())
270274
&& invocationContext.activeStreamingTools().get(this.name()).stream() != null) {
271275
arguments[i] = invocationContext.activeStreamingTools().get(this.name()).stream();

0 commit comments

Comments
 (0)