Skip to content
Open
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
23 changes: 10 additions & 13 deletions core/src/main/java/com/google/adk/agents/LlmAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -758,18 +758,25 @@ public Single<Map.Entry<String, Boolean>> canonicalGlobalInstruction(ReadonlyCon
/**
* Constructs the list of tools for this agent based on the {@link #tools} field.
*
* <p>This method is only for use by Agent Development Kit.
* @return The resolved list of tools as a {@link Single} wrapped list of {@link BaseTool}.
*/
public Flowable<BaseTool> canonicalTools() {
return canonicalTools(null);
}

/**
* Constructs the list of tools for this agent based on the {@link #tools} field.
*
* @param context The context to retrieve the session state.
* @return The resolved list of tools as a {@link Single} wrapped list of {@link BaseTool}.
*/
public Flowable<BaseTool> canonicalTools(Optional<ReadonlyContext> context) {
public Flowable<BaseTool> canonicalTools(@Nullable ReadonlyContext context) {
List<Flowable<BaseTool>> toolFlowables = new ArrayList<>();
for (Object toolOrToolset : toolsUnion) {
if (toolOrToolset instanceof BaseTool baseTool) {
toolFlowables.add(Flowable.just(baseTool));
} else if (toolOrToolset instanceof BaseToolset baseToolset) {
toolFlowables.add(baseToolset.getTools(context.orElse(null)));
toolFlowables.add(baseToolset.getTools(context));
} else {
throw new IllegalArgumentException(
"Object in tools list is not of a supported type: "
Expand All @@ -779,16 +786,6 @@ public Flowable<BaseTool> canonicalTools(Optional<ReadonlyContext> context) {
return Flowable.concat(toolFlowables);
}

/** Overload of canonicalTools that defaults to an empty context. */
public Flowable<BaseTool> canonicalTools() {
return canonicalTools(Optional.empty());
}

/** Convenience overload of canonicalTools that accepts a non-optional ReadonlyContext. */
public Flowable<BaseTool> canonicalTools(ReadonlyContext context) {
return canonicalTools(Optional.ofNullable(context));
}

public Instruction instruction() {
return instruction;
}
Expand Down