Skip to content
Open
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
13 changes: 11 additions & 2 deletions core/src/main/java/com/google/adk/tools/GoogleSearchTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public Completable processLlmRequest(
ImmutableList.Builder<Tool> updatedToolsBuilder = ImmutableList.builder();
updatedToolsBuilder.addAll(existingTools);

String model = llmRequestBuilder.build().model().get();
if (model != null && (model.startsWith("gemini-2") || model.startsWith("gemini-3"))) {
String model = llmRequestBuilder.build().model().orElse(null);
if (isSupportedModel(model)) {

updatedToolsBuilder.add(Tool.builder().googleSearch(GoogleSearch.builder().build()).build());
configBuilder.tools(updatedToolsBuilder.build());
Expand All @@ -74,4 +74,13 @@ public Completable processLlmRequest(
llmRequestBuilder.config(configBuilder.build());
return Completable.complete();
}

private boolean isSupportedModel(String model) {
if (model == null) {
return false;
}
return model.startsWith("gemini-2")
|| model.startsWith("gemini-3")
|| model.endsWith("-latest");
}
}
27 changes: 27 additions & 0 deletions core/src/test/java/com/google/adk/tools/BaseToolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,33 @@ public void processLlmRequestWithGoogleSearchToolAddsToolToConfig() {
Tool.builder().googleSearch(GoogleSearch.builder().build()).build());
}

@Test
public void processLlmRequestWithLatestAliasAddsToolToConfig() {
final GoogleSearchTool googleSearchTool = new GoogleSearchTool();
LlmRequest.Builder builder =
LlmRequest.builder().model("gemini-flash-latest").build().toBuilder();
Completable result = googleSearchTool.processLlmRequest(builder, null);
result.test().assertComplete();
assertThat(builder.build().config().get().tools().get())
.contains(Tool.builder().googleSearch(GoogleSearch.builder().build()).build());
}

@Test
public void processLlmRequestWithUnsupportedModelReturnsError() {
final GoogleSearchTool googleSearchTool = new GoogleSearchTool();
LlmRequest.Builder builder = LlmRequest.builder().model("text-bison-001").build().toBuilder();
Completable result = googleSearchTool.processLlmRequest(builder, null);
result.test().assertError(IllegalArgumentException.class);
}

@Test
public void processLlmRequest_WithNullModel_ReturnsError() {
final GoogleSearchTool googleSearchTool = new GoogleSearchTool();
LlmRequest.Builder builder = LlmRequest.builder().build().toBuilder();
Completable result = googleSearchTool.processLlmRequest(builder, null);
result.test().assertError(IllegalArgumentException.class);
}

@Test
public void processLlmRequestWithUrlContextToolAddsToolToConfig() {
FunctionDeclaration functionDeclaration =
Expand Down