Skip to content

Commit 8d40f6a

Browse files
Mateusz Krawieccopybara-github
authored andcommitted
chore!: remove deprecated Example processor
PiperOrigin-RevId: 880745271
1 parent dc51aec commit 8d40f6a

7 files changed

Lines changed: 25 additions & 204 deletions

File tree

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

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
import com.google.adk.agents.ConfigAgentUtils.ConfigurationException;
4646
import com.google.adk.codeexecutors.BaseCodeExecutor;
4747
import com.google.adk.events.Event;
48-
import com.google.adk.examples.BaseExampleProvider;
49-
import com.google.adk.examples.Example;
5048
import com.google.adk.flows.llmflows.AutoFlow;
5149
import com.google.adk.flows.llmflows.BaseLlmFlow;
5250
import com.google.adk.flows.llmflows.SingleFlow;
@@ -97,8 +95,6 @@ public enum IncludeContents {
9795
private final List<Object> toolsUnion;
9896
private final ImmutableList<BaseToolset> toolsets;
9997
private final Optional<GenerateContentConfig> generateContentConfig;
100-
// TODO: Remove exampleProvider field - examples should only be provided via ExampleTool
101-
private final Optional<BaseExampleProvider> exampleProvider;
10298
private final IncludeContents includeContents;
10399

104100
private final boolean planning;
@@ -132,7 +128,6 @@ protected LlmAgent(Builder builder) {
132128
this.globalInstruction =
133129
requireNonNullElse(builder.globalInstruction, new Instruction.Static(""));
134130
this.generateContentConfig = Optional.ofNullable(builder.generateContentConfig);
135-
this.exampleProvider = Optional.ofNullable(builder.exampleProvider);
136131
this.includeContents = requireNonNullElse(builder.includeContents, IncludeContents.DEFAULT);
137132
this.planning = builder.planning != null && builder.planning;
138133
this.maxSteps = Optional.ofNullable(builder.maxSteps);
@@ -180,7 +175,6 @@ public static class Builder extends BaseAgent.Builder<Builder> {
180175
private Instruction globalInstruction;
181176
private ImmutableList<Object> toolsUnion;
182177
private GenerateContentConfig generateContentConfig;
183-
private BaseExampleProvider exampleProvider;
184178
private IncludeContents includeContents;
185179
private Boolean planning;
186180
private Integer maxSteps;
@@ -253,26 +247,6 @@ public Builder generateContentConfig(GenerateContentConfig generateContentConfig
253247
return this;
254248
}
255249

256-
// TODO: Remove these example provider methods and only use ExampleTool for providing examples.
257-
// Direct example methods should be deprecated in favor of using ExampleTool consistently.
258-
@CanIgnoreReturnValue
259-
public Builder exampleProvider(BaseExampleProvider exampleProvider) {
260-
this.exampleProvider = exampleProvider;
261-
return this;
262-
}
263-
264-
@CanIgnoreReturnValue
265-
public Builder exampleProvider(List<Example> examples) {
266-
this.exampleProvider = (unused) -> examples;
267-
return this;
268-
}
269-
270-
@CanIgnoreReturnValue
271-
public Builder exampleProvider(Example... examples) {
272-
this.exampleProvider = (unused) -> ImmutableList.copyOf(examples);
273-
return this;
274-
}
275-
276250
@CanIgnoreReturnValue
277251
public Builder includeContents(IncludeContents includeContents) {
278252
this.includeContents = includeContents;
@@ -640,10 +614,24 @@ protected void validate() {
640614
+ " transfer.");
641615
}
642616
if (this.toolsUnion != null && !this.toolsUnion.isEmpty()) {
643-
throw new IllegalArgumentException(
644-
"Invalid config for agent "
645-
+ this.name
646-
+ ": if outputSchema is set, tools must be empty.");
617+
boolean hasOtherTools =
618+
this.toolsUnion.stream()
619+
.anyMatch(
620+
tool -> {
621+
if (tool instanceof BaseToolset) {
622+
return true;
623+
}
624+
if (tool instanceof BaseTool) {
625+
return !((BaseTool) tool).name().equals("example_tool");
626+
}
627+
return true;
628+
});
629+
if (hasOtherTools) {
630+
throw new IllegalArgumentException(
631+
"Invalid config for agent "
632+
+ this.name
633+
+ ": if outputSchema is set, tools must be empty.");
634+
}
647635
}
648636
}
649637
}
@@ -812,11 +800,6 @@ public Optional<GenerateContentConfig> generateContentConfig() {
812800
return generateContentConfig;
813801
}
814802

815-
// TODO: Remove this getter - examples should only be provided via ExampleTool
816-
public Optional<BaseExampleProvider> exampleProvider() {
817-
return exampleProvider;
818-
}
819-
820803
public IncludeContents includeContents() {
821804
return includeContents;
822805
}

core/src/main/java/com/google/adk/examples/ExampleUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public final class ExampleUtils {
6464
* @return string representation of the examples block.
6565
*/
6666
private static String convertExamplesToText(List<Example> examples) {
67+
if (examples.isEmpty()) {
68+
return "";
69+
}
6770
StringBuilder examplesStr = new StringBuilder();
6871

6972
// super header

core/src/main/java/com/google/adk/flows/llmflows/Examples.java

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

core/src/main/java/com/google/adk/flows/llmflows/SingleFlow.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public class SingleFlow extends BaseLlmFlow {
3232
new Identity(),
3333
new Compaction(),
3434
new Contents(),
35-
new Examples(),
3635
CodeExecution.requestProcessor);
3736

3837
protected static final ImmutableList<ResponseProcessor> RESPONSE_PROCESSORS =

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ public Completable processLlmRequest(
8585
return Completable.complete();
8686
}
8787

88-
llmRequestBuilder.appendInstructions(ImmutableList.of(examplesBlock));
88+
if (!examplesBlock.isEmpty()) {
89+
llmRequestBuilder.appendInstructions(ImmutableList.of(examplesBlock));
90+
}
8991
// Delegate to BaseTool to keep any declaration bookkeeping (none for this tool)
9092
return super.processLlmRequest(llmRequestBuilder, toolContext);
9193
}

core/src/test/java/com/google/adk/examples/ExampleUtilsTest.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,7 @@ public List<Example> getExamples(String query) {
4949
@Test
5050
public void buildFewShotFewShot_noExamples() {
5151
TestExampleProvider exampleProvider = new TestExampleProvider(ImmutableList.of());
52-
String expected =
53-
"""
54-
<EXAMPLES>
55-
Begin few-shot
56-
The following are examples of user queries and model responses using the available tools.
57-
58-
End few-shot
59-
Now, try to follow these examples and complete the following conversation
60-
<EXAMPLES>\
61-
""";
62-
assertThat(ExampleUtils.buildExampleSi(exampleProvider, "test query")).isEqualTo(expected);
52+
assertThat(ExampleUtils.buildExampleSi(exampleProvider, "test query")).isEqualTo("");
6353
}
6454

6555
@Test

core/src/test/java/com/google/adk/flows/llmflows/ExamplesTest.java

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

0 commit comments

Comments
 (0)