Skip to content
Open
Show file tree
Hide file tree
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
53 changes: 18 additions & 35 deletions core/src/main/java/com/google/adk/agents/LlmAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
import com.google.adk.agents.ConfigAgentUtils.ConfigurationException;
import com.google.adk.codeexecutors.BaseCodeExecutor;
import com.google.adk.events.Event;
import com.google.adk.examples.BaseExampleProvider;
import com.google.adk.examples.Example;
import com.google.adk.flows.llmflows.AutoFlow;
import com.google.adk.flows.llmflows.BaseLlmFlow;
import com.google.adk.flows.llmflows.SingleFlow;
Expand Down Expand Up @@ -97,8 +95,6 @@ public enum IncludeContents {
private final List<Object> toolsUnion;
private final ImmutableList<BaseToolset> toolsets;
private final Optional<GenerateContentConfig> generateContentConfig;
// TODO: Remove exampleProvider field - examples should only be provided via ExampleTool
private final Optional<BaseExampleProvider> exampleProvider;
private final IncludeContents includeContents;

private final boolean planning;
Expand Down Expand Up @@ -132,7 +128,6 @@ protected LlmAgent(Builder builder) {
this.globalInstruction =
requireNonNullElse(builder.globalInstruction, new Instruction.Static(""));
this.generateContentConfig = Optional.ofNullable(builder.generateContentConfig);
this.exampleProvider = Optional.ofNullable(builder.exampleProvider);
this.includeContents = requireNonNullElse(builder.includeContents, IncludeContents.DEFAULT);
this.planning = builder.planning != null && builder.planning;
this.maxSteps = Optional.ofNullable(builder.maxSteps);
Expand Down Expand Up @@ -180,7 +175,6 @@ public static class Builder extends BaseAgent.Builder<Builder> {
private Instruction globalInstruction;
private ImmutableList<Object> toolsUnion;
private GenerateContentConfig generateContentConfig;
private BaseExampleProvider exampleProvider;
private IncludeContents includeContents;
private Boolean planning;
private Integer maxSteps;
Expand Down Expand Up @@ -253,26 +247,6 @@ public Builder generateContentConfig(GenerateContentConfig generateContentConfig
return this;
}

// TODO: Remove these example provider methods and only use ExampleTool for providing examples.
// Direct example methods should be deprecated in favor of using ExampleTool consistently.
@CanIgnoreReturnValue
public Builder exampleProvider(BaseExampleProvider exampleProvider) {
this.exampleProvider = exampleProvider;
return this;
}

@CanIgnoreReturnValue
public Builder exampleProvider(List<Example> examples) {
this.exampleProvider = (unused) -> examples;
return this;
}

@CanIgnoreReturnValue
public Builder exampleProvider(Example... examples) {
this.exampleProvider = (unused) -> ImmutableList.copyOf(examples);
return this;
}

@CanIgnoreReturnValue
public Builder includeContents(IncludeContents includeContents) {
this.includeContents = includeContents;
Expand Down Expand Up @@ -640,10 +614,24 @@ protected void validate() {
+ " transfer.");
}
if (this.toolsUnion != null && !this.toolsUnion.isEmpty()) {
throw new IllegalArgumentException(
"Invalid config for agent "
+ this.name
+ ": if outputSchema is set, tools must be empty.");
boolean hasOtherTools =
this.toolsUnion.stream()
.anyMatch(
tool -> {
if (tool instanceof BaseToolset) {
return true;
}
if (tool instanceof BaseTool) {
return !((BaseTool) tool).name().equals("example_tool");
}
return true;
});
if (hasOtherTools) {
throw new IllegalArgumentException(
"Invalid config for agent "
+ this.name
+ ": if outputSchema is set, tools must be empty.");
}
}
}
}
Expand Down Expand Up @@ -812,11 +800,6 @@ public Optional<GenerateContentConfig> generateContentConfig() {
return generateContentConfig;
}

// TODO: Remove this getter - examples should only be provided via ExampleTool
public Optional<BaseExampleProvider> exampleProvider() {
return exampleProvider;
}

public IncludeContents includeContents() {
return includeContents;
}
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/com/google/adk/examples/ExampleUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public final class ExampleUtils {
* @return string representation of the examples block.
*/
private static String convertExamplesToText(List<Example> examples) {
if (examples.isEmpty()) {
return "";
}
StringBuilder examplesStr = new StringBuilder();

// super header
Expand Down
57 changes: 0 additions & 57 deletions core/src/main/java/com/google/adk/flows/llmflows/Examples.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class SingleFlow extends BaseLlmFlow {
new Identity(),
new Compaction(),
new Contents(),
new Examples(),
CodeExecution.requestProcessor);

protected static final ImmutableList<ResponseProcessor> RESPONSE_PROCESSORS =
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/com/google/adk/tools/ExampleTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ public Completable processLlmRequest(
return Completable.complete();
}

llmRequestBuilder.appendInstructions(ImmutableList.of(examplesBlock));
if (!examplesBlock.isEmpty()) {
llmRequestBuilder.appendInstructions(ImmutableList.of(examplesBlock));
}
// Delegate to BaseTool to keep any declaration bookkeeping (none for this tool)
return super.processLlmRequest(llmRequestBuilder, toolContext);
}
Expand Down
12 changes: 1 addition & 11 deletions core/src/test/java/com/google/adk/examples/ExampleUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,7 @@ public List<Example> getExamples(String query) {
@Test
public void buildFewShotFewShot_noExamples() {
TestExampleProvider exampleProvider = new TestExampleProvider(ImmutableList.of());
String expected =
"""
<EXAMPLES>
Begin few-shot
The following are examples of user queries and model responses using the available tools.

End few-shot
Now, try to follow these examples and complete the following conversation
<EXAMPLES>\
""";
assertThat(ExampleUtils.buildExampleSi(exampleProvider, "test query")).isEqualTo(expected);
assertThat(ExampleUtils.buildExampleSi(exampleProvider, "test query")).isEqualTo("");
}

@Test
Expand Down
99 changes: 0 additions & 99 deletions core/src/test/java/com/google/adk/flows/llmflows/ExamplesTest.java

This file was deleted.

Loading