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
20 changes: 18 additions & 2 deletions core/src/main/java/com/google/adk/tools/BaseTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ public abstract class BaseTool {
private final String description;
private final boolean isLongRunning;

protected BaseTool() {
this(/* name= */ null, /* description= */ null, /* isLongRunning= */ false);
}

protected BaseTool(boolean isLongRunning) {
this(/* name= */ null, /* description= */ null, isLongRunning);
}

protected BaseTool(@Nonnull String name, @Nonnull String description) {
this(name, description, /* isLongRunning= */ false);
}
Expand All @@ -48,11 +56,19 @@ protected BaseTool(@Nonnull String name, @Nonnull String description, boolean is
}

public String name() {
return name;
return name != null
? name
: declaration()
.flatMap(FunctionDeclaration::name)
.orElseThrow(() -> new IllegalStateException("Tool name is not set."));
}

public String description() {
return description;
return description != null
? description
: declaration()
.flatMap(FunctionDeclaration::description)
.orElseThrow(() -> new IllegalStateException("Tool description is not set."));
}

public boolean longRunning() {
Expand Down