Skip to content

Commit dace210

Browse files
google-genai-botcopybara-github
authored andcommitted
fix: populate finishReason in LlmResponse
PiperOrigin-RevId: 853628038
1 parent e7380f1 commit dace210

File tree

6 files changed

+12
-32
lines changed

6 files changed

+12
-32
lines changed

core/src/main/java/com/google/adk/agents/LlmAgent.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import com.google.adk.models.Model;
4949
import com.google.adk.tools.BaseTool;
5050
import com.google.adk.tools.BaseToolset;
51-
import com.google.adk.tools.ToolMarker;
5251
import com.google.common.base.Preconditions;
5352
import com.google.common.collect.ImmutableList;
5453
import com.google.errorprone.annotations.CanIgnoreReturnValue;
@@ -85,7 +84,7 @@ public enum IncludeContents {
8584
private final Optional<Model> model;
8685
private final Instruction instruction;
8786
private final Instruction globalInstruction;
88-
private final List<ToolMarker> toolsUnion;
87+
private final List<Object> toolsUnion;
8988
private final ImmutableList<BaseToolset> toolsets;
9089
private final Optional<GenerateContentConfig> generateContentConfig;
9190
// TODO: Remove exampleProvider field - examples should only be provided via ExampleTool
@@ -153,7 +152,7 @@ public static Builder builder() {
153152
}
154153

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

167166
private Instruction instruction;
168167
private Instruction globalInstruction;
169-
private ImmutableList<ToolMarker> toolsUnion;
168+
private ImmutableList<Object> toolsUnion;
170169
private GenerateContentConfig generateContentConfig;
171170
private BaseExampleProvider exampleProvider;
172171
private IncludeContents includeContents;
@@ -222,13 +221,13 @@ public Builder globalInstruction(String globalInstruction) {
222221
}
223222

224223
@CanIgnoreReturnValue
225-
public Builder tools(List<? extends ToolMarker> tools) {
224+
public Builder tools(List<?> tools) {
226225
this.toolsUnion = ImmutableList.copyOf(tools);
227226
return this;
228227
}
229228

230229
@CanIgnoreReturnValue
231-
public Builder tools(ToolMarker... tools) {
230+
public Builder tools(Object... tools) {
232231
this.toolsUnion = ImmutableList.copyOf(tools);
233232
return this;
234233
}
@@ -680,7 +679,7 @@ public Single<Map.Entry<String, Boolean>> canonicalGlobalInstruction(ReadonlyCon
680679
*/
681680
public Flowable<BaseTool> canonicalTools(Optional<ReadonlyContext> context) {
682681
List<Flowable<BaseTool>> toolFlowables = new ArrayList<>();
683-
for (ToolMarker toolOrToolset : toolsUnion) {
682+
for (Object toolOrToolset : toolsUnion) {
684683
if (toolOrToolset instanceof BaseTool baseTool) {
685684
toolFlowables.add(Flowable.just(baseTool));
686685
} else if (toolOrToolset instanceof BaseToolset baseToolset) {
@@ -741,7 +740,7 @@ public Single<List<BaseTool>> tools() {
741740
return canonicalTools().toList();
742741
}
743742

744-
public List<ToolMarker> toolsUnion() {
743+
public List<Object> toolsUnion() {
745744
return toolsUnion;
746745
}
747746

core/src/main/java/com/google/adk/agents/ToolResolver.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.google.adk.tools.BaseTool.ToolArgsConfig;
2424
import com.google.adk.tools.BaseTool.ToolConfig;
2525
import com.google.adk.tools.BaseToolset;
26-
import com.google.adk.tools.ToolMarker;
2726
import com.google.adk.utils.ComponentRegistry;
2827
import com.google.common.collect.ImmutableList;
2928
import java.lang.reflect.Constructor;
@@ -57,14 +56,14 @@ private ToolResolver() {}
5756
* @throws ConfigurationException if any tool configuration is invalid (e.g., missing name), if a
5857
* tool cannot be found by its name or class, or if tool instantiation fails.
5958
*/
60-
static ImmutableList<ToolMarker> resolveToolsAndToolsets(
59+
static ImmutableList<Object> resolveToolsAndToolsets(
6160
List<ToolConfig> toolConfigs, String configAbsPath) throws ConfigurationException {
6261

6362
if (toolConfigs == null || toolConfigs.isEmpty()) {
6463
return ImmutableList.of();
6564
}
6665

67-
ImmutableList.Builder<ToolMarker> resolvedItems = ImmutableList.builder();
66+
ImmutableList.Builder<Object> resolvedItems = ImmutableList.builder();
6867

6968
for (ToolConfig toolConfig : toolConfigs) {
7069
try {

core/src/main/java/com/google/adk/models/LlmResponse.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ public final Builder response(GenerateContentResponse response) {
180180
Optional<List<Candidate>> candidatesOpt = response.candidates();
181181
if (candidatesOpt.isPresent() && !candidatesOpt.get().isEmpty()) {
182182
Candidate candidate = candidatesOpt.get().get(0);
183+
this.finishReason(candidate.finishReason());
183184
if (candidate.content().isPresent()) {
184185
this.content(candidate.content().get());
185186
this.groundingMetadata(candidate.groundingMetadata());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import org.slf4j.LoggerFactory;
4545

4646
/** The base class for all ADK tools. */
47-
public abstract class BaseTool implements ToolMarker {
47+
public abstract class BaseTool {
4848
private final String name;
4949
private final String description;
5050
private final boolean isLongRunning;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.util.Optional;
77

88
/** Base interface for toolsets. */
9-
public interface BaseToolset extends AutoCloseable, ToolMarker {
9+
public interface BaseToolset extends AutoCloseable {
1010

1111
/**
1212
* Return all tools in the toolset based on the provided context.

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

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)