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
7 changes: 6 additions & 1 deletion core/src/main/java/com/google/adk/events/EventStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
import java.util.NoSuchElementException;
import java.util.function.Supplier;

/** Iterable stream of {@link Event} objects. */
/**
* Iterable stream of {@link Event} objects.
*
* <p>NOTE: This class is not thread-safe. Concurrent iteration from multiple threads should be
* avoided or externally synchronized.
*/
public class EventStream implements Iterable<Event> {

private final Supplier<Event> eventSupplier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public abstract static class Builder {

/** For internal usage. Please use `ToolConfirmation.builder()` for instantiation. */
@JsonCreator
private static Builder create() {
static Builder create() {
return new AutoValue_ToolConfirmation.Builder();
}

Expand Down
8 changes: 7 additions & 1 deletion core/src/main/java/com/google/adk/examples/ExampleUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,22 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.adk.JsonBaseModel;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.genai.types.Content;
import com.google.genai.types.FunctionCall;
import com.google.genai.types.FunctionResponse;
import com.google.genai.types.Part;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** Utility class for examples. */
public final class ExampleUtils {

private static final Logger logger = LoggerFactory.getLogger(ExampleUtils.class);

// Constant parts of the example string
private static final String EXAMPLES_INTRO =
"<EXAMPLES>\nBegin few-shot\nThe following are examples of user queries and"
Expand All @@ -50,7 +55,7 @@ public final class ExampleUtils {
private static final String FUNCTION_RESPONSE_PREFIX = "```tool_outputs\n";
private static final String FUNCTION_RESPONSE_SUFFIX = "\n```\n";

private static final ObjectMapper objectMapper = new ObjectMapper();
private static final ObjectMapper objectMapper = JsonBaseModel.getMapper();

/**
* Converts a list of examples into a formatted few-shot prompt string.
Expand Down Expand Up @@ -143,6 +148,7 @@ private static void appendFunctionResponse(FunctionResponse response, StringBuil
.append(objectMapper.writeValueAsString(responseMap))
.append(FUNCTION_RESPONSE_SUFFIX);
} catch (JsonProcessingException e) {
logger.error("Failed to serialize function response", e);
builder.append(FUNCTION_RESPONSE_PREFIX).append(FUNCTION_RESPONSE_SUFFIX);
}
}
Expand Down
16 changes: 16 additions & 0 deletions core/src/main/java/com/google/adk/tools/BaseToolset.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2026 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;

import com.google.adk.agents.ReadonlyContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* execution.
*/
public final class BuiltInCodeExecutionTool extends BaseTool {
public static final BuiltInCodeExecutionTool INSTANCE = new BuiltInCodeExecutionTool();

public BuiltInCodeExecutionTool() {
super("code_execution", "code_execution");
Expand Down
16 changes: 16 additions & 0 deletions core/src/main/java/com/google/adk/tools/GoogleMapsTool.java
Original file line number Diff line number Diff line change
@@ -1,3 +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;

import com.google.adk.models.LlmRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import com.google.genai.types.Tool;
import io.reactivex.rxjava3.core.Completable;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A built-in tool that is automatically invoked by Gemini 2 models to retrieve search results from
Expand All @@ -41,6 +43,7 @@
* }</pre>
*/
public final class GoogleSearchTool extends BaseTool {
private static final Logger logger = LoggerFactory.getLogger(GoogleSearchTool.class);
public static final GoogleSearchTool INSTANCE = new GoogleSearchTool();

public GoogleSearchTool() {
Expand All @@ -65,7 +68,7 @@ public Completable processLlmRequest(
String model = llmRequestBuilder.build().model().get();
if (model != null && model.startsWith("gemini-1")) {
if (!updatedToolsBuilder.build().isEmpty()) {
System.out.println(configBuilder.build().tools().get());
logger.error("Tools already present: {}", configBuilder.build().tools().get());
return Completable.error(
new IllegalArgumentException(
"Google search tool cannot be used with other tools in Gemini 1.x."));
Expand Down
16 changes: 16 additions & 0 deletions core/src/main/java/com/google/adk/tools/LoadMemoryTool.java
Original file line number Diff line number Diff line change
@@ -1,3 +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;

import com.google.adk.models.LlmRequest;
Expand Down
16 changes: 16 additions & 0 deletions core/src/main/java/com/google/adk/tools/NamedToolPredicate.java
Original file line number Diff line number Diff line change
@@ -1,3 +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;

import com.google.adk.agents.ReadonlyContext;
Expand Down
16 changes: 16 additions & 0 deletions core/src/main/java/com/google/adk/tools/ToolPredicate.java
Original file line number Diff line number Diff line change
@@ -1,3 +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;

import com.google.adk.agents.ReadonlyContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +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.applicationintegrationtoolset;

import static com.google.common.base.Strings.isNullOrEmpty;
Expand Down Expand Up @@ -26,10 +42,14 @@
import java.util.Map;
import java.util.Optional;
import org.jspecify.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** Application Integration Tool */
public class IntegrationConnectorTool extends BaseTool {

private static final Logger logger = LoggerFactory.getLogger(IntegrationConnectorTool.class);

private final String openApiSpec;
private final String pathUrl;
private final String connectionName;
Expand Down Expand Up @@ -129,7 +149,7 @@ public Optional<FunctionDeclaration> declaration() {
.build();
return Optional.of(declaration);
} catch (Exception e) {
System.err.println("Failed to get OpenAPI spec: " + e.getMessage());
logger.error("Failed to get OpenAPI spec", e);
return Optional.empty();
}
}
Expand All @@ -156,7 +176,7 @@ public Single<Map<String, Object>> runAsync(Map<String, Object> args, ToolContex
String response = executeIntegration(args);
return ImmutableMap.of("result", response);
} catch (Exception e) {
System.err.println("Failed to execute integration: " + e.getMessage());
logger.error("Failed to execute integration", e);
return ImmutableMap.of("error", e.getMessage());
}
});
Expand Down
18 changes: 17 additions & 1 deletion core/src/main/java/com/google/adk/utils/ModelNameUtils.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
/*
* 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.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ModelNameUtils {
public final class ModelNameUtils {
private static final Pattern GEMINI_2_PATTERN = Pattern.compile("^gemini-2\\..*");
private static final Pattern PATH_PATTERN =
Pattern.compile("^projects/[^/]+/locations/[^/]+/publishers/[^/]+/models/(.+)$");
Expand Down