Skip to content

Commit 0b63ca3

Browse files
google-genai-botcopybara-github
authored andcommitted
feat: Fix a handful of small changes related to headers, logging and javadoc
1. **License Headers**: Adds the Apache License 2.0 header to several Java files (`BaseToolset.java`, `GoogleMapsTool.java`, `LoadMemoryTool.java`, `NamedToolPredicate.java`, `ToolPredicate.java`, `IntegrationConnectorTool.java`, and `ModelNameUtils.java`). 2. **Logging**: Replaces `System.out.println` and `System.err.println` with `slf4j` logger calls (`logger.error`) in `ExampleUtils.java`, `GoogleSearchTool.java`, and `IntegrationConnectorTool.java` for better error handling and logging practices. 3. **JSON Handling**: In `ExampleUtils.java`, switches from a dedicated `ObjectMapper` instance to using `JsonBaseModel.getMapper()` for JSON serialization. 4. **Thread Safety Doc**: Adds a note to the javadoc for `EventStream.java` indicating that the class is not thread-safe. 5. **`ToolConfirmation.java`**: Makes the `create()` method package-private. 6. **`BuiltInCodeExecutionTool.java`**: Adds a public static `INSTANCE` field for easy access. 7. **`ModelNameUtils.java`**: Makes the class `final`. PiperOrigin-RevId: 861745391
1 parent c6c52c4 commit 0b63ca3

12 files changed

Lines changed: 138 additions & 7 deletions

File tree

core/src/main/java/com/google/adk/events/EventStream.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020
import java.util.NoSuchElementException;
2121
import java.util.function.Supplier;
2222

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

2631
private final Supplier<Event> eventSupplier;

core/src/main/java/com/google/adk/events/ToolConfirmation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public abstract static class Builder {
6262

6363
/** For internal usage. Please use `ToolConfirmation.builder()` for instantiation. */
6464
@JsonCreator
65-
private static Builder create() {
65+
static Builder create() {
6666
return new AutoValue_ToolConfirmation.Builder();
6767
}
6868

core/src/main/java/com/google/adk/examples/ExampleUtils.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,22 @@
2020

2121
import com.fasterxml.jackson.core.JsonProcessingException;
2222
import com.fasterxml.jackson.databind.ObjectMapper;
23+
import com.google.adk.JsonBaseModel;
2324
import com.google.common.collect.ImmutableList;
2425
import com.google.common.collect.ImmutableMap;
2526
import com.google.genai.types.Content;
2627
import com.google.genai.types.FunctionCall;
2728
import com.google.genai.types.FunctionResponse;
2829
import com.google.genai.types.Part;
2930
import java.util.List;
31+
import org.slf4j.Logger;
32+
import org.slf4j.LoggerFactory;
3033

3134
/** Utility class for examples. */
3235
public final class ExampleUtils {
3336

37+
private static final Logger logger = LoggerFactory.getLogger(ExampleUtils.class);
38+
3439
// Constant parts of the example string
3540
private static final String EXAMPLES_INTRO =
3641
"<EXAMPLES>\nBegin few-shot\nThe following are examples of user queries and"
@@ -50,7 +55,7 @@ public final class ExampleUtils {
5055
private static final String FUNCTION_RESPONSE_PREFIX = "```tool_outputs\n";
5156
private static final String FUNCTION_RESPONSE_SUFFIX = "\n```\n";
5257

53-
private static final ObjectMapper objectMapper = new ObjectMapper();
58+
private static final ObjectMapper objectMapper = JsonBaseModel.getMapper();
5459

5560
/**
5661
* Converts a list of examples into a formatted few-shot prompt string.
@@ -143,6 +148,7 @@ private static void appendFunctionResponse(FunctionResponse response, StringBuil
143148
.append(objectMapper.writeValueAsString(responseMap))
144149
.append(FUNCTION_RESPONSE_SUFFIX);
145150
} catch (JsonProcessingException e) {
151+
logger.error("Failed to serialize function response", e);
146152
builder.append(FUNCTION_RESPONSE_PREFIX).append(FUNCTION_RESPONSE_SUFFIX);
147153
}
148154
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2026 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.google.adk.tools;
218

319
import com.google.adk.agents.ReadonlyContext;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
* execution.
3232
*/
3333
public final class BuiltInCodeExecutionTool extends BaseTool {
34+
public static final BuiltInCodeExecutionTool INSTANCE = new BuiltInCodeExecutionTool();
3435

3536
public BuiltInCodeExecutionTool() {
3637
super("code_execution", "code_execution");

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.google.adk.tools;
218

319
import com.google.adk.models.LlmRequest;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import com.google.genai.types.Tool;
2525
import io.reactivex.rxjava3.core.Completable;
2626
import java.util.List;
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
2729

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

4649
public GoogleSearchTool() {
@@ -65,7 +68,7 @@ public Completable processLlmRequest(
6568
String model = llmRequestBuilder.build().model().get();
6669
if (model != null && model.startsWith("gemini-1")) {
6770
if (!updatedToolsBuilder.build().isEmpty()) {
68-
System.out.println(configBuilder.build().tools().get());
71+
logger.error("Tools already present: {}", configBuilder.build().tools().get());
6972
return Completable.error(
7073
new IllegalArgumentException(
7174
"Google search tool cannot be used with other tools in Gemini 1.x."));

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.google.adk.tools;
218

319
import com.google.adk.models.LlmRequest;

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.google.adk.tools;
218

319
import com.google.adk.agents.ReadonlyContext;

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.google.adk.tools;
218

319
import com.google.adk.agents.ReadonlyContext;

0 commit comments

Comments
 (0)