Skip to content
Merged
Show file tree
Hide file tree
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
15 changes: 8 additions & 7 deletions core/src/main/java/com/google/adk/agents/LlmAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import com.google.adk.models.Model;
import com.google.adk.tools.BaseTool;
import com.google.adk.tools.BaseToolset;
import com.google.adk.tools.ToolMarker;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
Expand Down Expand Up @@ -84,7 +85,7 @@ public enum IncludeContents {
private final Optional<Model> model;
private final Instruction instruction;
private final Instruction globalInstruction;
private final List<Object> toolsUnion;
private final List<ToolMarker> toolsUnion;
private final ImmutableList<BaseToolset> toolsets;
private final Optional<GenerateContentConfig> generateContentConfig;
// TODO: Remove exampleProvider field - examples should only be provided via ExampleTool
Expand Down Expand Up @@ -152,7 +153,7 @@ public static Builder builder() {
}

/** Extracts BaseToolset instances from the toolsUnion list. */
private static ImmutableList<BaseToolset> extractToolsets(List<Object> toolsUnion) {
private static ImmutableList<BaseToolset> extractToolsets(List<ToolMarker> toolsUnion) {
return toolsUnion.stream()
.filter(obj -> obj instanceof BaseToolset)
.map(obj -> (BaseToolset) obj)
Expand All @@ -165,7 +166,7 @@ public static class Builder extends BaseAgent.Builder<Builder> {

private Instruction instruction;
private Instruction globalInstruction;
private ImmutableList<Object> toolsUnion;
private ImmutableList<ToolMarker> toolsUnion;
private GenerateContentConfig generateContentConfig;
private BaseExampleProvider exampleProvider;
private IncludeContents includeContents;
Expand Down Expand Up @@ -221,13 +222,13 @@ public Builder globalInstruction(String globalInstruction) {
}

@CanIgnoreReturnValue
public Builder tools(List<?> tools) {
public Builder tools(List<? extends ToolMarker> tools) {
this.toolsUnion = ImmutableList.copyOf(tools);
return this;
}

@CanIgnoreReturnValue
public Builder tools(Object... tools) {
public Builder tools(ToolMarker... tools) {
this.toolsUnion = ImmutableList.copyOf(tools);
return this;
}
Expand Down Expand Up @@ -679,7 +680,7 @@ public Single<Map.Entry<String, Boolean>> canonicalGlobalInstruction(ReadonlyCon
*/
public Flowable<BaseTool> canonicalTools(Optional<ReadonlyContext> context) {
List<Flowable<BaseTool>> toolFlowables = new ArrayList<>();
for (Object toolOrToolset : toolsUnion) {
for (ToolMarker toolOrToolset : toolsUnion) {
if (toolOrToolset instanceof BaseTool baseTool) {
toolFlowables.add(Flowable.just(baseTool));
} else if (toolOrToolset instanceof BaseToolset baseToolset) {
Expand Down Expand Up @@ -740,7 +741,7 @@ public Single<List<BaseTool>> tools() {
return canonicalTools().toList();
}

public List<Object> toolsUnion() {
public List<ToolMarker> toolsUnion() {
return toolsUnion;
}

Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/com/google/adk/agents/ToolResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.adk.tools.BaseTool.ToolArgsConfig;
import com.google.adk.tools.BaseTool.ToolConfig;
import com.google.adk.tools.BaseToolset;
import com.google.adk.tools.ToolMarker;
import com.google.adk.utils.ComponentRegistry;
import com.google.common.collect.ImmutableList;
import java.lang.reflect.Constructor;
Expand Down Expand Up @@ -56,14 +57,14 @@ private ToolResolver() {}
* @throws ConfigurationException if any tool configuration is invalid (e.g., missing name), if a
* tool cannot be found by its name or class, or if tool instantiation fails.
*/
static ImmutableList<Object> resolveToolsAndToolsets(
static ImmutableList<ToolMarker> resolveToolsAndToolsets(
List<ToolConfig> toolConfigs, String configAbsPath) throws ConfigurationException {

if (toolConfigs == null || toolConfigs.isEmpty()) {
return ImmutableList.of();
}

ImmutableList.Builder<Object> resolvedItems = ImmutableList.builder();
ImmutableList.Builder<ToolMarker> resolvedItems = ImmutableList.builder();

for (ToolConfig toolConfig : toolConfigs) {
try {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/com/google/adk/tools/BaseTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.slf4j.LoggerFactory;

/** The base class for all ADK tools. */
public abstract class BaseTool {
public abstract class BaseTool implements ToolMarker {
private final String name;
private final String description;
private final boolean isLongRunning;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/com/google/adk/tools/BaseToolset.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.Optional;

/** Base interface for toolsets. */
public interface BaseToolset extends AutoCloseable {
public interface BaseToolset extends AutoCloseable, ToolMarker {

/**
* Return all tools in the toolset based on the provided context.
Expand Down
19 changes: 19 additions & 0 deletions core/src/main/java/com/google/adk/tools/ToolMarker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.adk.tools;

/** Marker interface for BaseTool and BaseToolset. */
public interface ToolMarker {}