1616
1717package com .google .adk .agents ;
1818
19- import static com .google .common .collect .ImmutableList .toImmutableList ;
2019import static java .util .stream .Collectors .joining ;
2120
2221import com .fasterxml .jackson .core .JsonProcessingException ;
4847import com .google .adk .models .BaseLlm ;
4948import com .google .adk .models .Model ;
5049import com .google .adk .tools .BaseTool ;
51- import com .google .adk .tools .BaseToolset ;
5250import com .google .common .base .Preconditions ;
5351import com .google .common .collect .ImmutableList ;
5452import com .google .errorprone .annotations .CanIgnoreReturnValue ;
5856import io .reactivex .rxjava3 .core .Flowable ;
5957import io .reactivex .rxjava3 .core .Maybe ;
6058import io .reactivex .rxjava3 .core .Single ;
61- import java .util .ArrayList ;
6259import java .util .List ;
6360import java .util .Map ;
6461import java .util .Optional ;
@@ -84,7 +81,7 @@ public enum IncludeContents {
8481 private final Optional <Model > model ;
8582 private final Instruction instruction ;
8683 private final Instruction globalInstruction ;
87- private final List <Object > toolsUnion ;
84+ private final List <BaseTool > tools ;
8885 private final Optional <GenerateContentConfig > generateContentConfig ;
8986 private final Optional <BaseExampleProvider > exampleProvider ;
9087 private final IncludeContents includeContents ;
@@ -133,7 +130,7 @@ protected LlmAgent(Builder builder) {
133130 this .outputSchema = Optional .ofNullable (builder .outputSchema );
134131 this .executor = Optional .ofNullable (builder .executor );
135132 this .outputKey = Optional .ofNullable (builder .outputKey );
136- this .toolsUnion = builder .toolsUnion != null ? builder .toolsUnion : ImmutableList .of ();
133+ this .tools = builder .tools != null ? builder .tools : ImmutableList .of ();
137134
138135 this .llmFlow = determineLlmFlow ();
139136
@@ -156,7 +153,7 @@ public static class Builder {
156153 private Instruction instruction ;
157154 private Instruction globalInstruction ;
158155 private ImmutableList <BaseAgent > subAgents ;
159- private ImmutableList <Object > toolsUnion ;
156+ private ImmutableList <BaseTool > tools ;
160157 private GenerateContentConfig generateContentConfig ;
161158 private BaseExampleProvider exampleProvider ;
162159 private IncludeContents includeContents ;
@@ -237,14 +234,14 @@ public Builder subAgents(BaseAgent... subAgents) {
237234 }
238235
239236 @ CanIgnoreReturnValue
240- public Builder tools (List <?> tools ) {
241- this .toolsUnion = ImmutableList .copyOf (tools );
237+ public Builder tools (List <? extends BaseTool > tools ) {
238+ this .tools = ImmutableList .copyOf (tools );
242239 return this ;
243240 }
244241
245242 @ CanIgnoreReturnValue
246- public Builder tools (Object ... tools ) {
247- this .toolsUnion = ImmutableList .copyOf (tools );
243+ public Builder tools (BaseTool ... tools ) {
244+ this .tools = ImmutableList .copyOf (tools );
248245 return this ;
249246 }
250247
@@ -583,7 +580,7 @@ protected void validate() {
583580 + ": if outputSchema is set, subAgents must be empty to disable agent"
584581 + " transfer." );
585582 }
586- if (this .toolsUnion != null && !this .toolsUnion .isEmpty ()) {
583+ if (this .tools != null && !this .tools .isEmpty ()) {
587584 throw new IllegalArgumentException (
588585 "Invalid config for agent "
589586 + this .name
@@ -690,42 +687,6 @@ public Single<String> canonicalGlobalInstruction(ReadonlyContext context) {
690687 throw new IllegalStateException ("Unknown Instruction subtype: " + instruction .getClass ());
691688 }
692689
693- /**
694- * Constructs the list of tools for this agent based on the {@link #tools} field.
695- *
696- * <p>This method is only for use by Agent Development Kit.
697- *
698- * @param context The context to retrieve the session state.
699- * @return The resolved list of tools as a {@link Single} wrapped list of {@link BaseTool}.
700- */
701- public Single <List <BaseTool >> canonicalTools (Optional <ReadonlyContext > context ) {
702- List <Single <List <BaseTool >>> toolSingles = new ArrayList <>();
703- for (Object toolOrToolset : toolsUnion ) {
704- if (toolOrToolset instanceof BaseTool baseTool ) {
705- toolSingles .add (Single .just (ImmutableList .of (baseTool )));
706- } else if (toolOrToolset instanceof BaseToolset baseToolset ) {
707- toolSingles .add (baseToolset .getTools (context .orElse (null )));
708- } else {
709- throw new IllegalArgumentException (
710- "Object in tools list is not of a supported type: "
711- + toolOrToolset .getClass ().getName ());
712- }
713- }
714- return Single .concat (toolSingles )
715- .toList ()
716- .map (listOfLists -> listOfLists .stream ().flatMap (List ::stream ).collect (toImmutableList ()));
717- }
718-
719- /** Overload of canonicalTools that defaults to an empty context. */
720- public Single <List <BaseTool >> canonicalTools () {
721- return canonicalTools (Optional .empty ());
722- }
723-
724- /** Convenience overload of canonicalTools that accepts a non-optional ReadonlyContext. */
725- public Single <List <BaseTool >> canonicalTools (ReadonlyContext context ) {
726- return canonicalTools (Optional .ofNullable (context ));
727- }
728-
729690 public Instruction instruction () {
730691 return instruction ;
731692 }
@@ -758,8 +719,8 @@ public IncludeContents includeContents() {
758719 return includeContents ;
759720 }
760721
761- public List <Object > tools () {
762- return toolsUnion ;
722+ public List <BaseTool > tools () {
723+ return tools ;
763724 }
764725
765726 public boolean disallowTransferToParent () {
0 commit comments